@@ -11,7 +11,7 @@ import {
1111 VariableWithMultiSupport ,
1212} from '@grafana/data' ;
1313import { config , FetchResponse , getTemplateSrv , TemplateSrv } from '@grafana/runtime' ;
14- import { isArray , isObject } from 'lodash' ;
14+ import { isArray , isEmpty , isObject } from 'lodash' ;
1515import { lastValueFrom } from 'rxjs' ;
1616import { map } from 'rxjs/operators' ;
1717import { ResponseParser } from './response_parser' ;
@@ -62,7 +62,6 @@ export class DataSource extends DataSourceApi<GrafanaQuery, GenericOptions> {
6262 }
6363
6464 query ( options : QueryRequest ) : Promise < DataQueryResponse > {
65- options . scopedVars = { ...this . getVariables ( options . scopedVars ) , ...options . scopedVars } ;
6665 const mergedVars = { ...this . getVariables ( options . scopedVars ) , ...options . scopedVars } ;
6766 const nextOptions = { ...options , scopedVars : mergedVars } ;
6867
@@ -290,7 +289,7 @@ export class DataSource extends DataSourceApi<GrafanaQuery, GenericOptions> {
290289 }
291290
292291 getVariables ( scopedVars : ScopedVars | undefined = undefined ) {
293- const variableOptions : Record < VariableWithMultiSupport [ 'id' ] , VariableOption > = { } ;
292+ const variableOptions : Record < VariableWithMultiSupport [ 'id' ] , Omit < VariableOption , 'selected' > > = { } ;
294293
295294 Object . values ( getTemplateSrv ( ) . getVariables ( ) ) . forEach ( ( variable ) => {
296295 if ( variable . type === 'adhoc' ) {
@@ -302,10 +301,13 @@ export class DataSource extends DataSourceApi<GrafanaQuery, GenericOptions> {
302301 return ;
303302 }
304303
305- const value = getTemplateSrv ( ) . replace ( '$' + variable . name , scopedVars ) ;
304+ if ( isEmpty ( variable . current ) ) {
305+ return ;
306+ }
307+
308+ const value = getTemplateSrv ( ) . replace ( '$' + variable . name , scopedVars , 'json' ) ;
306309
307310 variableOptions [ variable . name ] = {
308- selected : false ,
309311 text : variable . current . text ,
310312 value : value ,
311313 } ;
0 commit comments