@@ -43,7 +43,8 @@ import {
4343 SubmissionObjectAction ,
4444 SubmissionObjectActionTypes ,
4545 UpdateSectionDataAction ,
46- UpdateSectionDataSuccessAction
46+ UpdateSectionDataSuccessAction ,
47+ CleanDuplicateDetectionAction
4748} from './submission-objects.actions' ;
4849import { SubmissionObjectEntry } from './submission-objects.reducer' ;
4950import { Item } from '../../core/shared/item.model' ;
@@ -58,6 +59,7 @@ import {SubmissionSectionError} from './submission-section-error.model';
5859import {
5960 WorkspaceitemSectionDuplicatesObject
6061} from '../../core/submission/models/workspaceitem-section-duplicates.model' ;
62+ import { environment } from '../../../environments/environment' ;
6163
6264@Injectable ( )
6365export class SubmissionObjectEffects {
@@ -74,10 +76,11 @@ export class SubmissionObjectEffects {
7476 const selfLink = sectionDefinition . _links . self . href || sectionDefinition . _links . self ;
7577 const sectionId = selfLink . substr ( selfLink . lastIndexOf ( '/' ) + 1 ) ;
7678 const config = sectionDefinition . _links . config ? ( sectionDefinition . _links . config . href || sectionDefinition . _links . config ) : '' ;
77- // A section is enabled if it is mandatory (except duplicate detection) or contains data in its section payload
79+ // A section is enabled if it is mandatory or contains data in its section payload
80+ // except for detect duplicate steps which will be hidden with no data unless overridden in config, even if mandatory
7881 const enabled = ( sectionDefinition . mandatory && ( sectionDefinition . sectionType !== SectionsType . Duplicates ) )
7982 || ( isNotEmpty ( action . payload . sections ) && action . payload . sections . hasOwnProperty ( sectionId )
80- && ( sectionDefinition . sectionType === SectionsType . Duplicates && isNotEmpty ( ( action . payload . sections [ sectionId ] as WorkspaceitemSectionDuplicatesObject ) . potentialDuplicates ) )
83+ && ( sectionDefinition . sectionType === SectionsType . Duplicates && ( alwaysDisplayDuplicates ( ) || isNotEmpty ( ( action . payload . sections [ sectionId ] as WorkspaceitemSectionDuplicatesObject ) . potentialDuplicates ) ) )
8184 ) ;
8285 let sectionData ;
8386 if ( sectionDefinition . sectionType !== SectionsType . SubmissionForm ) {
@@ -442,10 +445,13 @@ export class SubmissionObjectEffects {
442445 mappedActions . push ( new UpdateSectionDataAction ( submissionId , sherpaPoliciesSectionId , null , [ ] , [ ] ) ) ;
443446 }
444447
445- // When Duplicate Detection step is enabled, add it only if there are duplicates
446- const duplicatesSectionId = findKey ( currentState . sections , ( section ) => section . sectionType === SectionsType . Duplicates ) ;
447- if ( isNotUndefined ( duplicatesSectionId ) && isNotEmpty ( currentState . sections [ duplicatesSectionId ] ?. data ) && isEmpty ( sections [ duplicatesSectionId ] ) ) {
448- mappedActions . push ( new UpdateSectionDataAction ( submissionId , duplicatesSectionId , null , [ ] , [ ] ) ) ;
448+ // When Duplicate Detection step is enabled, add it only if there are duplicates in the response section data
449+ // or if configuration overrides this behaviour
450+ if ( ! alwaysDisplayDuplicates ( ) ) {
451+ const duplicatesSectionId = findKey ( currentState . sections , ( section ) => section . sectionType === SectionsType . Duplicates ) ;
452+ if ( isNotUndefined ( duplicatesSectionId ) && isEmpty ( ( sections [ duplicatesSectionId ] as WorkspaceitemSectionDuplicatesObject ) . potentialDuplicates ) ) {
453+ mappedActions . push ( new CleanDuplicateDetectionAction ( submissionId ) ) ;
454+ }
449455 }
450456 } ) ;
451457 }
@@ -493,3 +499,7 @@ function filterErrors(sectionForm: FormState, sectionErrors: SubmissionSectionEr
493499 } ) ;
494500 return filteredErrors ;
495501}
502+
503+ function alwaysDisplayDuplicates ( ) : boolean {
504+ return ( environment . submission . duplicateDetection . alwaysShowSection ) ;
505+ }
0 commit comments