From ec39a98deca847d7738ac8fd553041cf063af19e Mon Sep 17 00:00:00 2001 From: Bogdan Cilibiu Date: Tue, 11 Dec 2018 17:09:52 +0200 Subject: [PATCH 1/3] router event filter search --- .../components/layout/app-layout/app-layout.component.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/app/components/layout/app-layout/app-layout.component.ts b/src/app/components/layout/app-layout/app-layout.component.ts index 1bf756966d..5bbf602ca0 100644 --- a/src/app/components/layout/app-layout/app-layout.component.ts +++ b/src/app/components/layout/app-layout/app-layout.component.ts @@ -135,7 +135,12 @@ export class AppLayoutComponent implements OnInit, OnDestroy { this.router.events .pipe( - filter(event => event instanceof NavigationStart), + filter(event => { + return ( + event instanceof NavigationStart && + !event.url.startsWith('/search;') + ); + }), takeUntil(this.onDestroy$) ) .subscribe(() => this.store.dispatch(new SetSelectedNodesAction([]))); From 165ce298ded533654310ec74cc3e97525086a582 Mon Sep 17 00:00:00 2001 From: Bogdan Cilibiu Date: Tue, 11 Dec 2018 17:10:17 +0200 Subject: [PATCH 2/3] test --- .../app-layout/app-layout.component.spec.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/app/components/layout/app-layout/app-layout.component.spec.ts b/src/app/components/layout/app-layout/app-layout.component.spec.ts index 701ac1d6c4..56c5c6b80f 100644 --- a/src/app/components/layout/app-layout/app-layout.component.spec.ts +++ b/src/app/components/layout/app-layout/app-layout.component.spec.ts @@ -41,7 +41,7 @@ class MockRouter { events = this.subject.asObservable(); routerState = { snapshot: { url: this.url } }; - navigate(url: string) { + navigateByUrl(url: string) { const navigationStart = new NavigationStart(0, url); this.subject.next(navigationStart); } @@ -143,11 +143,24 @@ describe('AppLayoutComponent', () => { const selection = [{ entry: { id: 'nodeId', name: 'name' } }]; store.dispatch(new SetSelectedNodesAction(selection)); - router.navigate(['somewhere/over/the/rainbow']); + router.navigateByUrl('somewhere/over/the/rainbow'); fixture.detectChanges(); store.select(appSelection).subscribe(state => { expect(state.isEmpty).toBe(true); done(); }); }); + + it('should not reset selection if route is `/search`', done => { + fixture.detectChanges(); + const selection = [{ entry: { id: 'nodeId', name: 'name' } }]; + store.dispatch(new SetSelectedNodesAction(selection)); + + router.navigateByUrl('/search;q='); + fixture.detectChanges(); + store.select(appSelection).subscribe(state => { + expect(state.isEmpty).toBe(false); + done(); + }); + }); }); From 3e12d9e95e79e61ba9e15a105c39f542828619cf Mon Sep 17 00:00:00 2001 From: Bogdan Cilibiu Date: Tue, 11 Dec 2018 17:12:13 +0200 Subject: [PATCH 3/3] added comment --- src/app/components/layout/app-layout/app-layout.component.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/components/layout/app-layout/app-layout.component.ts b/src/app/components/layout/app-layout/app-layout.component.ts index 5bbf602ca0..7ad898d830 100644 --- a/src/app/components/layout/app-layout/app-layout.component.ts +++ b/src/app/components/layout/app-layout/app-layout.component.ts @@ -138,6 +138,7 @@ export class AppLayoutComponent implements OnInit, OnDestroy { filter(event => { return ( event instanceof NavigationStart && + // search employs reuse route strategy !event.url.startsWith('/search;') ); }),