mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Variables: Add support for $__timezone template variable (#66785)
Co-authored-by: Isabel <76437239+imatwawana@users.noreply.github.com>
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { DataLinkBuiltInVars, ScopedVars, urlUtil } from '@grafana/data';
|
||||
import moment from 'moment-timezone';
|
||||
|
||||
import { DataLinkBuiltInVars, getTimeZone, ScopedVars, urlUtil } from '@grafana/data';
|
||||
|
||||
import { getTimeSrv } from '../dashboard/services/TimeSrv';
|
||||
import { getVariablesUrlParams } from '../variables/getAllVariableValuesForUrl';
|
||||
@@ -13,6 +15,7 @@ export const macroRegistry: Record<string, MacroHandler> = {
|
||||
['__field']: fieldMacro,
|
||||
[DataLinkBuiltInVars.includeVars]: includeVarsMacro,
|
||||
[DataLinkBuiltInVars.keepTime]: urlTimeRangeMacro,
|
||||
['__timezone']: timeZoneMacro,
|
||||
};
|
||||
|
||||
function includeVarsMacro(match: string, fieldPath?: string, scopedVars?: ScopedVars) {
|
||||
@@ -23,3 +26,8 @@ function includeVarsMacro(match: string, fieldPath?: string, scopedVars?: Scoped
|
||||
function urlTimeRangeMacro() {
|
||||
return urlUtil.toUrlParams(getTimeSrv().timeRangeForUrl());
|
||||
}
|
||||
|
||||
function timeZoneMacro() {
|
||||
const timeZone = getTimeZone({ timeZone: getTimeSrv().timeModel?.getTimezone() });
|
||||
return timeZone === 'browser' ? moment.tz.guess() : timeZone;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user