@@ -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' ;
3129import { VariableSupport } from './variable/VariableSupport' ;
3230import { doFetch } from './doFetch' ;
3331import { 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 ,
0 commit comments