Skip to content
This repository was archived by the owner on Jan 1, 2026. It is now read-only.

Commit 5f59092

Browse files
committed
fix: interpret variables via templateSrv.replace
Index by name property. Grafana 12 does not have `variable.id` property (checked on b674c3157915f1bd16257b46889ae3a28bb790a5)
1 parent b8d8b91 commit 5f59092

2 files changed

Lines changed: 4 additions & 39 deletions

File tree

src/DataSource.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ import {
2626
QueryRequest,
2727
VariableQuery,
2828
} from './types';
29-
import { match, P } from 'ts-pattern';
30-
import { valueFromVariableWithMultiSupport } from './variable/valueFromVariableWithMultiSupport';
3129
import { VariableSupport } from './variable/VariableSupport';
3230
import { doFetch } from './doFetch';
3331
import { MetricFindQuery } from './MetricFindQuery';
@@ -70,7 +68,7 @@ export class DataSource extends DataSourceApi<GrafanaQuery, GenericOptions> {
7068
return Promise.resolve({ data: [] });
7169
}
7270

73-
options.scopedVars = { ...this.getVariables(), ...options.scopedVars };
71+
options.scopedVars = { ...this.getVariables(options.scopedVars), ...options.scopedVars };
7472

7573
return lastValueFrom(
7674
doFetch<any[]>(this, {
@@ -289,7 +287,7 @@ export class DataSource extends DataSourceApi<GrafanaQuery, GenericOptions> {
289287
return replacedMatch;
290288
}
291289

292-
getVariables() {
290+
getVariables(scopedVars: ScopedVars | undefined = undefined) {
293291
const variableOptions: Record<VariableWithMultiSupport['id'], VariableOption> = {};
294292

295293
Object.values(getTemplateSrv().getVariables()).forEach((variable) => {
@@ -302,19 +300,9 @@ export class DataSource extends DataSourceApi<GrafanaQuery, GenericOptions> {
302300
return;
303301
}
304302

305-
const value = match(variable)
306-
.with({ type: P.union('custom', 'query') }, (v) => valueFromVariableWithMultiSupport(v))
307-
.with(
308-
{ type: P.union('constant', 'datasource', 'groupby', 'interval', 'snapshot', 'textbox') },
309-
(v) => v.current.value
310-
)
311-
.exhaustive();
312-
313-
if (value === undefined) {
314-
return;
315-
}
303+
const value = getTemplateSrv().replace('$'+variable.name, scopedVars);
316304

317-
variableOptions[variable.id] = {
305+
variableOptions[variable.name] = {
318306
selected: false,
319307
text: variable.current.text,
320308
value: value,

src/variable/valueFromVariableWithMultiSupport.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)