Skip to content

Commit 911cf89

Browse files
committed
[TLC-674] Hide empty duplicate section UNLESS config overrides
A new config property allows the user to force the duplicate section to be displayed even if there are no duplicates as sometimes this is useful information to a reviewer or submitter
1 parent 68dd350 commit 911cf89

9 files changed

Lines changed: 78 additions & 9 deletions

config/config.example.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ submission:
131131
# NOTE: after how many time (milliseconds) submission is saved automatically
132132
# eg. timer: 5 * (1000 * 60); // 5 minutes
133133
timer: 0
134+
# Always show the duplicate detection section if enabled, even if there are no potential duplicates detected
135+
# (a message will be displayed to indicate no matches were found)
136+
duplicateDetection:
137+
alwaysShowSection: false
134138
icons:
135139
metadata:
136140
# NOTE: example of configuration

src/app/submission/objects/submission-objects.actions.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ export const SubmissionObjectActionTypes = {
5656
DISCARD_SUBMISSION_SUCCESS: type('dspace/submission/DISCARD_SUBMISSION_SUCCESS'),
5757
DISCARD_SUBMISSION_ERROR: type('dspace/submission/DISCARD_SUBMISSION_ERROR'),
5858

59+
// Clearing active section types
60+
CLEAN_DUPLICATE_DETECTION: type('dspace/submission/CLEAN_DUPLICATE_DETECTION'),
61+
5962
// Upload file types
6063
NEW_FILE: type('dspace/submission/NEW_FILE'),
6164
EDIT_FILE_DATA: type('dspace/submission/EDIT_FILE_DATA'),
@@ -240,6 +243,25 @@ export class UpdateSectionDataAction implements Action {
240243
}
241244
}
242245

246+
/**
247+
* Removes data and makes 'detect-duplicate' section not visible.
248+
*/
249+
export class CleanDuplicateDetectionAction implements Action {
250+
type = SubmissionObjectActionTypes.CLEAN_DUPLICATE_DETECTION;
251+
payload: {
252+
submissionId: string;
253+
};
254+
255+
/**
256+
* creates a new CleanDetectDuplicateAction
257+
*
258+
* @param submissionId Id of the submission on which perform the action
259+
*/
260+
constructor(submissionId: string ) {
261+
this.payload = { submissionId };
262+
}
263+
}
264+
243265
export class UpdateSectionDataSuccessAction implements Action {
244266
type = SubmissionObjectActionTypes.UPDATE_SECTION_DATA_SUCCESS;
245267
}

src/app/submission/objects/submission-objects.effects.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ import {
4343
SubmissionObjectAction,
4444
SubmissionObjectActionTypes,
4545
UpdateSectionDataAction,
46-
UpdateSectionDataSuccessAction
46+
UpdateSectionDataSuccessAction,
47+
CleanDuplicateDetectionAction
4748
} from './submission-objects.actions';
4849
import {SubmissionObjectEntry} from './submission-objects.reducer';
4950
import {Item} from '../../core/shared/item.model';
@@ -58,6 +59,7 @@ import {SubmissionSectionError} from './submission-section-error.model';
5859
import {
5960
WorkspaceitemSectionDuplicatesObject
6061
} from '../../core/submission/models/workspaceitem-section-duplicates.model';
62+
import { environment } from '../../../environments/environment';
6163

6264
@Injectable()
6365
export 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+
}

src/app/submission/objects/submission-objects.reducer.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import isEqual from 'lodash/isEqual';
55
import uniqWith from 'lodash/uniqWith';
66

77
import {
8-
ChangeSubmissionCollectionAction,
8+
ChangeSubmissionCollectionAction, CleanDuplicateDetectionAction,
99
CompleteInitSubmissionFormAction,
1010
DeleteSectionErrorsAction,
1111
DeleteUploadedFileAction,
@@ -229,6 +229,10 @@ export function submissionObjectReducer(state = initialState, action: Submission
229229
return removeSectionErrors(state, action as RemoveSectionErrorsAction);
230230
}
231231

232+
case SubmissionObjectActionTypes.CLEAN_DUPLICATE_DETECTION: {
233+
return cleanDuplicateDetectionSection(state, action as CleanDuplicateDetectionAction);
234+
}
235+
232236
default: {
233237
return state;
234238
}
@@ -856,3 +860,20 @@ function deleteFile(state: SubmissionObjectState, action: DeleteUploadedFileActi
856860
}
857861
return state;
858862
}
863+
864+
function cleanDuplicateDetectionSection(state: SubmissionObjectState, action: CleanDuplicateDetectionAction): SubmissionObjectState {
865+
if (isNotEmpty(state[ action.payload.submissionId ])) {
866+
return Object.assign({}, state, {
867+
[ action.payload.submissionId ]: Object.assign({}, state[ action.payload.submissionId ], {
868+
sections: Object.assign({}, state[ action.payload.submissionId ].sections, {
869+
[ 'duplicates' ]: Object.assign({}, state[ action.payload.submissionId ].sections.duplicates, {
870+
enabled: false,
871+
data: { potentialDuplicates: [] }
872+
})
873+
})
874+
})
875+
});
876+
} else {
877+
return state;
878+
}
879+
}

src/app/submission/sections/duplicates/section-duplicates.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
-->
55
<div class="text-sm-left" *ngVar="(this.getDuplicateData() | async) as data">
66
<ng-container *ngIf="data?.potentialDuplicates.length == 0">
7-
<p>{{ 'submission.sections.duplicates.none' | translate }}</p>
7+
<div class="alert alert-success w-100">{{ 'submission.sections.duplicates.none' | translate }}</div>
88
</ng-container>
99
<ng-container *ngIf="data?.potentialDuplicates.length > 0">
1010
<div class="alert alert-warning w-100">{{ 'submission.sections.duplicates.detected' | translate }}</div>

src/config/config.util.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ describe('Config Util', () => {
1313
expect(appConfig.ui.useProxies).toEqual(true);
1414

1515
expect(appConfig.submission.autosave.metadata).toEqual([]);
16+
expect(appConfig.submission.duplicateDetection.alwaysShowSection).toEqual(false);
1617

1718
expect(appConfig.themes.length).toEqual(1);
1819
expect(appConfig.themes[0].name).toEqual('dspace');

src/config/default-app-config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ export class DefaultAppConfig implements AppConfig {
154154
*/
155155
timer: 0
156156
},
157+
duplicateDetection: {
158+
alwaysShowSection: false
159+
},
157160
typeBind: {
158161
field: 'dc.type'
159162
},

src/config/submission-config.interface.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ interface AutosaveConfig extends Config {
55
timer: number;
66
}
77

8+
interface DuplicateDetectionConfig extends Config {
9+
alwaysShowSection: boolean;
10+
}
11+
812
interface TypeBindConfig extends Config {
913
field: string;
1014
}
@@ -29,6 +33,7 @@ export interface ConfidenceIconConfig extends Config {
2933

3034
export interface SubmissionConfig extends Config {
3135
autosave: AutosaveConfig;
36+
duplicateDetection: DuplicateDetectionConfig;
3237
typeBind: TypeBindConfig;
3338
icons: IconsConfig;
3439
}

src/environments/environment.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ export const environment: BuildConfig = {
121121
// NOTE: every how many minutes submission is saved automatically
122122
timer: 5
123123
},
124+
duplicateDetection: {
125+
alwaysShowSection: false
126+
},
124127
typeBind: {
125128
field: 'dc.type'
126129
},

0 commit comments

Comments
 (0)