mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
Merge pull request #1607 from 4Science/CST-5418-improve-cannot-deposit-notification
[CST-5418] Improve notification when cannot deposit
This commit is contained in:
@@ -42,6 +42,7 @@ describe('New Submission page', () => {
|
|||||||
cy.get('button#deposit').click();
|
cy.get('button#deposit').click();
|
||||||
|
|
||||||
// A warning alert should display.
|
// A warning alert should display.
|
||||||
|
cy.get('ds-notification div.alert-success').should('not.exist');
|
||||||
cy.get('ds-notification div.alert-warning').should('be.visible');
|
cy.get('ds-notification div.alert-warning').should('be.visible');
|
||||||
|
|
||||||
// First section should have an exclamation error in the header
|
// First section should have an exclamation error in the header
|
||||||
|
@@ -421,7 +421,8 @@ export class SaveSubmissionFormSuccessAction implements Action {
|
|||||||
payload: {
|
payload: {
|
||||||
submissionId: string;
|
submissionId: string;
|
||||||
submissionObject: SubmissionObject[];
|
submissionObject: SubmissionObject[];
|
||||||
notify?: boolean
|
showNotifications?: boolean;
|
||||||
|
showErrors?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -431,9 +432,13 @@ export class SaveSubmissionFormSuccessAction implements Action {
|
|||||||
* the submission's ID
|
* the submission's ID
|
||||||
* @param submissionObject
|
* @param submissionObject
|
||||||
* the submission's Object
|
* the submission's Object
|
||||||
|
* @param showNotifications
|
||||||
|
* a boolean representing if to show notifications on save
|
||||||
|
* @param showErrors
|
||||||
|
* a boolean representing if to show errors on save
|
||||||
*/
|
*/
|
||||||
constructor(submissionId: string, submissionObject: SubmissionObject[], notify?: boolean) {
|
constructor(submissionId: string, submissionObject: SubmissionObject[], showNotifications?: boolean, showErrors?: boolean) {
|
||||||
this.payload = { submissionId, submissionObject, notify };
|
this.payload = { submissionId, submissionObject, showNotifications, showErrors };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -237,6 +237,7 @@ describe('SubmissionObjectEffects test suite', () => {
|
|||||||
b: new SaveSubmissionFormSuccessAction(
|
b: new SaveSubmissionFormSuccessAction(
|
||||||
submissionId,
|
submissionId,
|
||||||
mockSubmissionRestResponse as any,
|
mockSubmissionRestResponse as any,
|
||||||
|
true,
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
@@ -260,6 +261,7 @@ describe('SubmissionObjectEffects test suite', () => {
|
|||||||
b: new SaveSubmissionFormSuccessAction(
|
b: new SaveSubmissionFormSuccessAction(
|
||||||
submissionId,
|
submissionId,
|
||||||
mockSubmissionRestResponse as any,
|
mockSubmissionRestResponse as any,
|
||||||
|
false,
|
||||||
false
|
false
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
@@ -884,6 +886,7 @@ describe('SubmissionObjectEffects test suite', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(submissionObjectEffects.saveAndDeposit$).toBeObservable(expected);
|
expect(submissionObjectEffects.saveAndDeposit$).toBeObservable(expected);
|
||||||
|
expect(notificationsServiceStub.warning).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return a SAVE_SUBMISSION_FORM_SUCCESS action when there are errors', () => {
|
it('should return a SAVE_SUBMISSION_FORM_SUCCESS action when there are errors', () => {
|
||||||
@@ -910,10 +913,11 @@ describe('SubmissionObjectEffects test suite', () => {
|
|||||||
submissionJsonPatchOperationsServiceStub.jsonPatchByResourceType.and.returnValue(observableOf(response));
|
submissionJsonPatchOperationsServiceStub.jsonPatchByResourceType.and.returnValue(observableOf(response));
|
||||||
|
|
||||||
const expected = cold('--b-', {
|
const expected = cold('--b-', {
|
||||||
b: new SaveSubmissionFormSuccessAction(submissionId, response as any[])
|
b: new SaveSubmissionFormSuccessAction(submissionId, response as any[], false, true)
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(submissionObjectEffects.saveAndDeposit$).toBeObservable(expected);
|
expect(submissionObjectEffects.saveAndDeposit$).toBeObservable(expected);
|
||||||
|
expect(notificationsServiceStub.warning).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should catch errors and return a SAVE_SUBMISSION_FORM_ERROR', () => {
|
it('should catch errors and return a SAVE_SUBMISSION_FORM_ERROR', () => {
|
||||||
|
@@ -127,7 +127,7 @@ export class SubmissionObjectEffects {
|
|||||||
this.submissionService.getSubmissionObjectLinkName(),
|
this.submissionService.getSubmissionObjectLinkName(),
|
||||||
action.payload.submissionId,
|
action.payload.submissionId,
|
||||||
'sections').pipe(
|
'sections').pipe(
|
||||||
map((response: SubmissionObject[]) => new SaveSubmissionFormSuccessAction(action.payload.submissionId, response, action.payload.isManual)),
|
map((response: SubmissionObject[]) => new SaveSubmissionFormSuccessAction(action.payload.submissionId, response, action.payload.isManual, action.payload.isManual)),
|
||||||
catchError(() => observableOf(new SaveSubmissionFormErrorAction(action.payload.submissionId))));
|
catchError(() => observableOf(new SaveSubmissionFormErrorAction(action.payload.submissionId))));
|
||||||
})));
|
})));
|
||||||
|
|
||||||
@@ -153,7 +153,8 @@ export class SubmissionObjectEffects {
|
|||||||
withLatestFrom(this.store$),
|
withLatestFrom(this.store$),
|
||||||
map(([action, currentState]: [SaveSubmissionFormSuccessAction, any]) => {
|
map(([action, currentState]: [SaveSubmissionFormSuccessAction, any]) => {
|
||||||
return this.parseSaveResponse((currentState.submission as SubmissionState).objects[action.payload.submissionId],
|
return this.parseSaveResponse((currentState.submission as SubmissionState).objects[action.payload.submissionId],
|
||||||
action.payload.submissionObject, action.payload.submissionId, currentState.forms, action.payload.notify);
|
action.payload.submissionObject, action.payload.submissionId, currentState.forms,
|
||||||
|
action.payload.showNotifications, action.payload.showErrors);
|
||||||
}),
|
}),
|
||||||
mergeMap((actions) => observableFrom(actions))));
|
mergeMap((actions) => observableFrom(actions))));
|
||||||
|
|
||||||
@@ -166,7 +167,7 @@ export class SubmissionObjectEffects {
|
|||||||
withLatestFrom(this.store$),
|
withLatestFrom(this.store$),
|
||||||
map(([action, currentState]: [SaveSubmissionSectionFormSuccessAction, any]) => {
|
map(([action, currentState]: [SaveSubmissionSectionFormSuccessAction, any]) => {
|
||||||
return this.parseSaveResponse((currentState.submission as SubmissionState).objects[action.payload.submissionId],
|
return this.parseSaveResponse((currentState.submission as SubmissionState).objects[action.payload.submissionId],
|
||||||
action.payload.submissionObject, action.payload.submissionId, currentState.forms, false);
|
action.payload.submissionObject, action.payload.submissionId, currentState.forms, false, false);
|
||||||
}),
|
}),
|
||||||
mergeMap((actions) => observableFrom(actions))));
|
mergeMap((actions) => observableFrom(actions))));
|
||||||
|
|
||||||
@@ -217,7 +218,13 @@ export class SubmissionObjectEffects {
|
|||||||
if (this.canDeposit(response)) {
|
if (this.canDeposit(response)) {
|
||||||
return new DepositSubmissionAction(action.payload.submissionId);
|
return new DepositSubmissionAction(action.payload.submissionId);
|
||||||
} else {
|
} else {
|
||||||
return new SaveSubmissionFormSuccessAction(action.payload.submissionId, response);
|
this.notificationsService.warning(
|
||||||
|
null,
|
||||||
|
this.translate.instant('submission.sections.general.cannot_deposit'),
|
||||||
|
null,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
return new SaveSubmissionFormSuccessAction(action.payload.submissionId, response, false, true);
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
catchError(() => observableOf(new SaveSubmissionFormErrorAction(action.payload.submissionId))));
|
catchError(() => observableOf(new SaveSubmissionFormErrorAction(action.payload.submissionId))));
|
||||||
@@ -363,18 +370,23 @@ export class SubmissionObjectEffects {
|
|||||||
* A boolean that indicate if show notification or not
|
* A boolean that indicate if show notification or not
|
||||||
* @return SubmissionObjectAction[]
|
* @return SubmissionObjectAction[]
|
||||||
* List of SubmissionObjectAction to dispatch
|
* List of SubmissionObjectAction to dispatch
|
||||||
|
* @param showNotifications
|
||||||
|
* A boolean representing if to show notifications on save
|
||||||
|
* @param showErrors
|
||||||
|
* A boolean representing if to show errors on save
|
||||||
*/
|
*/
|
||||||
protected parseSaveResponse(
|
protected parseSaveResponse(
|
||||||
currentState: SubmissionObjectEntry,
|
currentState: SubmissionObjectEntry,
|
||||||
response: SubmissionObject[],
|
response: SubmissionObject[],
|
||||||
submissionId: string,
|
submissionId: string,
|
||||||
forms: FormState,
|
forms: FormState,
|
||||||
notify: boolean = true): SubmissionObjectAction[] {
|
showNotifications: boolean = true,
|
||||||
|
showErrors: boolean = true): SubmissionObjectAction[] {
|
||||||
|
|
||||||
const mappedActions = [];
|
const mappedActions = [];
|
||||||
|
|
||||||
if (isNotEmpty(response)) {
|
if (isNotEmpty(response)) {
|
||||||
if (notify) {
|
if (showNotifications) {
|
||||||
this.notificationsService.success(null, this.translate.get('submission.sections.general.save_success_notice'));
|
this.notificationsService.success(null, this.translate.get('submission.sections.general.save_success_notice'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -386,7 +398,7 @@ export class SubmissionObjectEffects {
|
|||||||
if (errors && !isEmpty(errors)) {
|
if (errors && !isEmpty(errors)) {
|
||||||
// to avoid dispatching an action for every error, create an array of errors per section
|
// to avoid dispatching an action for every error, create an array of errors per section
|
||||||
errorsList = parseSectionErrors(errors);
|
errorsList = parseSectionErrors(errors);
|
||||||
if (notify) {
|
if (showNotifications) {
|
||||||
this.notificationsService.warning(null, this.translate.get('submission.sections.general.sections_not_valid'));
|
this.notificationsService.warning(null, this.translate.get('submission.sections.general.sections_not_valid'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -405,12 +417,12 @@ export class SubmissionObjectEffects {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (notify && !currentState.sections[sectionId].enabled) {
|
if (showNotifications && !currentState.sections[sectionId].enabled) {
|
||||||
this.submissionService.notifyNewSection(submissionId, sectionId, currentState.sections[sectionId].sectionType);
|
this.submissionService.notifyNewSection(submissionId, sectionId, currentState.sections[sectionId].sectionType);
|
||||||
}
|
}
|
||||||
|
|
||||||
const sectionForm = getForm(forms, currentState, sectionId);
|
const sectionForm = getForm(forms, currentState, sectionId);
|
||||||
const filteredErrors = filterErrors(sectionForm, sectionErrors, currentState.sections[sectionId].sectionType, notify);
|
const filteredErrors = filterErrors(sectionForm, sectionErrors, currentState.sections[sectionId].sectionType, showErrors);
|
||||||
mappedActions.push(new UpdateSectionDataAction(submissionId, sectionId, sectionData, filteredErrors, sectionErrors));
|
mappedActions.push(new UpdateSectionDataAction(submissionId, sectionId, sectionData, filteredErrors, sectionErrors));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@@ -3828,6 +3828,8 @@
|
|||||||
|
|
||||||
"submission.sections.general.add-more": "Add more",
|
"submission.sections.general.add-more": "Add more",
|
||||||
|
|
||||||
|
"submission.sections.general.cannot_deposit": "Deposit cannot be completed due to errors in the form.<br>Please fill out all required fields to complete the deposit.",
|
||||||
|
|
||||||
"submission.sections.general.collection": "Collection",
|
"submission.sections.general.collection": "Collection",
|
||||||
|
|
||||||
"submission.sections.general.deposit_error_notice": "There was an issue when submitting the item, please try again later.",
|
"submission.sections.general.deposit_error_notice": "There was an issue when submitting the item, please try again later.",
|
||||||
|
Reference in New Issue
Block a user