[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
This commit is contained in:
Kim Shepherd
2024-02-19 17:03:31 +13:00
parent 68dd35095c
commit 911cf8905c
9 changed files with 78 additions and 9 deletions

View File

@@ -131,6 +131,10 @@ submission:
# NOTE: after how many time (milliseconds) submission is saved automatically
# eg. timer: 5 * (1000 * 60); // 5 minutes
timer: 0
# Always show the duplicate detection section if enabled, even if there are no potential duplicates detected
# (a message will be displayed to indicate no matches were found)
duplicateDetection:
alwaysShowSection: false
icons:
metadata:
# NOTE: example of configuration

View File

@@ -56,6 +56,9 @@ export const SubmissionObjectActionTypes = {
DISCARD_SUBMISSION_SUCCESS: type('dspace/submission/DISCARD_SUBMISSION_SUCCESS'),
DISCARD_SUBMISSION_ERROR: type('dspace/submission/DISCARD_SUBMISSION_ERROR'),
// Clearing active section types
CLEAN_DUPLICATE_DETECTION: type('dspace/submission/CLEAN_DUPLICATE_DETECTION'),
// Upload file types
NEW_FILE: type('dspace/submission/NEW_FILE'),
EDIT_FILE_DATA: type('dspace/submission/EDIT_FILE_DATA'),
@@ -240,6 +243,25 @@ export class UpdateSectionDataAction implements Action {
}
}
/**
* Removes data and makes 'detect-duplicate' section not visible.
*/
export class CleanDuplicateDetectionAction implements Action {
type = SubmissionObjectActionTypes.CLEAN_DUPLICATE_DETECTION;
payload: {
submissionId: string;
};
/**
* creates a new CleanDetectDuplicateAction
*
* @param submissionId Id of the submission on which perform the action
*/
constructor(submissionId: string ) {
this.payload = { submissionId };
}
}
export class UpdateSectionDataSuccessAction implements Action {
type = SubmissionObjectActionTypes.UPDATE_SECTION_DATA_SUCCESS;
}

View File

@@ -43,7 +43,8 @@ import {
SubmissionObjectAction,
SubmissionObjectActionTypes,
UpdateSectionDataAction,
UpdateSectionDataSuccessAction
UpdateSectionDataSuccessAction,
CleanDuplicateDetectionAction
} from './submission-objects.actions';
import {SubmissionObjectEntry} from './submission-objects.reducer';
import {Item} from '../../core/shared/item.model';
@@ -58,6 +59,7 @@ import {SubmissionSectionError} from './submission-section-error.model';
import {
WorkspaceitemSectionDuplicatesObject
} from '../../core/submission/models/workspaceitem-section-duplicates.model';
import { environment } from '../../../environments/environment';
@Injectable()
export class SubmissionObjectEffects {
@@ -74,10 +76,11 @@ export class SubmissionObjectEffects {
const selfLink = sectionDefinition._links.self.href || sectionDefinition._links.self;
const sectionId = selfLink.substr(selfLink.lastIndexOf('/') + 1);
const config = sectionDefinition._links.config ? (sectionDefinition._links.config.href || sectionDefinition._links.config) : '';
// A section is enabled if it is mandatory (except duplicate detection) or contains data in its section payload
// A section is enabled if it is mandatory or contains data in its section payload
// except for detect duplicate steps which will be hidden with no data unless overridden in config, even if mandatory
const enabled = (sectionDefinition.mandatory && (sectionDefinition.sectionType !== SectionsType.Duplicates))
|| (isNotEmpty(action.payload.sections) && action.payload.sections.hasOwnProperty(sectionId)
&& (sectionDefinition.sectionType === SectionsType.Duplicates && isNotEmpty((action.payload.sections[sectionId] as WorkspaceitemSectionDuplicatesObject).potentialDuplicates))
&& (sectionDefinition.sectionType === SectionsType.Duplicates && (alwaysDisplayDuplicates() || isNotEmpty((action.payload.sections[sectionId] as WorkspaceitemSectionDuplicatesObject).potentialDuplicates)))
);
let sectionData;
if (sectionDefinition.sectionType !== SectionsType.SubmissionForm) {
@@ -442,10 +445,13 @@ export class SubmissionObjectEffects {
mappedActions.push(new UpdateSectionDataAction(submissionId, sherpaPoliciesSectionId, null, [], []));
}
// When Duplicate Detection step is enabled, add it only if there are duplicates
// When Duplicate Detection step is enabled, add it only if there are duplicates in the response section data
// or if configuration overrides this behaviour
if (!alwaysDisplayDuplicates()) {
const duplicatesSectionId = findKey(currentState.sections, (section) => section.sectionType === SectionsType.Duplicates);
if (isNotUndefined(duplicatesSectionId) && isNotEmpty(currentState.sections[duplicatesSectionId]?.data) && isEmpty(sections[duplicatesSectionId])) {
mappedActions.push(new UpdateSectionDataAction(submissionId, duplicatesSectionId, null, [], []));
if (isNotUndefined(duplicatesSectionId) && isEmpty((sections[duplicatesSectionId] as WorkspaceitemSectionDuplicatesObject).potentialDuplicates)) {
mappedActions.push(new CleanDuplicateDetectionAction(submissionId));
}
}
});
}
@@ -493,3 +499,7 @@ function filterErrors(sectionForm: FormState, sectionErrors: SubmissionSectionEr
});
return filteredErrors;
}
function alwaysDisplayDuplicates(): boolean {
return (environment.submission.duplicateDetection.alwaysShowSection);
}

View File

@@ -5,7 +5,7 @@ import isEqual from 'lodash/isEqual';
import uniqWith from 'lodash/uniqWith';
import {
ChangeSubmissionCollectionAction,
ChangeSubmissionCollectionAction, CleanDuplicateDetectionAction,
CompleteInitSubmissionFormAction,
DeleteSectionErrorsAction,
DeleteUploadedFileAction,
@@ -229,6 +229,10 @@ export function submissionObjectReducer(state = initialState, action: Submission
return removeSectionErrors(state, action as RemoveSectionErrorsAction);
}
case SubmissionObjectActionTypes.CLEAN_DUPLICATE_DETECTION: {
return cleanDuplicateDetectionSection(state, action as CleanDuplicateDetectionAction);
}
default: {
return state;
}
@@ -856,3 +860,20 @@ function deleteFile(state: SubmissionObjectState, action: DeleteUploadedFileActi
}
return state;
}
function cleanDuplicateDetectionSection(state: SubmissionObjectState, action: CleanDuplicateDetectionAction): SubmissionObjectState {
if (isNotEmpty(state[ action.payload.submissionId ])) {
return Object.assign({}, state, {
[ action.payload.submissionId ]: Object.assign({}, state[ action.payload.submissionId ], {
sections: Object.assign({}, state[ action.payload.submissionId ].sections, {
[ 'duplicates' ]: Object.assign({}, state[ action.payload.submissionId ].sections.duplicates, {
enabled: false,
data: { potentialDuplicates: [] }
})
})
})
});
} else {
return state;
}
}

View File

@@ -4,7 +4,7 @@ Template for the detect duplicates submission section component
-->
<div class="text-sm-left" *ngVar="(this.getDuplicateData() | async) as data">
<ng-container *ngIf="data?.potentialDuplicates.length == 0">
<p>{{ 'submission.sections.duplicates.none' | translate }}</p>
<div class="alert alert-success w-100">{{ 'submission.sections.duplicates.none' | translate }}</div>
</ng-container>
<ng-container *ngIf="data?.potentialDuplicates.length > 0">
<div class="alert alert-warning w-100">{{ 'submission.sections.duplicates.detected' | translate }}</div>

View File

@@ -13,6 +13,7 @@ describe('Config Util', () => {
expect(appConfig.ui.useProxies).toEqual(true);
expect(appConfig.submission.autosave.metadata).toEqual([]);
expect(appConfig.submission.duplicateDetection.alwaysShowSection).toEqual(false);
expect(appConfig.themes.length).toEqual(1);
expect(appConfig.themes[0].name).toEqual('dspace');

View File

@@ -154,6 +154,9 @@ export class DefaultAppConfig implements AppConfig {
*/
timer: 0
},
duplicateDetection: {
alwaysShowSection: false
},
typeBind: {
field: 'dc.type'
},

View File

@@ -5,6 +5,10 @@ interface AutosaveConfig extends Config {
timer: number;
}
interface DuplicateDetectionConfig extends Config {
alwaysShowSection: boolean;
}
interface TypeBindConfig extends Config {
field: string;
}
@@ -29,6 +33,7 @@ export interface ConfidenceIconConfig extends Config {
export interface SubmissionConfig extends Config {
autosave: AutosaveConfig;
duplicateDetection: DuplicateDetectionConfig;
typeBind: TypeBindConfig;
icons: IconsConfig;
}

View File

@@ -121,6 +121,9 @@ export const environment: BuildConfig = {
// NOTE: every how many minutes submission is saved automatically
timer: 5
},
duplicateDetection: {
alwaysShowSection: false
},
typeBind: {
field: 'dc.type'
},