LP1904036 Clear patron context data on navigation
authorBill Erickson <berickxx@gmail.com>
Thu, 24 Feb 2022 15:47:40 +0000 (10:47 -0500)
committerGalen Charlton <gmc@equinoxOLI.org>
Fri, 28 Oct 2022 00:13:41 +0000 (20:13 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Jane Sandberg <js7389@princeton.edu>
Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Open-ILS/src/eg2/src/app/staff/circ/patron/patron.component.ts
Open-ILS/src/eg2/src/app/staff/circ/patron/patron.service.ts

index 96f64d8..d476cbf 100644 (file)
@@ -36,7 +36,6 @@ export class PatronComponent implements OnInit, AfterViewInit {
     showSummary = true;
     loading = true;
     showRecentPatrons = false;
-    refreshing = false;
 
     /* eg-patron-edit is unable to find #editorToolbar directly
      * within the template.  Adding a ref here allows it to
@@ -120,21 +119,14 @@ export class PatronComponent implements OnInit, AfterViewInit {
 
     watchForTabChange() {
 
-        // When routing to a patron UI from a non-patron UI, refresh the
-        // patron's data so we pick up an external changes (e.g. holds
-        // placement).  This is needed because the last active patron,
-        // if one exists, will still be cached in the patron service,
-        // which survives route changes.  Route events occur in series
-        // and often repeat, though, so avoid refreshing the patron if
-        // we are already mid-refresh.
+        // When routing to a patron UI from a non-patron UI, clear all
+        // patron info that may have persisted via the context service.
         this.router.events
             .pipe(filter((evt: any) => evt instanceof RoutesRecognized), pairwise())
             .subscribe((events: RoutesRecognized[]) => {
-                const prevUrl = events[0].urlAfterRedirects;
-
-                if (!prevUrl.startsWith('/staff/circ/patron') && !this.refreshing) {
-                    this.refreshing = true;
-                    this.context.refreshPatron().then(_ => this.refreshing = false);
+                const prevUrl = events[0].urlAfterRedirects || '';
+                if (!prevUrl.startsWith('/staff/circ/patron')) {
+                    this.context.reset();
                 }
             });
 
index 3c677cd..e696cba 100644 (file)
@@ -72,6 +72,14 @@ export class PatronContextService {
         public patrons: PatronService
     ) {}
 
+    reset() {
+        this.summary = null;
+        this.loaded = false;
+        this.lastPatronSearch = null;
+        this.searchBarcode = null;
+        this.checkouts = [];
+    }
+
     loadPatron(id: number): Promise<any> {
         this.loaded = false;
         this.checkouts = [];
@@ -83,7 +91,7 @@ export class PatronContextService {
 
         if (!id) {
             if (!this.summary) {
-                return Promise.reject('no can do');
+                return Promise.resolve();
             } else {
                 id = this.summary.id;
             }