mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
DataSourceAPI: Add adhoc filters to DataQueryRequest and make it not depend on global templateSrv (#75552)
* DataSourceAPI: Add adhoc filters to DataQueryRequest and some methods to make it not depend on global templateSrv * Minor tweaks/fixes * Renamed to filters * Fix test * Log deprecation warning * I give up
This commit is contained in:
@@ -60,4 +60,8 @@ export class TemplateSrvMock implements TemplateSrv {
|
||||
}
|
||||
|
||||
updateTimeRange(timeRange: TimeRange) {}
|
||||
|
||||
getAdhocFilters(dsName: string) {
|
||||
return [{ key: 'key', operator: '=', value: 'a' }];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ export class TemplateSrv implements BaseTemplateSrv {
|
||||
private index: any = {};
|
||||
private grafanaVariables = new Map<string, any>();
|
||||
private timeRange?: TimeRange | null = null;
|
||||
private _adhocFiltersDeprecationWarningLogged = new Map<string, boolean>();
|
||||
|
||||
constructor(private dependencies: TemplateSrvDependencies = runtimeDependencies) {
|
||||
this._variables = [];
|
||||
@@ -111,6 +112,11 @@ export class TemplateSrv implements BaseTemplateSrv {
|
||||
this.index[variable.name] = variable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* Use filters property on the request (DataQueryRequest) or if this is called from
|
||||
* interpolateVariablesInQueries or applyTemplateVariables it is passed as a new argument
|
||||
**/
|
||||
getAdhocFilters(datasourceName: string): AdHocVariableFilter[] {
|
||||
let filters: any = [];
|
||||
let ds = getDataSourceSrv().getInstanceSettings(datasourceName);
|
||||
@@ -119,6 +125,17 @@ export class TemplateSrv implements BaseTemplateSrv {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (!this._adhocFiltersDeprecationWarningLogged.get(ds.type)) {
|
||||
if (process.env.NODE_ENV !== 'test') {
|
||||
deprecationWarning(
|
||||
`DataSource ${ds.type}`,
|
||||
'templateSrv.getAdhocFilters',
|
||||
'filters property on the request (DataQueryRequest). Or if this is called from interpolateVariablesInQueries or applyTemplateVariables it is passed as a new argument'
|
||||
);
|
||||
}
|
||||
this._adhocFiltersDeprecationWarningLogged.set(ds.type, true);
|
||||
}
|
||||
|
||||
for (const variable of this.getAdHocVariables()) {
|
||||
const variableUid = variable.datasource?.uid;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user