2021-07-02 03:52:13 -05:00
|
|
|
import { combineLatest, Observable, of } from 'rxjs';
|
2022-04-22 08:33:13 -05:00
|
|
|
import { mergeMap } from 'rxjs/operators';
|
|
|
|
|
2021-04-25 23:13:03 -05:00
|
|
|
import { ArrayDataFrame, PanelData } from '@grafana/data';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2021-04-25 23:13:03 -05:00
|
|
|
import { DashboardQueryRunnerResult } from './DashboardQueryRunner/types';
|
|
|
|
|
|
|
|
export function mergePanelAndDashData(
|
|
|
|
panelObservable: Observable<PanelData>,
|
|
|
|
dashObservable: Observable<DashboardQueryRunnerResult>
|
|
|
|
): Observable<PanelData> {
|
2021-07-02 03:52:13 -05:00
|
|
|
return combineLatest([panelObservable, dashObservable]).pipe(
|
2021-04-25 23:13:03 -05:00
|
|
|
mergeMap((combined) => {
|
|
|
|
const [panelData, dashData] = combined;
|
|
|
|
|
|
|
|
if (Boolean(dashData.annotations?.length) || Boolean(dashData.alertState)) {
|
|
|
|
if (!panelData.annotations) {
|
|
|
|
panelData.annotations = [];
|
|
|
|
}
|
|
|
|
|
2021-07-02 03:52:13 -05:00
|
|
|
const annotations = panelData.annotations.concat(new ArrayDataFrame(dashData.annotations));
|
|
|
|
const alertState = dashData.alertState;
|
|
|
|
return of({ ...panelData, annotations, alertState });
|
2021-04-25 23:13:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return of(panelData);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|