Dispaly an error notification when an error occured on submission save

This commit is contained in:
Giuseppe Digilio
2019-02-28 18:39:12 +01:00
parent ce06b1af2a
commit 167c50e9a3
5 changed files with 47 additions and 5 deletions

View File

@@ -645,7 +645,7 @@
"collection": "Collection", "collection": "Collection",
"no-collection": "No collection found", "no-collection": "No collection found",
"search-collection": "Search for a collection", "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_success_notice": "Submission deposited successfully.",
"deposit_error_notice": "There was an issue when submitting the item, please try again later.", "deposit_error_notice": "There was an issue when submitting the item, please try again later.",
"discard_success_notice": "Submission discarded successfully.", "discard_success_notice": "Submission discarded successfully.",

View File

@@ -23,6 +23,7 @@ import {
} from './json-patch-operations.actions'; } from './json-patch-operations.actions';
import { MockStore } from '../../shared/testing/mock-store'; import { MockStore } from '../../shared/testing/mock-store';
import { RequestEntry } from '../data/request.reducer'; import { RequestEntry } from '../data/request.reducer';
import { catchError } from 'rxjs/operators';
class TestService extends JsonPatchOperationsService<SubmitDataResponseDefinitionObject, SubmissionPatchRequest> { class TestService extends JsonPatchOperationsService<SubmitDataResponseDefinitionObject, SubmissionPatchRequest> {
protected linkPath = ''; protected linkPath = '';
@@ -176,7 +177,9 @@ describe('JsonPatchOperationsService test suite', () => {
it('should dispatch a new RollbacktPatchOperationsAction', () => { it('should dispatch a new RollbacktPatchOperationsAction', () => {
const expectedAction = new RollbacktPatchOperationsAction(testJsonPatchResourceType, undefined); 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(); scheduler.flush();
expect(store.dispatch).toHaveBeenCalledWith(expectedAction); expect(store.dispatch).toHaveBeenCalledWith(expectedAction);
@@ -237,7 +240,9 @@ describe('JsonPatchOperationsService test suite', () => {
it('should dispatch a new RollbacktPatchOperationsAction', () => { it('should dispatch a new RollbacktPatchOperationsAction', () => {
const expectedAction = new RollbacktPatchOperationsAction(testJsonPatchResourceType, testJsonPatchResourceId); 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(); scheduler.flush();
expect(store.dispatch).toHaveBeenCalledWith(expectedAction); expect(store.dispatch).toHaveBeenCalledWith(expectedAction);

View File

@@ -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 { distinctUntilChanged, filter, find, flatMap, map, partition, take, tap } from 'rxjs/operators';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
@@ -94,7 +94,7 @@ export abstract class JsonPatchOperationsService<ResponseDefinitionDomain, Patch
return observableMerge( return observableMerge(
errorResponse$.pipe( errorResponse$.pipe(
tap(() => this.store.dispatch(new RollbacktPatchOperationsAction(resourceType, resourceId))), tap(() => this.store.dispatch(new RollbacktPatchOperationsAction(resourceType, resourceId))),
flatMap((response: ErrorResponse) => observableOf(new Error(`Couldn't patch operations`)))), flatMap((error: ErrorResponse) => observableThrowError(error))),
successResponse$.pipe( successResponse$.pipe(
filter((response: PostPatchSuccessResponse) => isNotEmpty(response)), filter((response: PostPatchSuccessResponse) => isNotEmpty(response)),
tap(() => this.store.dispatch(new CommitPatchOperationsAction(resourceType, resourceId))), tap(() => this.store.dispatch(new CommitPatchOperationsAction(resourceType, resourceId))),

View File

@@ -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$', () => { describe('discardSubmission$', () => {
it('should return a DISCARD_SUBMISSION_SUCCESS action on success', () => { it('should return a DISCARD_SUBMISSION_SUCCESS action on success', () => {
store.nextState({ store.nextState({

View File

@@ -137,6 +137,11 @@ export class SubmissionObjectEffects {
catchError(() => observableOf(new SaveSubmissionSectionFormErrorAction(action.payload.submissionId)))); 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( @Effect() saveAndDeposit$ = this.actions$.pipe(
ofType(SubmissionObjectActionTypes.SAVE_AND_DEPOSIT_SUBMISSION), ofType(SubmissionObjectActionTypes.SAVE_AND_DEPOSIT_SUBMISSION),
withLatestFrom(this.store$), withLatestFrom(this.store$),