Skip to content

Commit

Permalink
support variable at query eidtor (#103)
Browse files Browse the repository at this point in the history
* Fix window or no zoneinfo.zip timezone problem

* Support variable
  • Loading branch information
lcc3108 authored Dec 1, 2023
1 parent 8a3c8f5 commit 9bccae2
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/DataSource.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -11,6 +11,28 @@ export class DataSource extends DataSourceWithBackend<GAQuery, GADataSourceOptio
this.version = instanceSettings.jsonData.version
}

applyTemplateVariables(query: GAQuery, scopedVars: ScopedVars): Record<string, any> {
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<CascaderOption[]> {
let accountSummaries = (await this.getResource('account-summaries')).accountSummaries as AccountSummary[]
let accounts: CascaderOption[] = [];
Expand Down

0 comments on commit 9bccae2

Please sign in to comment.