Skip to content

Commit e231f9c

Browse files
author
Vikas Agarwal
committed
Github issue#2204, Attachments/File Upload for phase specification question is not working
- Work around to enable attachments for products. Need proper implementation in upcoming releases.
1 parent 7360a78 commit e231f9c

File tree

4 files changed

+34
-9
lines changed

4 files changed

+34
-9
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
@@ -158,10 +158,16 @@ const SpecSection = props => {
158158
case 'files': {
159159
const projectLatest = isProjectDirty ? dirtyProject : project
160160
const files = _.get(projectLatest, props.fieldName, [])
161+
// NOTE using category to differentiate between project and product attachments is a workaround to give ability
162+
// to upload attachments for products. We need to come up with a better way to handle this.
163+
// defaults to appDefinition to be backward compatible
164+
let category = _.get(props, 'category', 'appDefinition')
165+
category = 'product' === category ? `${category}#${projectLatest.id}` : category
161166
return (
162167
<FileListContainer
163168
project={projectLatest}
164169
files={files}
170+
category={category}
165171
addAttachment={addAttachment}
166172
updateAttachment={updateAttachment}
167173
removeAttachment={removeAttachment}

src/projects/reducers/project.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,30 @@ 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+
// TODO remove `a` from project's attachments
205+
}
206+
})
207+
}
208+
return { ...prd, attachments }
209+
})
210+
return p
211+
})
195212
return update(state, {
196-
phases: { $set: action.payload },
213+
phases: { $set:phases },
197214
phasesNonDirty: { $set: action.payload },
198215
isLoadingPhases: { $set: false}
199216
})
217+
}
200218

201219
// Create & Edit project
202220
case CREATE_PROJECT_STAGE_PENDING:

0 commit comments

Comments
 (0)