mirror of
https://github.com/grafana/grafana.git
synced 2025-01-17 12:03:26 -06:00
Templating: Add default ref id for data source variable queries (#35923)
* add default ref id for ds variable queries * cleanup
This commit is contained in:
parent
c51af73bf6
commit
7ff26bdfae
@ -1,4 +1,4 @@
|
|||||||
import { QueryRunners } from './queryRunners';
|
import { QueryRunners, variableDummyRefId } from './queryRunners';
|
||||||
import { getDefaultTimeRange, VariableSupportType } from '@grafana/data';
|
import { getDefaultTimeRange, VariableSupportType } from '@grafana/data';
|
||||||
import { VariableRefresh } from '../types';
|
import { VariableRefresh } from '../types';
|
||||||
import { of } from 'rxjs';
|
import { of } from 'rxjs';
|
||||||
@ -293,6 +293,14 @@ describe('QueryRunners', () => {
|
|||||||
const target = runner.getTarget({ datasource, variable });
|
const target = runner.getTarget({ datasource, variable });
|
||||||
expect(target).toEqual({ refId: 'A', query: 'A query' });
|
expect(target).toEqual({ refId: 'A', query: 'A query' });
|
||||||
});
|
});
|
||||||
|
describe('and ref id is missing', () => {
|
||||||
|
it('then it should return correct target with dummy ref id', () => {
|
||||||
|
const { runner, datasource, variable } = getDatasourceTestContext();
|
||||||
|
delete variable.query.refId;
|
||||||
|
const target = runner.getTarget({ datasource, variable });
|
||||||
|
expect(target).toEqual({ refId: variableDummyRefId, query: 'A query' });
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('and calling runRequest', () => {
|
describe('and calling runRequest', () => {
|
||||||
|
@ -149,6 +149,8 @@ class CustomQueryRunner implements QueryRunner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const variableDummyRefId = 'variable-query';
|
||||||
|
|
||||||
class DatasourceQueryRunner implements QueryRunner {
|
class DatasourceQueryRunner implements QueryRunner {
|
||||||
type = VariableSupportType.Datasource;
|
type = VariableSupportType.Datasource;
|
||||||
|
|
||||||
@ -158,6 +160,9 @@ class DatasourceQueryRunner implements QueryRunner {
|
|||||||
|
|
||||||
getTarget({ datasource, variable }: GetTargetArgs) {
|
getTarget({ datasource, variable }: GetTargetArgs) {
|
||||||
if (hasDatasourceVariableSupport(datasource)) {
|
if (hasDatasourceVariableSupport(datasource)) {
|
||||||
|
if (!variable.query.refId) {
|
||||||
|
variable.query.refId = variableDummyRefId;
|
||||||
|
}
|
||||||
return variable.query;
|
return variable.query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user