Skip to content

Commit 0135c4d

Browse files
committed
Merge branch 'dashboard-misc-changes' of github.com:hypertrace/hypertrace-ui into dashboard-misc-changes
2 parents 6f779ec + c585721 commit 0135c4d

15 files changed

+248
-90
lines changed

package-lock.json

Lines changed: 83 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
"@types/d3-zoom": "^1.7.5",
9090
"@types/jest": "^26.0.23",
9191
"@types/lodash-es": "^4.17.4",
92-
"@types/node": "^14.14.41",
92+
"@types/node": "^15.12.5",
9393
"@types/uuid": "^8.3.0",
9494
"@types/webpack-env": "^1.14.0",
9595
"codelyzer": "^6.0.2",
@@ -106,7 +106,7 @@
106106
"ng-packagr": "^11.2.4",
107107
"prettier": "^2.2.1",
108108
"pretty-quick": "^3.0.0",
109-
"ts-node": "~9.1.1",
109+
"ts-node": "~10.0.0",
110110
"tslint": "~6.1.3",
111111
"tslint-config-prettier": "^1.18.0",
112112
"typescript": "~4.1.5",

projects/common/src/navigation/navigation.service.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import {
1414
UrlTree
1515
} from '@angular/router';
1616
import { from, Observable, of } from 'rxjs';
17-
import { distinctUntilChanged, filter, map, share, skip, startWith, take } from 'rxjs/operators';
18-
import { throwIfNil } from '../utilities/lang/lang-utils';
17+
import { distinctUntilChanged, filter, map, share, skip, startWith, switchMap, take } from 'rxjs/operators';
18+
import { isEqualIgnoreFunctions, throwIfNil } from '../utilities/lang/lang-utils';
1919
import { Dictionary } from '../utilities/types/types';
2020
import { TraceRoute } from './trace-route';
2121

@@ -124,6 +124,17 @@ export class NavigationService {
124124
};
125125
}
126126

127+
public buildNavigationParams$(
128+
paramsOrUrl: NavigationParams | string
129+
): Observable<{ path: NavigationPath; extras?: NavigationExtras }> {
130+
return this.navigation$.pipe(
131+
startWith(this.getCurrentActivatedRoute()),
132+
switchMap(route => route.queryParams),
133+
map(() => this.buildNavigationParams(paramsOrUrl)),
134+
distinctUntilChanged(isEqualIgnoreFunctions)
135+
);
136+
}
137+
127138
/**
128139
* Navigate within the app.
129140
* To be used for URLs with pattern '/partial_path' or 'partial_path'

projects/components/src/link/link.component.test.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ import { RouterLinkWithHref } from '@angular/router';
22
import { NavigationService } from '@hypertrace/common';
33
import { createHostFactory, mockProvider, SpectatorHost } from '@ngneat/spectator/jest';
44
import { MockDirective } from 'ng-mocks';
5+
import { of } from 'rxjs';
6+
import { LetAsyncModule } from '../let-async/let-async.module';
57
import { LinkComponent } from './link.component';
68

79
describe('Link component', () => {
810
let spectator: SpectatorHost<LinkComponent>;
911

1012
const createHost = createHostFactory({
1113
component: LinkComponent,
14+
imports: [LetAsyncModule],
1215
providers: [mockProvider(NavigationService)],
1316
declarations: [MockDirective(RouterLinkWithHref)]
1417
});
@@ -32,16 +35,18 @@ describe('Link component', () => {
3235
},
3336
providers: [
3437
mockProvider(NavigationService, {
35-
buildNavigationParams: jest.fn().mockReturnValue({
36-
path: [
37-
'/external',
38-
{
39-
url: 'http://test.hypertrace.ai',
40-
navType: 'same_window'
41-
}
42-
],
43-
extras: { skipLocationChange: true }
44-
})
38+
buildNavigationParams$: jest.fn().mockReturnValue(
39+
of({
40+
path: [
41+
'/external',
42+
{
43+
url: 'http://test.hypertrace.ai',
44+
navType: 'same_window'
45+
}
46+
],
47+
extras: { skipLocationChange: true }
48+
})
49+
)
4550
})
4651
]
4752
});
@@ -72,7 +77,7 @@ describe('Link component', () => {
7277
},
7378
providers: [
7479
mockProvider(NavigationService, {
75-
buildNavigationParams: jest.fn().mockReturnValue({ path: ['test'], extras: {} })
80+
buildNavigationParams$: jest.fn().mockReturnValue(of({ path: ['test'], extras: {} }))
7681
})
7782
]
7883
});
@@ -97,7 +102,7 @@ describe('Link component', () => {
97102
},
98103
providers: [
99104
mockProvider(NavigationService, {
100-
buildNavigationParams: jest.fn().mockReturnValue({ path: ['/test'], extras: {} })
105+
buildNavigationParams$: jest.fn().mockReturnValue(of({ path: ['/test'], extras: {} }))
101106
})
102107
]
103108
});
@@ -122,7 +127,7 @@ describe('Link component', () => {
122127
},
123128
providers: [
124129
mockProvider(NavigationService, {
125-
buildNavigationParams: jest.fn().mockReturnValue({ path: ['/test'], extras: {} })
130+
buildNavigationParams$: jest.fn().mockReturnValue(of({ path: ['/test'], extras: {} }))
126131
})
127132
]
128133
});

projects/components/src/link/link.component.ts

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,22 @@ import { ChangeDetectionStrategy, Component, Input, OnChanges } from '@angular/c
22
import { NavigationExtras } from '@angular/router';
33
import { NavigationParams, NavigationPath, NavigationService } from '@hypertrace/common';
44
import { isNil } from 'lodash-es';
5+
import { EMPTY, Observable } from 'rxjs';
56

67
@Component({
78
selector: 'ht-link',
89
styleUrls: ['./link.component.scss'],
910
changeDetection: ChangeDetectionStrategy.OnPush,
1011
template: `
1112
<a
13+
*htLetAsync="this.navData$ as navData"
1214
class="ht-link"
13-
[ngClass]="{ disabled: this.disabled || !this.navigationPath }"
14-
[routerLink]="this.navigationPath"
15-
[queryParams]="this.navigationOptions?.queryParams"
16-
[queryParamsHandling]="this.navigationOptions?.queryParamsHandling"
17-
[skipLocationChange]="this.navigationOptions?.skipLocationChange"
18-
[replaceUrl]="this.navigationOptions?.replaceUrl"
15+
[ngClass]="{ disabled: this.disabled || !navData }"
16+
[routerLink]="navData?.path"
17+
[queryParams]="navData?.extras?.queryParams"
18+
[queryParamsHandling]="navData?.extras?.queryParamsHandling"
19+
[skipLocationChange]="navData?.extras?.skipLocationChange"
20+
[replaceUrl]="navData?.extras?.replaceUrl"
1921
>
2022
<ng-content></ng-content>
2123
</a>
@@ -28,23 +30,16 @@ export class LinkComponent implements OnChanges {
2830
@Input()
2931
public disabled?: boolean;
3032

31-
public navigationPath?: NavigationPath;
32-
public navigationOptions?: NavigationExtras;
33+
public navData$: Observable<NavData> = EMPTY;
3334

3435
public constructor(private readonly navigationService: NavigationService) {}
3536

3637
public ngOnChanges(): void {
37-
this.setNavigationParams();
38+
this.navData$ = isNil(this.paramsOrUrl) ? EMPTY : this.navigationService.buildNavigationParams$(this.paramsOrUrl);
3839
}
40+
}
3941

40-
private setNavigationParams(): void {
41-
if (isNil(this.paramsOrUrl)) {
42-
this.navigationPath = undefined;
43-
this.navigationOptions = undefined;
44-
} else {
45-
const { path, extras } = this.navigationService.buildNavigationParams(this.paramsOrUrl);
46-
this.navigationPath = path;
47-
this.navigationOptions = extras;
48-
}
49-
}
42+
interface NavData {
43+
path: NavigationPath;
44+
extras?: NavigationExtras;
5045
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { CommonModule } from '@angular/common';
22
import { NgModule } from '@angular/core';
33
import { RouterModule } from '@angular/router';
4+
import { LetAsyncModule } from '../let-async/let-async.module';
45
import { LinkComponent } from './link.component';
56

67
@NgModule({
78
declarations: [LinkComponent],
89
exports: [LinkComponent],
9-
imports: [CommonModule, RouterModule]
10+
imports: [CommonModule, RouterModule, LetAsyncModule]
1011
})
1112
export class LinkModule {}

0 commit comments

Comments
 (0)