LP1807461 Admin page avoid errors on dialog dismissal
authorBill Erickson <berickxx@gmail.com>
Wed, 23 Jan 2019 22:30:26 +0000 (17:30 -0500)
committerDan Wells <dbw2@calvin.edu>
Fri, 22 Mar 2019 19:42:53 +0000 (15:42 -0400)
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 <berickxx@gmail.com>
Signed-off-by: Dan Wells <dbw2@calvin.edu>

Open-ILS/src/eg2/src/app/share/dialog/dialog.component.ts
Open-ILS/src/eg2/src/app/staff/share/admin-page/admin-page.component.ts

index 3ffd5db..b7531a2 100644 (file)
@@ -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: '<ng-template></ng-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;
                 }
             );
index cfb01e5..cd6e706 100644 (file)
@@ -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));
+                }
             }
         );
     }