mirror of
https://github.com/grafana/grafana.git
synced 2025-02-12 00:25:46 -06:00
* Modify the annotation support api * Migrate annotation editor component * Update public/app/features/annotations/standardAnnotationSupport.ts Co-authored-by: Ryan McKinley <ryantxu@gmail.com> * Move the escape hatches out of the public API * Fix props transforms * Break import cycle Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
import { Observable, of } from 'rxjs';
|
|
import { catchError, map } from 'rxjs/operators';
|
|
|
|
import { AnnotationEvent, DataSourceApi } from '@grafana/data';
|
|
|
|
import { executeAnnotationQuery } from '../../../annotations/executeAnnotationQuery';
|
|
import { PanelModel } from '../../../dashboard/state';
|
|
|
|
import { AnnotationQueryRunner, AnnotationQueryRunnerOptions } from './types';
|
|
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)
|
|
);
|
|
}
|
|
}
|