mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
25 lines
844 B
TypeScript
25 lines
844 B
TypeScript
import { from, Observable } from 'rxjs';
|
|
import { map } from 'rxjs/operators';
|
|
|
|
import { DataQueryRequest, CustomVariableSupport, MetricFindValue } from '@grafana/data';
|
|
|
|
import { TempoVariableQuery, TempoVariableQueryEditor } from './VariableQueryEditor';
|
|
import { TempoDatasource } from './datasource';
|
|
|
|
export class TempoVariableSupport extends CustomVariableSupport<TempoDatasource, TempoVariableQuery> {
|
|
editor = TempoVariableQueryEditor;
|
|
|
|
constructor(private datasource: TempoDatasource) {
|
|
super();
|
|
}
|
|
|
|
query(request: DataQueryRequest<TempoVariableQuery>): Observable<{ data: MetricFindValue[] }> {
|
|
if (!this.datasource) {
|
|
throw new Error('Datasource not initialized');
|
|
}
|
|
|
|
const result = this.datasource.executeVariableQuery(request.targets[0]);
|
|
return from(result).pipe(map((data) => ({ data })));
|
|
}
|
|
}
|