Skip to content

Commit 1ffb587

Browse files
author
vikasrohit
authored
Merge pull request #2211 from appirio-tech/hotfix/adding_capability_of_product_attachments
Hotfix/adding capability of product attachments
2 parents f0342be + 4bdce32 commit 1ffb587

File tree

7 files changed

+61
-12
lines changed

7 files changed

+61
-12
lines changed

src/projects/actions/projectAttachment.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import {
22
addProjectAttachment as addProjectAttachmentAPI,
33
removeProjectAttachment as removeProjectAttachmentAPI,
44
updateProjectAttachment as updateProjectAttachmentAPI,
5-
addProductAttachment as addProductAttachmentAPI,
6-
removeProductAttachment as removeProductAttachmentAPI,
7-
updateProductAttachment as updateProductAttachmentAPI,
5+
// addProductAttachment as addProductAttachmentAPI,
6+
// removeProductAttachment as removeProductAttachmentAPI,
7+
// updateProductAttachment as updateProductAttachmentAPI,
88
} from '../../api/projectAttachments'
99

1010
import {
@@ -47,7 +47,7 @@ export function addProductAttachment(projectId, phaseId, productId, attachment)
4747
return (dispatch) => {
4848
return dispatch({
4949
type: ADD_PRODUCT_ATTACHMENT,
50-
payload: addProductAttachmentAPI(projectId, phaseId, productId, attachment)
50+
payload: addProjectAttachmentAPI(projectId, attachment)
5151
.then((uploadedAttachment) => ({
5252
phaseId,
5353
productId,
@@ -61,7 +61,7 @@ export function updateProductAttachment(projectId, phaseId, productId, attachmen
6161
return (dispatch) => {
6262
return dispatch({
6363
type: UPDATE_PRODUCT_ATTACHMENT,
64-
payload: updateProductAttachmentAPI(projectId, phaseId, productId, attachmentId, attachment)
64+
payload: updateProjectAttachmentAPI(projectId, attachmentId, attachment)
6565
.then((uploadedAttachment) => ({
6666
phaseId,
6767
productId,
@@ -75,7 +75,7 @@ export function removeProductAttachment(projectId, phaseId, productId, attachmen
7575
return (dispatch) => {
7676
return dispatch({
7777
type: REMOVE_PRODUCT_ATTACHMENT,
78-
payload: removeProductAttachmentAPI(projectId, phaseId, productId, attachmentId)
78+
payload: removeProjectAttachmentAPI(projectId, attachmentId)
7979
.then((removedAttachmentId) => ({
8080
phaseId,
8181
productId,

src/projects/detail/components/FileListContainer.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class FileListContainer extends Component {
3636
render() {
3737
const {
3838
files,
39+
category,
3940
allMembers,
4041
attachmentsStorePath,
4142
canManageAttachments,
@@ -56,7 +57,7 @@ class FileListContainer extends Component {
5657
return (
5758
<div>
5859
<FileList files={files} onDelete={removeAttachment} onSave={updateAttachment} canModify={canManageAttachments}/>
59-
<AddFiles successHandler={this.processUploadedFiles} storePath={attachmentsStorePath} category={'appDefinition'} />
60+
<AddFiles successHandler={this.processUploadedFiles} storePath={attachmentsStorePath} category={category} />
6061
</div>
6162
)
6263
}

src/projects/detail/components/SpecSection.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,16 @@ const SpecSection = props => {
159159
case 'files': {
160160
const projectLatest = isProjectDirty ? dirtyProject : project
161161
const files = _.get(projectLatest, props.fieldName, [])
162+
// NOTE using category to differentiate between project and product attachments is a workaround to give ability
163+
// to upload attachments for products. We need to come up with a better way to handle this.
164+
// defaults to appDefinition to be backward compatible
165+
let category = _.get(props, 'category', 'appDefinition')
166+
category = 'product' === category ? `${category}#${projectLatest.id}` : category
162167
return (
163168
<FileListContainer
164169
project={projectLatest}
165170
files={files}
171+
category={category}
166172
addAttachment={addAttachment}
167173
updateAttachment={updateAttachment}
168174
removeAttachment={removeAttachment}

src/projects/detail/containers/DashboardContainer.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class DashboardContainer extends React.Component {
8585
<ProjectInfoContainer
8686
currentMemberRole={currentMemberRole}
8787
project={project}
88+
phases={phases}
8889
isSuperUser={isSuperUser}
8990
/>
9091
)

src/projects/detail/containers/ProjectInfoContainer.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class ProjectInfoContainer extends React.Component {
8282

8383
render() {
8484
const { duration } = this.state
85-
const { project, currentMemberRole, isSuperUser } = this.props
85+
const { project, phases, currentMemberRole, isSuperUser } = this.props
8686
let directLinks = null
8787
// check if direct links need to be added
8888
const isMemberOrCopilot = _.indexOf([PROJECT_ROLE_COPILOT, PROJECT_ROLE_MANAGER], currentMemberRole) > -1
@@ -107,7 +107,20 @@ class ProjectInfoContainer extends React.Component {
107107
devices = _.get(project, 'details.devices', [])
108108
}
109109

110-
const attachments = _.sortBy(project.attachments, attachment => -new Date(attachment.updatedAt).getTime())
110+
let attachments = project.attachments
111+
// merges the product attachments to show in the links menu
112+
if (phases && phases.length > 0) {
113+
phases.forEach(phase => {
114+
if (phase.products && phase.products.length > 0) {
115+
phase.products.forEach(product => {
116+
if (product.attachments && product.attachments.length > 0) {
117+
attachments = attachments.concat(product.attachments)
118+
}
119+
})
120+
}
121+
})
122+
}
123+
attachments = _.sortBy(attachments, attachment => -new Date(attachment.updatedAt).getTime())
111124
.map(attachment => ({
112125
title: attachment.title,
113126
address: attachment.downloadUrl,
@@ -148,7 +161,8 @@ class ProjectInfoContainer extends React.Component {
148161

149162
ProjectInfoContainer.PropTypes = {
150163
currentMemberRole: PropTypes.string,
151-
project: PropTypes.object.isRequired
164+
project: PropTypes.object.isRequired,
165+
phases: PropTypes.arrayOf(PropTypes.object)
152166
}
153167

154168
const mapDispatchToProps = { updateProject, deleteProject }

src/projects/detail/containers/ProjectPlanContainer.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const ProjectPlanContainer = (props) => {
4646
<ProjectInfoContainer
4747
currentMemberRole={currentMemberRole}
4848
project={project}
49+
phases={phases}
4950
isSuperUser={isSuperUser}
5051
/>
5152
)

src/projects/reducers/project.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,38 @@ export const projectState = function (state=initialState, action) {
191191
isLoadingPhases: true
192192
})
193193

194-
case LOAD_PROJECT_PHASES_SUCCESS:
194+
case LOAD_PROJECT_PHASES_SUCCESS: {
195+
// loops through the phases to update the attachments field in the products of each phase
196+
// NOTE it might not be needed after we get a proper implementation for supporting product attachments
197+
const phases = _.map(action.payload, p => {
198+
p.products = _.map(p.products, prd => {
199+
const attachments = []
200+
if (state.project.attachments && state.project.attachments.length) {
201+
state.project.attachments.forEach(a => {
202+
if (a.category === `product#${prd.id}`) {
203+
attachments.push(a)
204+
}
205+
})
206+
}
207+
return { ...prd, attachments }
208+
})
209+
return p
210+
})
211+
// updates projects' attachments which are not coupled with any product/phase
212+
const projectAttachments = []
213+
state.project.attachments.forEach(a => {
214+
if (!a.category || a.category.indexOf('product') !== 0) {
215+
projectAttachments.push(a)
216+
}
217+
})
195218
return update(state, {
196-
phases: { $set: action.payload },
219+
project: { attachments : { $set : projectAttachments } },
220+
projectNonDirty: { attachments: { $set: projectAttachments } },
221+
phases: { $set:phases },
197222
phasesNonDirty: { $set: action.payload },
198223
isLoadingPhases: { $set: false}
199224
})
225+
}
200226

201227
// Create & Edit project
202228
case CREATE_PROJECT_STAGE_PENDING:

0 commit comments

Comments
 (0)