Files
grafana/public/app/features/query/state/DashboardQueryRunner/AnnotationsQueryRunner.ts
Torkel Ödegaard c96c92d712 Angular: Isolate angular more (#41440)
* Getting close

* Restore angular app boot at startup

* Moving angular annotations dependencies to app/angular or old graph

* Remove redundant setLinkSrv call

* Fixing graph test

* Minor refactor based on review feedback

* Create in get function
2021-11-10 11:05:36 +01:00

34 lines
1.2 KiB
TypeScript

import { Observable, of } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { AnnotationEvent, DataSourceApi } from '@grafana/data';
import { AnnotationQueryRunner, AnnotationQueryRunnerOptions } from './types';
import { PanelModel } from '../../../dashboard/state';
import { executeAnnotationQuery } from '../../../annotations/executeAnnotationQuery';
import { handleAnnotationQueryRunnerError } from './utils';
export class AnnotationsQueryRunner implements AnnotationQueryRunner {
canRun(datasource?: DataSourceApi): boolean {
if (!datasource) {
return false;
}
return !Boolean(datasource.annotationQuery && !datasource.annotations);
}
run({ annotation, datasource, dashboard, range }: AnnotationQueryRunnerOptions): Observable<AnnotationEvent[]> {
if (!this.canRun(datasource)) {
return of([]);
}
const panel: PanelModel = ({} as unknown) as PanelModel; // deliberate setting panel to empty object because executeAnnotationQuery shouldn't depend on panelModel
return executeAnnotationQuery({ dashboard, range, panel }, datasource!, annotation).pipe(
map((result) => {
return result.events ?? [];
}),
catchError(handleAnnotationQueryRunnerError)
);
}
}