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' ;
33import { Dashboard , ModelJson } from '@hypertrace/hyperdash' ;
4+ import { TypedSimpleChanges } from '@hypertrace/hyperdash-angular/util/angular-change-object' ;
45import { Subject } from 'rxjs' ;
56import { takeUntil } from 'rxjs/operators' ;
67import { 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}
0 commit comments