grafana/public/app/features/query/state/mergePanelAndDashData.ts
Josh Hunt 3c6e0e8ef8
Chore: ESlint import order (#44959)
* Add and configure eslint-plugin-import

* Fix the lint:ts npm command

* Autofix + prettier all the files

* Manually fix remaining files

* Move jquery code in jest-setup to external file to safely reorder imports

* Resolve issue caused by circular dependencies within Prometheus

* Update .betterer.results

* Fix missing // @ts-ignore

* ignore iconBundle.ts

* Fix missing // @ts-ignore
2022-04-22 14:33:13 +01:00

30 lines
970 B
TypeScript

import { combineLatest, Observable, of } from 'rxjs';
import { mergeMap } from 'rxjs/operators';
import { ArrayDataFrame, PanelData } from '@grafana/data';
import { DashboardQueryRunnerResult } from './DashboardQueryRunner/types';
export function mergePanelAndDashData(
panelObservable: Observable<PanelData>,
dashObservable: Observable<DashboardQueryRunnerResult>
): Observable<PanelData> {
return combineLatest([panelObservable, dashObservable]).pipe(
mergeMap((combined) => {
const [panelData, dashData] = combined;
if (Boolean(dashData.annotations?.length) || Boolean(dashData.alertState)) {
if (!panelData.annotations) {
panelData.annotations = [];
}
const annotations = panelData.annotations.concat(new ArrayDataFrame(dashData.annotations));
const alertState = dashData.alertState;
return of({ ...panelData, annotations, alertState });
}
return of(panelData);
})
);
}