From 9caf95c04daf2e32eef1e6d05190d2685f73217d Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Tue, 11 Dec 2018 20:01:42 +0100 Subject: [PATCH] On metadata enrichment, When Upload section is disabled, add it to submission only if there are files --- .../objects/submission-objects.effects.ts | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/app/submission/objects/submission-objects.effects.ts b/src/app/submission/objects/submission-objects.effects.ts index 89b9289b38..1e0c9063d4 100644 --- a/src/app/submission/objects/submission-objects.effects.ts +++ b/src/app/submission/objects/submission-objects.effects.ts @@ -42,6 +42,8 @@ import { SubmissionObjectEntry } from './submission-objects.reducer'; import { SubmissionSectionModel } from '../../core/config/models/config-submission-section.model'; import parseSectionErrors from '../utils/parseSectionErrors'; import { WorkspaceitemSectionsObject } from '../../core/submission/models/workspaceitem-sections.model'; +import { WorkspaceitemSectionUploadObject } from '../../core/submission/models/workspaceitem-section-upload.model'; +import { SectionsType } from '../sections/sections-type'; @Injectable() export class SubmissionObjectEffects { @@ -242,15 +244,22 @@ export class SubmissionObjectEffects { const sections: WorkspaceitemSectionsObject = (item.sections && isNotEmpty(item.sections)) ? item.sections : {}; const sectionsKeys: string[] = union(Object.keys(sections), Object.keys(errorsList)); - sectionsKeys - .forEach((sectionId) => { - const sectionErrors = errorsList[sectionId] || []; - const sectionData = sections[sectionId] || {}; - if (notify && !currentState.sections[sectionId].enabled) { - this.submissionService.notifyNewSection(submissionId, sectionId, currentState.sections[sectionId].sectionType); - } - mappedActions.push(new UpdateSectionDataAction(submissionId, sectionId, sectionData, sectionErrors)); - }); + for (const sectionId of sectionsKeys) { + const sectionErrors = errorsList[sectionId] || []; + const sectionData = sections[sectionId] || {}; + + // When Upload section is disabled, add to submission only if there are files + if (currentState.sections[sectionId].sectionType === SectionsType.Upload + && isEmpty((sectionData as WorkspaceitemSectionUploadObject).files) + && !currentState.sections[sectionId].enabled) { + continue; + } + + if (notify && !currentState.sections[sectionId].enabled) { + this.submissionService.notifyNewSection(submissionId, sectionId, currentState.sections[sectionId].sectionType); + } + mappedActions.push(new UpdateSectionDataAction(submissionId, sectionId, sectionData, sectionErrors)); + } });