improve how picklist operation failures are displayed to user
authorGalen Charlton <gmc@equinoxinitiative.org>
Tue, 11 Feb 2020 22:56:22 +0000 (17:56 -0500)
committerGalen Charlton <gmc@equinoxinitiative.org>
Tue, 11 Feb 2020 22:56:22 +0000 (17:56 -0500)
- don't show the success toast unless the operation has actually
  succeeded
- give user a hint if creation failed because of a duplicate name

Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/eg2/src/app/staff/acq/search/picklist-clone-dialog.component.ts
Open-ILS/src/eg2/src/app/staff/acq/search/picklist-create-dialog.component.html
Open-ILS/src/eg2/src/app/staff/acq/search/picklist-create-dialog.component.ts
Open-ILS/src/eg2/src/app/staff/acq/search/picklist-delete-dialog.component.ts
Open-ILS/src/eg2/src/app/staff/acq/search/picklist-merge-dialog.component.ts
Open-ILS/src/eg2/src/app/staff/acq/search/picklist-results.component.ts

index e2b23d3..aceca1e 100644 (file)
@@ -59,6 +59,7 @@ export class PicklistCloneDialogComponent
         if (this.evt.parse(res)) {
           console.error(res);
           this.fail.open();
+          this.close(false);
         } else {
           console.log(res);
         }
@@ -66,6 +67,7 @@ export class PicklistCloneDialogComponent
       (err) => {
         console.error(err);
         this.fail.open();
+        this.close(false);
       },
       () => this.close(true)
     );
index b4ac8ad..0f36ab7 100644 (file)
@@ -25,3 +25,6 @@
 <eg-alert-dialog #fail i18n-dialogBody
   dialogBody="Could not create this selection list.">
 </eg-alert-dialog>
+<eg-alert-dialog #dupe i18n-dialogBody
+  dialogBody="Could not create this selection list: name already in use.">
+</eg-alert-dialog>
index 9a5a8da..f4f81b3 100644 (file)
@@ -20,6 +20,7 @@ export class PicklistCreateDialogComponent
   selectionListName: String;
 
   @ViewChild('fail', { static: true }) private fail: AlertDialogComponent;
+  @ViewChild('dupe', { static: true }) private dupe: AlertDialogComponent;
 
   constructor(
     private renderer: Renderer2,
@@ -53,7 +54,14 @@ export class PicklistCreateDialogComponent
       (res) => {
         if (this.evt.parse(res)) {
           console.error(res);
-          this.fail.open();
+          if (res.textcode === 'DATABASE_UPDATE_FAILED') {
+            // a duplicate name is not the only reason it could have failed,
+            // but that's the way to bet
+            this.dupe.open();
+          } else {
+            this.fail.open();
+          }
+          this.close(false);
         } else {
           console.log(res);
         }
@@ -61,6 +69,7 @@ export class PicklistCreateDialogComponent
       (err) => {
         console.error(err);
         this.fail.open();
+        this.close(false);
       },
       () => this.close(true)
     );
index 401937e..f7cfd49 100644 (file)
@@ -59,6 +59,7 @@ export class PicklistDeleteDialogComponent
         if (this.evt.parse(res)) {
           console.error(res);
           this.fail.open();
+          this.close(false);
         } else {
           console.log(res);
         }
@@ -66,6 +67,7 @@ export class PicklistDeleteDialogComponent
       (err) => {
         console.error(err);
         this.fail.open();
+        this.close(false);
       },
       () => this.close(true)
     );
index dca24cf..60ed6d6 100644 (file)
@@ -54,6 +54,7 @@ export class PicklistMergeDialogComponent
         if (this.evt.parse(res)) {
           console.error(res);
           this.fail.open();
+          this.close(false);
         } else {
           console.log(res);
         }
@@ -61,6 +62,7 @@ export class PicklistMergeDialogComponent
       (err) => {
         console.error(err);
         this.fail.open();
+        this.close(false);
       },
       () => this.close(true)
     );
index 3705ad1..d0c5bbe 100644 (file)
@@ -75,6 +75,7 @@ export class PicklistResultsComponent implements OnInit {
     openCreateDialog() {
         this.picklistCreateDialog.open().subscribe(
             modified => {
+                if (!modified) { return; }
                 this.createSelectionListString.current().then(msg => this.toast.success(msg));
                 this.picklistResultsGrid.reload(); // FIXME - spec calls for inserted grid row and not refresh
             }
@@ -85,6 +86,7 @@ export class PicklistResultsComponent implements OnInit {
     openCloneDialog(rows: IdlObject[]) {
         this.picklistCloneDialog.open().subscribe(
             modified => {
+                if (!modified) { return; }
                 this.cloneSelectionListString.current().then(msg => this.toast.success(msg));
                 this.picklistResultsGrid.reload(); // FIXME - spec calls for inserted grid row and not refresh
             }
@@ -95,6 +97,7 @@ export class PicklistResultsComponent implements OnInit {
     openDeleteDialog(rows: IdlObject[]) {
         this.picklistDeleteDialog.open().subscribe(
             modified => {
+                if (!modified) { return; }
                 this.deleteSelectionListString.current().then(msg => this.toast.success(msg));
                 this.picklistResultsGrid.reload(); // FIXME - spec calls for removed grid rows and not refresh
             }
@@ -105,6 +108,7 @@ export class PicklistResultsComponent implements OnInit {
     openMergeDialog(rows: IdlObject[]) {
         this.picklistMergeDialog.open().subscribe(
             modified => {
+                if (!modified) { return; }
                 this.mergeSelectionListString.current().then(msg => this.toast.success(msg));
                 this.picklistResultsGrid.reload(); // FIXME - spec calls for removed grid rows and not refresh
             }