From 0e18c2fe13b72c9b91f9b4dbcaf883c70cae2d4b Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 23 Jan 2019 17:30:26 -0500 Subject: [PATCH] LP1807461 Admin page avoid errors on dialog dismissal Add support to the base DialogComponent class for passing information to the caller via the reject handler about whether a dialog was dismissed via user interface interaction (body click, esc key, cross click, cancel button) or for some other reason, presumably an error. Teach the generic admin page to avoid toasting errors when an edit or create dialog is dismissed via UI. Signed-off-by: Bill Erickson Signed-off-by: Dan Wells --- .../src/app/share/dialog/dialog.component.ts | 26 ++++++++++++++++++- .../share/admin-page/admin-page.component.ts | 16 +++++++----- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/share/dialog/dialog.component.ts b/Open-ILS/src/eg2/src/app/share/dialog/dialog.component.ts index 3ffd5db069..b7531a2a20 100644 --- a/Open-ILS/src/eg2/src/app/share/dialog/dialog.component.ts +++ b/Open-ILS/src/eg2/src/app/share/dialog/dialog.component.ts @@ -7,6 +7,13 @@ import {NgbModal, NgbModalRef, NgbModalOptions} from '@ng-bootstrap/ng-bootstrap * at the root of the template (see ConfirmDialogComponent). */ +export interface DialogRejectionResponse { + // Did the user simply close the dialog without performing an action. + dismissed?: boolean; + // Relays error, etc. messages from the dialog handler to the caller. + message?: string; +} + @Component({ selector: 'eg-dialog', template: '' @@ -55,9 +62,26 @@ export class DialogComponent implements OnInit { resolve(result); this.modalRef = null; }, + (result) => { + // NgbModal creates some result values for us, which + // are outside of our control. Other dismissal + // reasons are agreed upon by implementing subclasses. console.debug('dialog closed with ' + result); - reject(result); + + const dismissed = ( + result === 0 // body click + || result === 1 // Esc key + || result === 'canceled' // Cancel button + || result === 'cross_click' // modal top-right X + ); + + const rejection: DialogRejectionResponse = { + dismissed: dismissed, + message: result + }; + + reject(rejection); this.modalRef = null; } ); diff --git a/Open-ILS/src/eg2/src/app/staff/share/admin-page/admin-page.component.ts b/Open-ILS/src/eg2/src/app/staff/share/admin-page/admin-page.component.ts index cfb01e5fa3..cd6e706660 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/admin-page/admin-page.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/share/admin-page/admin-page.component.ts @@ -180,9 +180,11 @@ export class AdminPageComponent implements OnInit { .then(str => this.toast.success(str)); this.grid.reload(); }, - err => { - this.createErrString.current() - .then(str => this.toast.danger(str)); + rejection => { + if (!rejection.dismissed) { + this.createErrString.current() + .then(str => this.toast.danger(str)); + } } ); }; @@ -326,9 +328,11 @@ export class AdminPageComponent implements OnInit { .then(str => this.toast.success(str)); this.grid.reload(); }, - err => { - this.updateFailedString.current() - .then(str => this.toast.danger(str)); + rejection => { + if (!rejection.dismissed) { + this.updateFailedString.current() + .then(str => this.toast.danger(str)); + } } ); } -- 2.43.2