Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions projects/common/src/navigation/navigation.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ describe('Navigation Service', () => {
expect(router.navigate).toHaveBeenCalledWith(
['root', 'child'],
expect.objectContaining({
// tslint:disable-next-line: no-null-keyword
queryParams: { time: null },
relativeTo: undefined
})
);
Expand All @@ -155,8 +153,6 @@ describe('Navigation Service', () => {
expect(router.navigate).toHaveBeenLastCalledWith(
['child'],
expect.objectContaining({
// tslint:disable-next-line: no-null-keyword
queryParams: { time: null },
relativeTo: spectator.service.getCurrentActivatedRoute()
})
);
Expand Down Expand Up @@ -199,8 +195,6 @@ describe('Navigation Service', () => {
expect(spectator.service.buildNavigationParams('/services')).toEqual({
path: '/services',
extras: expect.objectContaining({
// tslint:disable-next-line: no-null-keyword
queryParams: { time: null },
relativeTo: undefined
})
});
Expand All @@ -220,4 +214,24 @@ describe('Navigation Service', () => {
})
);
});

test('propagates global query params', () => {
spectator.service.navigate({
navType: NavigationParamsType.InApp,
path: 'root',
queryParams: {
global: 'foo',
other: 'bar'
}
});

spectator.service.registerGlobalQueryParamKey('global');

spectator.service.navigate('root/child');

expect(spectator.service.getCurrentActivatedRoute().snapshot.url).toEqual([
expect.objectContaining({ path: 'child' })
]);
expect(spectator.service.getCurrentActivatedRoute().snapshot.queryParams).toEqual({ global: 'foo' });
});
});
10 changes: 9 additions & 1 deletion projects/common/src/navigation/navigation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class NavigationService {
);

private isFirstNavigation: boolean = true;
private readonly globalQueryParams: Set<string> = new Set();

public constructor(
private readonly router: Router,
Expand Down Expand Up @@ -57,6 +58,13 @@ export class NavigationService {
});
}

/**
* Global query params will be preserved by default on navigation
*/
public registerGlobalQueryParamKey(queryParamKey: string): void {
this.globalQueryParams.add(queryParamKey);
}

public getQueryParameter(parameterName: string, defaultValue: string): string {
return this.currentParamMap.has(parameterName) ? this.currentParamMap.get(parameterName)! : defaultValue;
}
Expand Down Expand Up @@ -116,7 +124,7 @@ export class NavigationService {
}

private buildQueryParam(preserveParameters: string[] = []): QueryParamObject {
return ['time', ...preserveParameters].reduce<Params>(
return [...this.globalQueryParams, ...preserveParameters].reduce<Params>(
(paramObj, param) => ({
...paramObj,
[param]: this.currentParamMap.get(param)
Expand Down
1 change: 1 addition & 0 deletions projects/common/src/time/time-range.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class TimeRangeService {
private readonly timeDurationService: TimeDurationService
) {
this.initializeTimeRange();
this.navigationService.registerGlobalQueryParamKey(TimeRangeService.TIME_RANGE_QUERY_PARAM);
}

public getShareableCurrentUrl(): string {
Expand Down