mirror of
https://github.com/grafana/grafana.git
synced 2025-02-12 00:25:46 -06:00
4124294011
* 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>
33 lines
1.0 KiB
TypeScript
33 lines
1.0 KiB
TypeScript
import { from, Observable, of } from 'rxjs';
|
|
import { catchError } from 'rxjs/operators';
|
|
|
|
import { AnnotationEvent, DataSourceApi } from '@grafana/data';
|
|
import { shouldUseLegacyRunner } from 'app/features/annotations/standardAnnotationSupport';
|
|
|
|
import { AnnotationQueryRunner, AnnotationQueryRunnerOptions } from './types';
|
|
import { handleAnnotationQueryRunnerError } from './utils';
|
|
|
|
export class LegacyAnnotationQueryRunner implements AnnotationQueryRunner {
|
|
canRun(datasource?: DataSourceApi): boolean {
|
|
if (!datasource) {
|
|
return false;
|
|
}
|
|
|
|
if (shouldUseLegacyRunner(datasource)) {
|
|
return true;
|
|
}
|
|
|
|
return Boolean(datasource.annotationQuery && !datasource.annotations);
|
|
}
|
|
|
|
run({ annotation, datasource, dashboard, range }: AnnotationQueryRunnerOptions): Observable<AnnotationEvent[]> {
|
|
if (!this.canRun(datasource)) {
|
|
return of([]);
|
|
}
|
|
|
|
return from(datasource!.annotationQuery!({ range, rangeRaw: range.raw, annotation, dashboard })).pipe(
|
|
catchError(handleAnnotationQueryRunnerError)
|
|
);
|
|
}
|
|
}
|