mergePanelAndDashData.ts 970 B

1234567891011121314151617181920212223242526272829
  1. import { combineLatest, Observable, of } from 'rxjs';
  2. import { mergeMap } from 'rxjs/operators';
  3. import { ArrayDataFrame, PanelData } from '@grafana/data';
  4. import { DashboardQueryRunnerResult } from './DashboardQueryRunner/types';
  5. export function mergePanelAndDashData(
  6. panelObservable: Observable<PanelData>,
  7. dashObservable: Observable<DashboardQueryRunnerResult>
  8. ): Observable<PanelData> {
  9. return combineLatest([panelObservable, dashObservable]).pipe(
  10. mergeMap((combined) => {
  11. const [panelData, dashData] = combined;
  12. if (Boolean(dashData.annotations?.length) || Boolean(dashData.alertState)) {
  13. if (!panelData.annotations) {
  14. panelData.annotations = [];
  15. }
  16. const annotations = panelData.annotations.concat(new ArrayDataFrame(dashData.annotations));
  17. const alertState = dashData.alertState;
  18. return of({ ...panelData, annotations, alertState });
  19. }
  20. return of(panelData);
  21. })
  22. );
  23. }