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' ;
3
3
import { Dashboard , ModelJson } from '@hypertrace/hyperdash' ;
4
+ import { TypedSimpleChanges } from '@hypertrace/hyperdash-angular/util/angular-change-object' ;
4
5
import { Subject } from 'rxjs' ;
5
6
import { takeUntil } from 'rxjs/operators' ;
6
7
import { GraphQlFilterDataSourceModel } from '../data/graphql/filter/graphql-filter-data-source.model' ;
@@ -28,7 +29,7 @@ import { GraphQlFilterDataSourceModel } from '../data/graphql/filter/graphql-fil
28
29
</div>
29
30
`
30
31
} )
31
- export class ApplicationAwareDashboardComponent implements OnDestroy {
32
+ export class ApplicationAwareDashboardComponent implements OnDestroy , OnChanges {
32
33
@Input ( )
33
34
public json ?: ModelJson ;
34
35
@@ -38,6 +39,9 @@ export class ApplicationAwareDashboardComponent implements OnDestroy {
38
39
@Input ( )
39
40
public padding ?: number ;
40
41
42
+ @Input ( )
43
+ public variables ?: Dictionary < unknown > ;
44
+
41
45
@Output ( )
42
46
public readonly dashboardReady : EventEmitter < Dashboard > = new EventEmitter ( ) ;
43
47
@@ -50,11 +54,11 @@ export class ApplicationAwareDashboardComponent implements OnDestroy {
50
54
51
55
public constructor ( private readonly timeRangeService : TimeRangeService ) { }
52
56
53
- /* Dashboards */
54
57
public onDashboardReady ( dashboard : Dashboard ) : void {
55
58
this . destroyDashboard$ . next ( ) ;
56
59
57
60
dashboard . createAndSetRootDataFromModelClass ( GraphQlFilterDataSourceModel ) ;
61
+ this . applyVariablesToDashboard ( dashboard , this . variables ?? undefined ) ;
58
62
this . dashboard = dashboard ;
59
63
this . widgetSelection = dashboard . root ;
60
64
@@ -71,11 +75,24 @@ export class ApplicationAwareDashboardComponent implements OnDestroy {
71
75
this . destroyDashboard$ . complete ( ) ;
72
76
}
73
77
78
+ public ngOnChanges ( changes : TypedSimpleChanges < this> ) : void {
79
+ if ( changes . variables && this . dashboard ) {
80
+ this . applyVariablesToDashboard ( this . dashboard , this . variables ?? undefined ) ;
81
+ }
82
+ }
83
+
74
84
public onWidgetSelectionChange ( newSelection : object ) : void {
75
85
this . widgetSelection = newSelection ;
76
86
}
77
87
78
88
public onDashboardUpdated ( ) : void {
79
89
this . jsonChange . emit ( this . dashboard ! . serialize ( ) as ModelJson ) ;
80
90
}
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
+ }
81
98
}
0 commit comments