Skip to content

Commit 693c4cf

Browse files
atarix83alisaismailati
authored andcommitted
[DSC-1917]Port of [CST-16492] Changed navigation through item tab in order to remove query params
1 parent 8253a7d commit 693c4cf

4 files changed

Lines changed: 12 additions & 21 deletions

File tree

src/app/app.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export class AppComponent implements OnInit, AfterViewInit {
134134
))
135135
).subscribe(([currentUrl, event]: [string, RouterEvent]) => {
136136
if (event instanceof NavigationStart) {
137-
if (!(currentUrl.startsWith(getEditItemPageRoute()) || currentUrl.startsWith(getWorkspaceItemModuleRoute()) || currentUrl.startsWith(getWorkflowItemModuleRoute()))) {
137+
if (!(currentUrl.startsWith('/entities' || getEditItemPageRoute()) || currentUrl.startsWith(getWorkspaceItemModuleRoute()) || currentUrl.startsWith(getWorkflowItemModuleRoute()))) {
138138
distinctNext(this.isRouteLoading$, true);
139139
}
140140
// distinctNext(this.isRouteLoading$, true);

src/app/core/services/route.service.spec.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { RouteService } from './route.service';
99
import { RouterMock } from '../../shared/mocks/router.mock';
1010
import { TestScheduler } from 'rxjs/testing';
1111
import { AddUrlToHistoryAction } from '../history/history.actions';
12-
import { NativeWindowRefMock} from '../../shared/mocks/mock-native-window-ref';
1312

1413
describe('RouteService', () => {
1514
let scheduler: TestScheduler;
@@ -49,19 +48,17 @@ describe('RouteService', () => {
4948
},
5049
{ provide: Router, useValue: router },
5150
{ provide: Store, useValue: store },
52-
{ provide: NativeWindowRefMock, useClass: NativeWindowRefMock }
5351
]
5452
});
5553
}));
5654

5755
beforeEach(() => {
58-
service = new RouteService(TestBed.inject(ActivatedRoute), TestBed.inject(Router), TestBed.inject(Store), TestBed.inject(NativeWindowRefMock));
56+
service = new RouteService(TestBed.inject(ActivatedRoute), TestBed.inject(Router), TestBed.inject(Store));
5957
serviceAsAny = service;
6058
});
6159

6260
describe('hasQueryParam', () => {
6361
it('should return true when the parameter name exists', () => {
64-
spyOnProperty(serviceAsAny._window.nativeWindow.location, 'href').and.returnValue('http://localhost?name=Test%20Name');
6562
service.hasQueryParam(paramName1).subscribe((status) => {
6663
expect(status).toBeTruthy();
6764
});
@@ -75,7 +72,6 @@ describe('RouteService', () => {
7572

7673
describe('hasQueryParamWithValue', () => {
7774
it('should return true when the parameter name exists and contains the specified value', () => {
78-
spyOnProperty(serviceAsAny._window.nativeWindow.location, 'href').and.returnValue('http://localhost?name=Test%20Name');
7975
service.hasQueryParamWithValue(paramName2, paramValue2a).subscribe((status) => {
8076
expect(status).toBeTruthy();
8177
});
@@ -94,7 +90,6 @@ describe('RouteService', () => {
9490

9591
describe('getQueryParameterValues', () => {
9692
it('should return a list of values when the parameter exists', () => {
97-
spyOnProperty(serviceAsAny._window.nativeWindow.location, 'href').and.returnValue('http://localhost?id=Test%20id&another=another%20id');
9893
service.getQueryParameterValues(paramName2).subscribe((params) => {
9994
expect(params).toEqual([paramValue2a, paramValue2b]);
10095
});
@@ -109,14 +104,12 @@ describe('RouteService', () => {
109104

110105
describe('getQueryParameterValue', () => {
111106
it('should return a single value when the parameter exists', () => {
112-
spyOnProperty(serviceAsAny._window.nativeWindow.location, 'href').and.returnValue('http://localhost?name=Test%20Name');
113107
service.getQueryParameterValue(paramName1).subscribe((params) => {
114108
expect(params).toEqual(paramValue1);
115109
});
116110
});
117111

118112
it('should return only the first value when the parameter exists', () => {
119-
spyOnProperty(serviceAsAny._window.nativeWindow.location, 'href').and.returnValue('http://localhost?id=Test%id');
120113
service.getQueryParameterValue(paramName2).subscribe((params) => {
121114
expect(params).toEqual(paramValue2a);
122115
});

src/app/core/services/route.service.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { distinctUntilChanged, filter, map, take } from 'rxjs/operators';
2-
import {Inject, Injectable} from '@angular/core';
3-
import {ActivatedRoute, NavigationEnd, ParamMap, Params, Router, RouterStateSnapshot,} from '@angular/router';
2+
import { Injectable } from '@angular/core';
3+
import { ActivatedRoute, NavigationEnd, Params, Router, RouterStateSnapshot, } from '@angular/router';
44

55
import { combineLatest, Observable } from 'rxjs';
66
import { createSelector, MemoizedSelector, select, Store } from '@ngrx/store';
@@ -12,7 +12,6 @@ import { hasValue } from '../../shared/empty.util';
1212
import { historySelector } from '../history/selectors';
1313
import { AddUrlToHistoryAction } from '../history/history.actions';
1414
import { CoreState } from '../core-state.model';
15-
import {NativeWindowRef, NativeWindowService} from './window.service';
1615

1716
/**
1817
* Selector to select all route parameters from the store
@@ -64,7 +63,7 @@ export function parameterSelector(key: string, paramsSelector: (state: CoreState
6463
providedIn: 'root'
6564
})
6665
export class RouteService {
67-
constructor(private route: ActivatedRoute, private router: Router, private store: Store<CoreState>, @Inject(NativeWindowService) private _window: NativeWindowRef) {
66+
constructor(private route: ActivatedRoute, private router: Router, private store: Store<CoreState>) {
6867
this.saveRouting();
6968
}
7069

@@ -142,14 +141,9 @@ export class RouteService {
142141

143142
public getQueryParamMap(): Observable<any> {
144143
return this.route.queryParamMap.pipe(
145-
map((paramMap: ParamMap) => {
144+
map((paramMap) => {
146145
const snapshot: RouterStateSnapshot = this.router.routerState.snapshot;
147146
// Due to an Angular bug, sometimes change of QueryParam is not detected so double checks with route snapshot
148-
if (!(this._window.nativeWindow.location.href || '').includes('?')){
149-
// Prevent sending outdated query params
150-
const emptyParamMap: ParamMap = { keys: [], has: (name: string) => false, get: (name: string) => null, getAll: (name: string) => [] };
151-
return emptyParamMap;
152-
}
153147
if (!isEqual(paramMap, snapshot.root.queryParamMap)) {
154148
return snapshot.root.queryParamMap;
155149
} else {

src/app/cris-layout/cris-layout-loader/shared/cris-layout-tabs/cris-layout-tabs.component.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,13 @@ export abstract class CrisLayoutTabsComponent {
112112
this.activeTab$.next(tab);
113113
this.emitSelected(tab);
114114
if (this.tabs[0].shortname === tab.shortname) {
115-
this.location.replaceState(itemPageRoute);
115+
this.router.navigate([], { queryParams: {}, replaceUrl: true, skipLocationChange: true }).then(() => {
116+
this.location.replaceState(itemPageRoute);
117+
});
116118
} else {
117-
this.location.replaceState(itemPageRoute + '/' + tab.shortname);
119+
this.router.navigate([], { queryParams: {}, replaceUrl: true, skipLocationChange: true }).then(() => {
120+
this.location.replaceState(itemPageRoute + '/' + tab.shortname);
121+
});
118122
}
119123
}
120124

0 commit comments

Comments
 (0)