mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Annotations: Fixes blank panels for queries with unknown data sources * Chore: fixes strict typescript error
27 lines
899 B
TypeScript
27 lines
899 B
TypeScript
import { from, Observable, of } from 'rxjs';
|
|
import { catchError } from 'rxjs/operators';
|
|
import { AnnotationEvent, DataSourceApi } from '@grafana/data';
|
|
|
|
import { AnnotationQueryRunner, AnnotationQueryRunnerOptions } from './types';
|
|
import { handleAnnotationQueryRunnerError } from './utils';
|
|
|
|
export class LegacyAnnotationQueryRunner 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([]);
|
|
}
|
|
|
|
return from(datasource!.annotationQuery!({ range, rangeRaw: range.raw, annotation, dashboard })).pipe(
|
|
catchError(handleAnnotationQueryRunnerError)
|
|
);
|
|
}
|
|
}
|