Skip to content

Commit fa25c51

Browse files
refactor: push variables down to app-aware-dash (#934)
1 parent 6a049e3 commit fa25c51

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

projects/distributed-tracing/src/shared/dashboard/dashboard-wrapper/application-aware-dashboard.component.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnDestroy, Output } from '@angular/core';
2-
import { TimeRangeService } from '@hypertrace/common';
1+
import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnChanges, OnDestroy, Output } from '@angular/core';
2+
import { Dictionary, TimeRangeService } from '@hypertrace/common';
33
import { Dashboard, ModelJson } from '@hypertrace/hyperdash';
4+
import { TypedSimpleChanges } from '@hypertrace/hyperdash-angular/util/angular-change-object';
45
import { Subject } from 'rxjs';
56
import { takeUntil } from 'rxjs/operators';
67
import { GraphQlFilterDataSourceModel } from '../data/graphql/filter/graphql-filter-data-source.model';
@@ -28,7 +29,7 @@ import { GraphQlFilterDataSourceModel } from '../data/graphql/filter/graphql-fil
2829
</div>
2930
`
3031
})
31-
export class ApplicationAwareDashboardComponent implements OnDestroy {
32+
export class ApplicationAwareDashboardComponent implements OnDestroy, OnChanges {
3233
@Input()
3334
public json?: ModelJson;
3435

@@ -38,6 +39,9 @@ export class ApplicationAwareDashboardComponent implements OnDestroy {
3839
@Input()
3940
public padding?: number;
4041

42+
@Input()
43+
public variables?: Dictionary<unknown>;
44+
4145
@Output()
4246
public readonly dashboardReady: EventEmitter<Dashboard> = new EventEmitter();
4347

@@ -50,11 +54,11 @@ export class ApplicationAwareDashboardComponent implements OnDestroy {
5054

5155
public constructor(private readonly timeRangeService: TimeRangeService) {}
5256

53-
/* Dashboards */
5457
public onDashboardReady(dashboard: Dashboard): void {
5558
this.destroyDashboard$.next();
5659

5760
dashboard.createAndSetRootDataFromModelClass(GraphQlFilterDataSourceModel);
61+
this.applyVariablesToDashboard(dashboard, this.variables ?? undefined);
5862
this.dashboard = dashboard;
5963
this.widgetSelection = dashboard.root;
6064

@@ -71,11 +75,24 @@ export class ApplicationAwareDashboardComponent implements OnDestroy {
7175
this.destroyDashboard$.complete();
7276
}
7377

78+
public ngOnChanges(changes: TypedSimpleChanges<this>): void {
79+
if (changes.variables && this.dashboard) {
80+
this.applyVariablesToDashboard(this.dashboard, this.variables ?? undefined);
81+
}
82+
}
83+
7484
public onWidgetSelectionChange(newSelection: object): void {
7585
this.widgetSelection = newSelection;
7686
}
7787

7888
public onDashboardUpdated(): void {
7989
this.jsonChange.emit(this.dashboard!.serialize() as ModelJson);
8090
}
91+
92+
private applyVariablesToDashboard(dashboard: Dashboard, variables: Dictionary<unknown> = {}): void {
93+
for (const key of Object.keys(variables)) {
94+
dashboard.setVariable(key, variables[key]);
95+
}
96+
dashboard.refresh();
97+
}
8198
}

projects/distributed-tracing/src/shared/dashboard/dashboard-wrapper/navigable-dashboard.component.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { GraphQlFilterDataSourceModel } from '../data/graphql/filter/graphql-fil
2929
class="dashboard"
3030
[json]="dashboardJson"
3131
[padding]="this.padding"
32+
[variables]="this.variables"
3233
(dashboardReady)="this.onDashboardReady($event)"
3334
>
3435
</ht-application-aware-dashboard>
@@ -94,7 +95,6 @@ export class NavigableDashboardComponent implements OnChanges {
9495

9596
public onDashboardReady(dashboard: Dashboard): void {
9697
this.dashboard = dashboard;
97-
this.applyVariablesToDashboard(this.dashboard, this.variables);
9898
this.applyFiltersToDashboard(dashboard, this.explicitFilters);
9999
this.dashboardReady.emit(dashboard);
100100
}
@@ -106,12 +106,6 @@ export class NavigableDashboardComponent implements OnChanges {
106106
}
107107
}
108108

109-
public applyVariablesToDashboard(dashboard: Dashboard, variables: Dictionary<unknown> = {}): void {
110-
for (const key of Object.keys(variables)) {
111-
dashboard.setVariable(key, variables[key]);
112-
}
113-
}
114-
115109
public applyFiltersToDashboard(dashboard: Dashboard, explicitFilters: Filter[]): void {
116110
const rootDataSource = dashboard.getRootDataSource<GraphQlFilterDataSourceModel>();
117111
rootDataSource

0 commit comments

Comments
 (0)