LP1837067: Fixing race condition in Replace Barcodes dialog user/sandbergja/lp1837067_race_condition_in_replace_barcode
authorJane Sandberg <sandbej@linnbenton.edu>
Thu, 18 Jul 2019 15:22:35 +0000 (08:22 -0700)
committerJane Sandberg <sandbej@linnbenton.edu>
Thu, 18 Jul 2019 15:22:35 +0000 (08:22 -0700)
To test:
1) In the experimental Angular staff catalog, open up a bib record.
2) Open the Holdings View tab.
3) Select several items.
4) Use the Actions for Selected Rows menu to Replace Barcodes
5) Change the first barcode to something recognizable. Click the
Replace Barcode button.
6) Note that the dialog opens again to ask you to replace the
barcode you just added.
7) Apply this patch.
8) Repeat steps 1-5.
9) Note that the dialog opens again to ask you to replace the next
barcode.

Also removes some unused imports, and consolidates two RxJS pipes that
were next to one another.

Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
Open-ILS/src/eg2/src/app/staff/share/holdings/replace-barcode-dialog.component.ts

index 2b85d38..de7787c 100644 (file)
@@ -2,11 +2,8 @@ import {Component, OnInit, Input, ViewChild, Renderer2} from '@angular/core';
 import {Observable, throwError} from 'rxjs';
 import {switchMap, map, tap} from 'rxjs/operators';
 import {IdlObject} from '@eg/core/idl.service';
-import {NetService} from '@eg/core/net.service';
-import {EventService} from '@eg/core/event.service';
 import {PcrudService} from '@eg/core/pcrud.service';
 import {ToastService} from '@eg/share/toast/toast.service';
-import {AuthService} from '@eg/core/auth.service';
 import {NgbModal, NgbModalOptions} from '@ng-bootstrap/ng-bootstrap';
 import {DialogComponent} from '@eg/share/dialog/dialog.component';
 import {StringComponent} from '@eg/share/string/string.component';
@@ -43,11 +40,8 @@ export class ReplaceBarcodeDialogComponent
     constructor(
         private modal: NgbModal, // required for passing to parent
         private toast: ToastService,
-        private net: NetService,
         private pcrud: PcrudService,
-        private evt: EventService,
-        private renderer: Renderer2,
-        private auth: AuthService) {
+        private renderer: Renderer2) {
         super(modal); // required for subclassing
     }
 
@@ -59,9 +53,9 @@ export class ReplaceBarcodeDialogComponent
         this.numFailed = 0;
 
         return this.getNextCopy()
-        .pipe(switchMap(() => super.open(args)))
-        .pipe(tap(() =>
-            this.renderer.selectRootElement('#new-barcode-input').focus())
+        .pipe(switchMap(() => super.open(args)),
+            tap(() =>
+                this.renderer.selectRootElement('#new-barcode-input').focus())
         );
     }
 
@@ -93,10 +87,13 @@ export class ReplaceBarcodeDialogComponent
 
             this.copy.barcode(this.newBarcode);
             this.pcrud.update(this.copy).toPromise().then(
-                async (ok) => {
+                (ok) => {
                     this.numSucceeded++;
-                    this.toast.success(await this.successMsg.current());
-                    this.getNextCopy();
+                    return this.successMsg.current()
+                    .then((msg) => {
+                        this.toast.success(msg);
+                        return this.getNextCopy().toPromise();
+                    });
                 },
                 async (err) => {
                     this.numFailed++;