mirror of
https://github.com/grafana/grafana.git
synced 2025-02-12 00:25:46 -06:00
* feat(loki-variable-query-support): refactor datasource to support legacy and new variable query format * Chore: fix comment * Chore: use internal method to interpolate strings * Chore: revert removed changes * Chore: update test
28 lines
893 B
TypeScript
28 lines
893 B
TypeScript
import { from, Observable } from 'rxjs';
|
|
import { map } from 'rxjs/operators';
|
|
|
|
import { CustomVariableSupport, DataQueryRequest, DataQueryResponse } from '@grafana/data';
|
|
|
|
import { LokiVariableQueryEditor } from './components/VariableQueryEditor';
|
|
import { LokiDatasource } from './datasource';
|
|
import { LokiVariableQuery } from './types';
|
|
|
|
export class LokiVariableSupport extends CustomVariableSupport<LokiDatasource, LokiVariableQuery> {
|
|
editor = LokiVariableQueryEditor;
|
|
|
|
constructor(private datasource: LokiDatasource) {
|
|
super();
|
|
this.query = this.query.bind(this);
|
|
}
|
|
|
|
async execute(query: LokiVariableQuery) {
|
|
return this.datasource.metricFindQuery(query);
|
|
}
|
|
|
|
query(request: DataQueryRequest<LokiVariableQuery>): Observable<DataQueryResponse> {
|
|
const result = this.execute(request.targets[0]);
|
|
|
|
return from(result).pipe(map((data) => ({ data })));
|
|
}
|
|
}
|