From 9bccae258ab4f0e01a33cf6e4acb4e0748dd1162 Mon Sep 17 00:00:00 2001 From: IM CHAECHEOL Date: Fri, 1 Dec 2023 21:01:54 +0900 Subject: [PATCH] support variable at query eidtor (#103) * Fix window or no zoneinfo.zip timezone problem * Support variable --- src/DataSource.ts | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/DataSource.ts b/src/DataSource.ts index 748bccc..480bcae 100644 --- a/src/DataSource.ts +++ b/src/DataSource.ts @@ -1,5 +1,5 @@ -import { DataSourceInstanceSettings, SelectableValue } from '@grafana/data'; -import { DataSourceWithBackend } from '@grafana/runtime'; +import { DataSourceInstanceSettings, ScopedVars, SelectableValue } from '@grafana/data'; +import { DataSourceWithBackend, getTemplateSrv } from '@grafana/runtime'; import { CascaderOption } from '@grafana/ui'; import { AccountSummary, GADataSourceOptions, GAMetadata, GAQuery } from './types'; @@ -11,6 +11,28 @@ export class DataSource extends DataSourceWithBackend { + const templateSrv = getTemplateSrv(); + let dimensionFilter = query.dimensionFilter + if (dimensionFilter.orGroup) { + dimensionFilter.orGroup.expressions.map(expression => { + if (expression.filter?.stringFilter) { + expression.filter.stringFilter.value = templateSrv.replace(expression.filter.stringFilter.value, scopedVars) + } + if (expression.filter?.inListFilter) { + expression.filter.inListFilter.values = expression.filter.inListFilter.values.map(value => { + value = templateSrv.replace(value, scopedVars) + return value + }) + } + return expression + }) + } + return { + ...query, + dimensionFilter + }; + } async getAccountSummaries(): Promise { let accountSummaries = (await this.getResource('account-summaries')).accountSummaries as AccountSummary[] let accounts: CascaderOption[] = [];