From 167c50e9a3162e4c81e97d2c9e8d440152337c4c Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Thu, 28 Feb 2019 18:39:12 +0100 Subject: [PATCH] Dispaly an error notification when an error occured on submission save --- resources/i18n/en.json | 2 +- .../json-patch-operations.service.spec.ts | 9 ++++-- .../json-patch-operations.service.ts | 4 +-- .../submission-objects.effects.spec.ts | 32 +++++++++++++++++++ .../objects/submission-objects.effects.ts | 5 +++ 5 files changed, 47 insertions(+), 5 deletions(-) diff --git a/resources/i18n/en.json b/resources/i18n/en.json index a05cb6c24e..30011b30c1 100644 --- a/resources/i18n/en.json +++ b/resources/i18n/en.json @@ -645,7 +645,7 @@ "collection": "Collection", "no-collection": "No collection found", "search-collection": "Search for a collection", - + "save_error_notice": "There was an issue when saving the item, please try again later.", "deposit_success_notice": "Submission deposited successfully.", "deposit_error_notice": "There was an issue when submitting the item, please try again later.", "discard_success_notice": "Submission discarded successfully.", diff --git a/src/app/core/json-patch/json-patch-operations.service.spec.ts b/src/app/core/json-patch/json-patch-operations.service.spec.ts index 67751ee9a9..4ecc215dc7 100644 --- a/src/app/core/json-patch/json-patch-operations.service.spec.ts +++ b/src/app/core/json-patch/json-patch-operations.service.spec.ts @@ -23,6 +23,7 @@ import { } from './json-patch-operations.actions'; import { MockStore } from '../../shared/testing/mock-store'; import { RequestEntry } from '../data/request.reducer'; +import { catchError } from 'rxjs/operators'; class TestService extends JsonPatchOperationsService { protected linkPath = ''; @@ -176,7 +177,9 @@ describe('JsonPatchOperationsService test suite', () => { it('should dispatch a new RollbacktPatchOperationsAction', () => { const expectedAction = new RollbacktPatchOperationsAction(testJsonPatchResourceType, undefined); - scheduler.schedule(() => service.jsonPatchByResourceType(resourceEndpoint, resourceScope, testJsonPatchResourceType).subscribe()); + scheduler.schedule(() => service.jsonPatchByResourceType(resourceEndpoint, resourceScope, testJsonPatchResourceType) + .pipe(catchError(() => observableOf({}))) + .subscribe()); scheduler.flush(); expect(store.dispatch).toHaveBeenCalledWith(expectedAction); @@ -237,7 +240,9 @@ describe('JsonPatchOperationsService test suite', () => { it('should dispatch a new RollbacktPatchOperationsAction', () => { const expectedAction = new RollbacktPatchOperationsAction(testJsonPatchResourceType, testJsonPatchResourceId); - scheduler.schedule(() => service.jsonPatchByResourceID(resourceEndpoint, resourceScope, testJsonPatchResourceType, testJsonPatchResourceId).subscribe()); + scheduler.schedule(() => service.jsonPatchByResourceID(resourceEndpoint, resourceScope, testJsonPatchResourceType, testJsonPatchResourceId) + .pipe(catchError(() => observableOf({}))) + .subscribe()); scheduler.flush(); expect(store.dispatch).toHaveBeenCalledWith(expectedAction); diff --git a/src/app/core/json-patch/json-patch-operations.service.ts b/src/app/core/json-patch/json-patch-operations.service.ts index 7ca59e8b39..90eaf87a0e 100644 --- a/src/app/core/json-patch/json-patch-operations.service.ts +++ b/src/app/core/json-patch/json-patch-operations.service.ts @@ -1,4 +1,4 @@ -import { merge as observableMerge, Observable, of as observableOf } from 'rxjs'; +import { merge as observableMerge, Observable, throwError as observableThrowError } from 'rxjs'; import { distinctUntilChanged, filter, find, flatMap, map, partition, take, tap } from 'rxjs/operators'; import { Store } from '@ngrx/store'; @@ -94,7 +94,7 @@ export abstract class JsonPatchOperationsService this.store.dispatch(new RollbacktPatchOperationsAction(resourceType, resourceId))), - flatMap((response: ErrorResponse) => observableOf(new Error(`Couldn't patch operations`)))), + flatMap((error: ErrorResponse) => observableThrowError(error))), successResponse$.pipe( filter((response: PostPatchSuccessResponse) => isNotEmpty(response)), tap(() => this.store.dispatch(new CommitPatchOperationsAction(resourceType, resourceId))), diff --git a/src/app/submission/objects/submission-objects.effects.spec.ts b/src/app/submission/objects/submission-objects.effects.spec.ts index d773bef751..8bbdd4e0ee 100644 --- a/src/app/submission/objects/submission-objects.effects.spec.ts +++ b/src/app/submission/objects/submission-objects.effects.spec.ts @@ -715,6 +715,38 @@ describe('SubmissionObjectEffects test suite', () => { }); }); + describe('saveError$', () => { + it('should display a new error notification', () => { + actions = hot('--a-', { + a: { + type: SubmissionObjectActionTypes.SAVE_SUBMISSION_FORM_ERROR, + payload: { + submissionId: submissionId + } + } + }); + + submissionObjectEffects.saveError$.subscribe(() => { + expect(notificationsServiceStub.error).toHaveBeenCalled(); + }); + }); + + it('should display a new error notification', () => { + actions = hot('--a-', { + a: { + type: SubmissionObjectActionTypes.SAVE_SUBMISSION_SECTION_FORM_ERROR, + payload: { + submissionId: submissionId + } + } + }); + + submissionObjectEffects.saveError$.subscribe(() => { + expect(notificationsServiceStub.error).toHaveBeenCalled(); + }); + }); + }); + describe('discardSubmission$', () => { it('should return a DISCARD_SUBMISSION_SUCCESS action on success', () => { store.nextState({ diff --git a/src/app/submission/objects/submission-objects.effects.ts b/src/app/submission/objects/submission-objects.effects.ts index 2127836c22..bebec482c2 100644 --- a/src/app/submission/objects/submission-objects.effects.ts +++ b/src/app/submission/objects/submission-objects.effects.ts @@ -137,6 +137,11 @@ export class SubmissionObjectEffects { catchError(() => observableOf(new SaveSubmissionSectionFormErrorAction(action.payload.submissionId)))); })); + @Effect({dispatch: false}) saveError$ = this.actions$.pipe( + ofType(SubmissionObjectActionTypes.SAVE_SUBMISSION_FORM_ERROR, SubmissionObjectActionTypes.SAVE_SUBMISSION_SECTION_FORM_ERROR), + withLatestFrom(this.store$), + tap(() => this.notificationsService.error(null, this.translate.get('submission.sections.general.save_error_notice')))); + @Effect() saveAndDeposit$ = this.actions$.pipe( ofType(SubmissionObjectActionTypes.SAVE_AND_DEPOSIT_SUBMISSION), withLatestFrom(this.store$),