From 896c89d6eacc6e0d354ff492dc9c53cef48162dc Mon Sep 17 00:00:00 2001 From: Xiao Gui <xgui3783@gmail.com> Date: Thu, 25 Nov 2021 18:19:17 +0100 Subject: [PATCH] bugfix: default value of genericInfo urls bugfix: router will now consider custom route chore: do not unnecessarily set oct removal flag --- .../genericInfoCmp/genericInfo.component.ts | 2 +- src/routerModule/router.service.spec.ts | 67 +++++++++++++------ src/routerModule/router.service.ts | 27 ++++++-- .../viewerCtrlCmp/viewerCtrlCmp.component.ts | 1 + 4 files changed, 70 insertions(+), 27 deletions(-) diff --git a/src/atlasComponents/regionalFeatures/bsFeatures/genericInfo/genericInfoCmp/genericInfo.component.ts b/src/atlasComponents/regionalFeatures/bsFeatures/genericInfo/genericInfoCmp/genericInfo.component.ts index 4b9112654..ceec64a21 100644 --- a/src/atlasComponents/regionalFeatures/bsFeatures/genericInfo/genericInfoCmp/genericInfo.component.ts +++ b/src/atlasComponents/regionalFeatures/bsFeatures/genericInfo/genericInfoCmp/genericInfo.component.ts @@ -76,7 +76,7 @@ export class GenericInfoCmp extends BsRegionInputBase implements OnChanges, Afte const { dataType, description, name, urls, useClassicUi, view, region, summary, isGdprProtected } = data this.description = description this.name = name - this.urls = urls + this.urls = urls || [] this.doiUrls = this.urls.filter(d => !!d.doi) this.useClassicUi = useClassicUi if (dataType) this.dataType = dataType diff --git a/src/routerModule/router.service.spec.ts b/src/routerModule/router.service.spec.ts index 2b933c6f1..a06a700ff 100644 --- a/src/routerModule/router.service.spec.ts +++ b/src/routerModule/router.service.spec.ts @@ -267,27 +267,56 @@ describe('> router.service.ts', () => { discardPeriodicTasks() })) - it('> ... returns same value, does not dispatches', fakeAsync(() => { - const fakeParsedState = { - bizz: 'buzz' - } - cvtFullRouteToStateSpy.and.callFake(() => fakeParsedState) - cvtStateToHashedRoutesSpy.and.callFake(() => { - return `foo/bar` - }) - router = TestBed.inject(Router) - router.navigate(['foo', 'bar']) - - const service = TestBed.inject(RouterService) - const store = TestBed.inject(MockStore) - const dispatchSpy = spyOn(store, 'dispatch') + describe('> returns the same value', () => { + it('> ... returns same value, does not dispatches', fakeAsync(() => { + const fakeParsedState = { + bizz: 'buzz' + } + cvtFullRouteToStateSpy.and.callFake(() => fakeParsedState) + cvtStateToHashedRoutesSpy.and.callFake(() => { + return `foo/bar` + }) + router = TestBed.inject(Router) + router.navigate(['foo', 'bar']) + + const service = TestBed.inject(RouterService) + const store = TestBed.inject(MockStore) + const dispatchSpy = spyOn(store, 'dispatch') + + tick(320) + + expect(dispatchSpy).not.toHaveBeenCalled() + + discardPeriodicTasks() + })) - tick(320) + it('> takes into account of customRoute', fakeAsync(() => { + const fakeParsedState = { + bizz: 'buzz' + } + cvtFullRouteToStateSpy.and.callFake(() => fakeParsedState) + cvtStateToHashedRoutesSpy.and.callFake(() => { + return `foo/bar` + }) + + const service = TestBed.inject(RouterService) + service.customRoute$ = of({ + 'x-foo': 'hello' + }) - expect(dispatchSpy).not.toHaveBeenCalled() - - discardPeriodicTasks() - })) + router = TestBed.inject(Router) + router.navigate(['foo', 'bar', 'x-foo:hello']) + + const store = TestBed.inject(MockStore) + const dispatchSpy = spyOn(store, 'dispatch') + + tick(320) + + expect(dispatchSpy).not.toHaveBeenCalled() + + discardPeriodicTasks() + })) + }) }) }) }) diff --git a/src/routerModule/router.service.ts b/src/routerModule/router.service.ts index ee0246f79..a17b554ad 100644 --- a/src/routerModule/router.service.ts +++ b/src/routerModule/router.service.ts @@ -7,7 +7,7 @@ import { debounceTime, distinctUntilChanged, filter, map, shareReplay, startWith import { generalApplyState } from "src/services/stateStore.helper"; import { PureContantService } from "src/util"; import { cvtStateToHashedRoutes, cvtFullRouteToState, encodeCustomState, decodeCustomState, verifyCustomState } from "./util"; -import { BehaviorSubject, combineLatest, merge, Observable } from 'rxjs' +import { BehaviorSubject, combineLatest, merge, Observable, of } from 'rxjs' import { scan } from 'rxjs/operators' @Injectable({ @@ -45,7 +45,7 @@ export class RouterService { // could be navigation (history api) // could be on init const navEnd$ = router.events.pipe( - filter(ev => ev instanceof NavigationEnd), + filter<NavigationEnd>(ev => ev instanceof NavigationEnd), shareReplay(1) ) @@ -94,10 +94,17 @@ export class RouterService { ready$.pipe( switchMapTo( navEnd$.pipe( - withLatestFrom(store$) + withLatestFrom( + store$, + this.customRoute$.pipe( + startWith({}) + ) + ) ) ) - ).subscribe(([ev, state]: [NavigationEnd, any]) => { + ).subscribe(arg => { + const [ev, state, customRoutes] = arg + const fullPath = ev.urlAfterRedirects const stateFromRoute = cvtFullRouteToState(router.parseUrl(fullPath), state, this.logError) let routeFromState: string @@ -107,6 +114,12 @@ export class RouterService { routeFromState = `` } + for (const key in customRoutes) { + const customStatePath = encodeCustomState(key, customRoutes[key]) + if (!customStatePath) continue + routeFromState += `/${customStatePath}` + } + if ( fullPath !== `/${routeFromState}`) { store$.dispatch( generalApplyState({ @@ -135,10 +148,10 @@ export class RouterService { ), this.customRoute$, ]).pipe( - map(([ routePath, customPath ]) => { + map(([ routePath, customRoutes ]) => { let returnPath = routePath - for (const key in customPath) { - const customStatePath = encodeCustomState(key, customPath[key]) + for (const key in customRoutes) { + const customStatePath = encodeCustomState(key, customRoutes[key]) if (!customStatePath) continue returnPath += `/${customStatePath}` } diff --git a/src/viewerModule/nehuba/viewerCtrl/viewerCtrlCmp/viewerCtrlCmp.component.ts b/src/viewerModule/nehuba/viewerCtrl/viewerCtrlCmp/viewerCtrlCmp.component.ts index dad948664..d46a84cfa 100644 --- a/src/viewerModule/nehuba/viewerCtrl/viewerCtrlCmp/viewerCtrlCmp.component.ts +++ b/src/viewerModule/nehuba/viewerCtrl/viewerCtrlCmp/viewerCtrlCmp.component.ts @@ -48,6 +48,7 @@ export class ViewerCtrlCmp{ return this._removeOctantFlag } set removeOctantFlag(val){ + if (val === this._removeOctantFlag) return this._removeOctantFlag = val this.setOctantRemoval(this._removeOctantFlag) } -- GitLab