@grafana/scenes 5.21.0 → 5.21.1--canary.947.11593224430.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -168,10 +168,7 @@ class SceneTimeRange extends SceneObjectBase {
|
|
168
168
|
}
|
169
169
|
getUrlState() {
|
170
170
|
const params = locationService.getSearchObject();
|
171
|
-
const urlValues = { from: this.state.from, to: this.state.to };
|
172
|
-
if (this.state.timeZone) {
|
173
|
-
urlValues.timezone = this.state.timeZone;
|
174
|
-
}
|
171
|
+
const urlValues = { from: this.state.from, to: this.state.to, timezone: this.getTimeZone() };
|
175
172
|
if (params.time && params["time.window"]) {
|
176
173
|
urlValues.time = null;
|
177
174
|
urlValues["time.window"] = null;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"SceneTimeRange.js","sources":["../../../src/core/SceneTimeRange.tsx"],"sourcesContent":["import { getTimeZone, rangeUtil, TimeRange, toUtc } from '@grafana/data';\nimport { TimeZone } from '@grafana/schema';\n\nimport { SceneObjectUrlSyncConfig } from '../services/SceneObjectUrlSyncConfig';\n\nimport { SceneObjectBase } from './SceneObjectBase';\nimport { SceneTimeRangeLike, SceneTimeRangeState, SceneObjectUrlValues } from './types';\nimport { getClosest } from './sceneGraph/utils';\nimport { parseUrlParam } from '../utils/parseUrlParam';\nimport { evaluateTimeRange } from '../utils/evaluateTimeRange';\nimport { locationService, RefreshEvent } from '@grafana/runtime';\nimport { isValid } from '../utils/date';\n\nexport class SceneTimeRange extends SceneObjectBase<SceneTimeRangeState> implements SceneTimeRangeLike {\n protected _urlSync = new SceneObjectUrlSyncConfig(this, { keys: ['from', 'to', 'timezone', 'time', 'time.window'] });\n\n public constructor(state: Partial<SceneTimeRangeState> = {}) {\n const from = state.from && isValid(state.from) ? state.from : 'now-6h';\n const to = state.to && isValid(state.to) ? state.to : 'now';\n\n const timeZone = state.timeZone;\n const value = evaluateTimeRange(\n from,\n to,\n timeZone || getTimeZone(),\n state.fiscalYearStartMonth,\n state.UNSAFE_nowDelay\n );\n const refreshOnActivate = state.refreshOnActivate ?? { percent: 10 };\n super({ from, to, timeZone, value, refreshOnActivate, ...state });\n\n this.addActivationHandler(this._onActivate.bind(this));\n }\n\n private _onActivate() {\n // When SceneTimeRange has no time zone provided, find closest source of time zone and subscribe to it\n if (!this.state.timeZone) {\n const timeZoneSource = this.getTimeZoneSource();\n if (timeZoneSource !== this) {\n this._subs.add(\n timeZoneSource.subscribeToState((n, p) => {\n if (n.timeZone !== undefined && n.timeZone !== p.timeZone) {\n this.setState({\n value: evaluateTimeRange(\n this.state.from,\n this.state.to,\n timeZoneSource.getTimeZone(),\n this.state.fiscalYearStartMonth,\n this.state.UNSAFE_nowDelay\n ),\n });\n }\n })\n );\n }\n }\n\n if (rangeUtil.isRelativeTimeRange(this.state.value.raw)) {\n this.refreshIfStale();\n }\n }\n\n private refreshIfStale() {\n let ms;\n if (this.state?.refreshOnActivate?.percent !== undefined) {\n ms = this.calculatePercentOfInterval(this.state.refreshOnActivate.percent);\n }\n if (this.state?.refreshOnActivate?.afterMs !== undefined) {\n ms = Math.min(this.state.refreshOnActivate.afterMs, ms ?? Infinity);\n }\n if (ms !== undefined) {\n this.refreshRange(ms);\n }\n }\n\n /**\n * Will traverse up the scene graph to find the closest SceneTimeRangeLike with time zone set\n */\n private getTimeZoneSource() {\n if (!this.parent || !this.parent.parent) {\n return this;\n }\n // Find the closest source of time zone\n const source = getClosest<SceneTimeRangeLike>(this.parent.parent, (o) => {\n if (o.state.$timeRange && o.state.$timeRange.state.timeZone) {\n return o.state.$timeRange;\n }\n return undefined;\n });\n\n if (!source) {\n return this;\n }\n\n return source;\n }\n\n /**\n * Refreshes time range if it is older than the invalidation interval\n * @param refreshAfterMs invalidation interval (milliseconds)\n * @private\n */\n private refreshRange(refreshAfterMs: number) {\n const value = evaluateTimeRange(\n this.state.from,\n this.state.to,\n this.state.timeZone ?? getTimeZone(),\n this.state.fiscalYearStartMonth,\n this.state.UNSAFE_nowDelay\n );\n\n const diff = value.to.diff(this.state.value.to, 'milliseconds');\n if (diff >= refreshAfterMs) {\n this.setState({\n value,\n });\n }\n }\n\n private calculatePercentOfInterval(percent: number): number {\n const intervalMs = this.state.value.to.diff(this.state.value.from, 'milliseconds');\n return Math.ceil(intervalMs / percent);\n }\n\n public getTimeZone(): TimeZone {\n // Return local time zone if provided\n if (this.state.timeZone) {\n return this.state.timeZone;\n }\n\n // Resolve higher level time zone source\n const timeZoneSource = this.getTimeZoneSource();\n if (timeZoneSource !== this) {\n return timeZoneSource.state.timeZone!;\n }\n\n // Return default time zone\n return getTimeZone();\n }\n\n public onTimeRangeChange = (timeRange: TimeRange) => {\n const update: Partial<SceneTimeRangeState> = {};\n\n if (typeof timeRange.raw.from === 'string') {\n update.from = timeRange.raw.from;\n } else {\n update.from = timeRange.raw.from.toISOString();\n }\n\n if (typeof timeRange.raw.to === 'string') {\n update.to = timeRange.raw.to;\n } else {\n update.to = timeRange.raw.to.toISOString();\n }\n\n update.value = evaluateTimeRange(\n update.from,\n update.to,\n this.getTimeZone(),\n this.state.fiscalYearStartMonth,\n this.state.UNSAFE_nowDelay\n );\n\n // Only update if time range actually changed\n if (update.from !== this.state.from || update.to !== this.state.to) {\n this._urlSync.performBrowserHistoryAction(() => {\n this.setState(update);\n });\n }\n };\n\n public onTimeZoneChange = (timeZone: TimeZone) => {\n this._urlSync.performBrowserHistoryAction(() => {\n this.setState({ timeZone });\n });\n };\n\n public onRefresh = () => {\n this.setState({\n value: evaluateTimeRange(\n this.state.from,\n this.state.to,\n this.getTimeZone(),\n this.state.fiscalYearStartMonth,\n this.state.UNSAFE_nowDelay\n ),\n });\n\n this.publishEvent(new RefreshEvent(), true);\n };\n\n public getUrlState() {\n const params = locationService.getSearchObject();\n const urlValues: SceneObjectUrlValues = { from: this.state.from, to: this.state.to };\n\n if (this.state.timeZone) {\n urlValues.timezone = this.state.timeZone;\n }\n\n // Clear time and time.window once they are converted to from and to\n if (params.time && params['time.window']) {\n urlValues.time = null;\n urlValues['time.window'] = null;\n }\n\n return urlValues;\n }\n\n public updateFromUrl(values: SceneObjectUrlValues) {\n const update: Partial<SceneTimeRangeState> = {};\n\n let from = parseUrlParam(values.from);\n let to = parseUrlParam(values.to);\n\n if (values.time && values['time.window']) {\n const time = Array.isArray(values.time) ? values.time[0] : values.time;\n const timeWindow = Array.isArray(values['time.window']) ? values['time.window'][0] : values['time.window'];\n const timeRange = getTimeWindow(time, timeWindow);\n if (timeRange.from && isValid(timeRange.from)) {\n from = timeRange.from;\n }\n\n if (timeRange.to && isValid(timeRange.to)) {\n to = timeRange.to;\n }\n }\n\n if (from && isValid(from)) {\n update.from = from;\n }\n\n if (to && isValid(to)) {\n update.to = to;\n }\n\n if (typeof values.timezone === 'string') {\n update.timeZone = values.timezone !== '' ? values.timezone : undefined;\n }\n\n if (Object.keys(update).length === 0) {\n return;\n }\n\n update.value = evaluateTimeRange(\n update.from ?? this.state.from,\n update.to ?? this.state.to,\n update.timeZone ?? this.getTimeZone(),\n this.state.fiscalYearStartMonth,\n this.state.UNSAFE_nowDelay\n );\n\n return this.setState(update);\n }\n}\n\n/**\n * Calculates the duration of the time range from time-time.window/2 to time+time.window/2. Both be specified in ms. For example ?time=1500000000000&time.window=10000 results in a 10-second time range from 1499999995000 to 1500000005000`.\n * @param time - time in ms\n * @param timeWindow - time window in ms or interval string\n */\nfunction getTimeWindow(time: string, timeWindow: string) {\n // Parse the time, assuming it could be an ISO string or a number in milliseconds\n const valueTime = isNaN(Date.parse(time)) ? parseInt(time, 10) : Date.parse(time);\n\n let timeWindowMs;\n\n if (timeWindow.match(/^\\d+$/) && parseInt(timeWindow, 10)) {\n // when time window is specified in ms\n timeWindowMs = parseInt(timeWindow, 10);\n } else {\n timeWindowMs = rangeUtil.intervalToMs(timeWindow);\n }\n\n return {\n from: toUtc(valueTime - timeWindowMs / 2).toISOString(),\n to: toUtc(valueTime + timeWindowMs / 2).toISOString(),\n };\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAaO,MAAM,uBAAuB,eAAm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;AAAA,MAAA,CAC1B,EAAO,GAAA,MAAA,CAAA,EAAA,KAAP,IAAa,GAAA,EAAA,GAAA,IAAA,CAAK,KAAM,CAAA,EAAA;AAAA,MAAA,CACxB,EAAO,GAAA,MAAA,CAAA,QAAA,KAAP,IAAmB,GAAA,EAAA,GAAA,IAAA,CAAK,WAAY,EAAA;AAAA,MACpC,KAAK,KAAM,CAAA,oBAAA;AAAA,MACX,KAAK,KAAM,CAAA,eAAA;AAAA,KACb,CAAA;AAEA,IAAO,OAAA,IAAA,CAAK,SAAS,MAAM,CAAA,CAAA;AAAA,GAC7B;AACF,CAAA;AAOA,SAAS,aAAA,CAAc,MAAc,UAAoB,EAAA;AAEvD,EAAA,MAAM,SAAY,GAAA,KAAA,CAAM,IAAK,CAAA,KAAA,CAAM,IAAI,CAAC,CAAI,GAAA,QAAA,CAAS,IAAM,EAAA,EAAE,CAAI,GAAA,IAAA,CAAK,MAAM,IAAI,CAAA,CAAA;AAEhF,EAAI,IAAA,YAAA,CAAA;AAEJ,EAAA,IAAI,WAAW,KAAM,CAAA,OAAO,KAAK,QAAS,CAAA,UAAA,EAAY,EAAE,CAAG,EAAA;AAEzD,IAAe,YAAA,GAAA,QAAA,CAAS,YAAY,EAAE,CAAA,CAAA;AAAA,GACjC,MAAA;AACL,IAAe,YAAA,GAAA,SAAA,CAAU,aAAa,UAAU,CAAA,CAAA;AAAA,GAClD;AAEA,EAAO,OAAA;AAAA,IACL,MAAM,KAAM,CAAA,SAAA,GAAY,YAAe,GAAA,CAAC,EAAE,WAAY,EAAA;AAAA,IACtD,IAAI,KAAM,CAAA,SAAA,GAAY,YAAe,GAAA,CAAC,EAAE,WAAY,EAAA;AAAA,GACtD,CAAA;AACF;;;;"}
|
1
|
+
{"version":3,"file":"SceneTimeRange.js","sources":["../../../src/core/SceneTimeRange.tsx"],"sourcesContent":["import { getTimeZone, rangeUtil, TimeRange, toUtc } from '@grafana/data';\nimport { TimeZone } from '@grafana/schema';\n\nimport { SceneObjectUrlSyncConfig } from '../services/SceneObjectUrlSyncConfig';\n\nimport { SceneObjectBase } from './SceneObjectBase';\nimport { SceneTimeRangeLike, SceneTimeRangeState, SceneObjectUrlValues } from './types';\nimport { getClosest } from './sceneGraph/utils';\nimport { parseUrlParam } from '../utils/parseUrlParam';\nimport { evaluateTimeRange } from '../utils/evaluateTimeRange';\nimport { locationService, RefreshEvent } from '@grafana/runtime';\nimport { isValid } from '../utils/date';\n\nexport class SceneTimeRange extends SceneObjectBase<SceneTimeRangeState> implements SceneTimeRangeLike {\n protected _urlSync = new SceneObjectUrlSyncConfig(this, { keys: ['from', 'to', 'timezone', 'time', 'time.window'] });\n\n public constructor(state: Partial<SceneTimeRangeState> = {}) {\n const from = state.from && isValid(state.from) ? state.from : 'now-6h';\n const to = state.to && isValid(state.to) ? state.to : 'now';\n\n const timeZone = state.timeZone;\n const value = evaluateTimeRange(\n from,\n to,\n timeZone || getTimeZone(),\n state.fiscalYearStartMonth,\n state.UNSAFE_nowDelay\n );\n const refreshOnActivate = state.refreshOnActivate ?? { percent: 10 };\n super({ from, to, timeZone, value, refreshOnActivate, ...state });\n\n this.addActivationHandler(this._onActivate.bind(this));\n }\n\n private _onActivate() {\n // When SceneTimeRange has no time zone provided, find closest source of time zone and subscribe to it\n if (!this.state.timeZone) {\n const timeZoneSource = this.getTimeZoneSource();\n if (timeZoneSource !== this) {\n this._subs.add(\n timeZoneSource.subscribeToState((n, p) => {\n if (n.timeZone !== undefined && n.timeZone !== p.timeZone) {\n this.setState({\n value: evaluateTimeRange(\n this.state.from,\n this.state.to,\n timeZoneSource.getTimeZone(),\n this.state.fiscalYearStartMonth,\n this.state.UNSAFE_nowDelay\n ),\n });\n }\n })\n );\n }\n }\n\n if (rangeUtil.isRelativeTimeRange(this.state.value.raw)) {\n this.refreshIfStale();\n }\n }\n\n private refreshIfStale() {\n let ms;\n if (this.state?.refreshOnActivate?.percent !== undefined) {\n ms = this.calculatePercentOfInterval(this.state.refreshOnActivate.percent);\n }\n if (this.state?.refreshOnActivate?.afterMs !== undefined) {\n ms = Math.min(this.state.refreshOnActivate.afterMs, ms ?? Infinity);\n }\n if (ms !== undefined) {\n this.refreshRange(ms);\n }\n }\n\n /**\n * Will traverse up the scene graph to find the closest SceneTimeRangeLike with time zone set\n */\n private getTimeZoneSource() {\n if (!this.parent || !this.parent.parent) {\n return this;\n }\n // Find the closest source of time zone\n const source = getClosest<SceneTimeRangeLike>(this.parent.parent, (o) => {\n if (o.state.$timeRange && o.state.$timeRange.state.timeZone) {\n return o.state.$timeRange;\n }\n return undefined;\n });\n\n if (!source) {\n return this;\n }\n\n return source;\n }\n\n /**\n * Refreshes time range if it is older than the invalidation interval\n * @param refreshAfterMs invalidation interval (milliseconds)\n * @private\n */\n private refreshRange(refreshAfterMs: number) {\n const value = evaluateTimeRange(\n this.state.from,\n this.state.to,\n this.state.timeZone ?? getTimeZone(),\n this.state.fiscalYearStartMonth,\n this.state.UNSAFE_nowDelay\n );\n\n const diff = value.to.diff(this.state.value.to, 'milliseconds');\n if (diff >= refreshAfterMs) {\n this.setState({\n value,\n });\n }\n }\n\n private calculatePercentOfInterval(percent: number): number {\n const intervalMs = this.state.value.to.diff(this.state.value.from, 'milliseconds');\n return Math.ceil(intervalMs / percent);\n }\n\n public getTimeZone(): TimeZone {\n // Return local time zone if provided\n if (this.state.timeZone) {\n return this.state.timeZone;\n }\n\n // Resolve higher level time zone source\n const timeZoneSource = this.getTimeZoneSource();\n if (timeZoneSource !== this) {\n return timeZoneSource.state.timeZone!;\n }\n\n // Return default time zone\n return getTimeZone();\n }\n\n public onTimeRangeChange = (timeRange: TimeRange) => {\n const update: Partial<SceneTimeRangeState> = {};\n\n if (typeof timeRange.raw.from === 'string') {\n update.from = timeRange.raw.from;\n } else {\n update.from = timeRange.raw.from.toISOString();\n }\n\n if (typeof timeRange.raw.to === 'string') {\n update.to = timeRange.raw.to;\n } else {\n update.to = timeRange.raw.to.toISOString();\n }\n\n update.value = evaluateTimeRange(\n update.from,\n update.to,\n this.getTimeZone(),\n this.state.fiscalYearStartMonth,\n this.state.UNSAFE_nowDelay\n );\n\n // Only update if time range actually changed\n if (update.from !== this.state.from || update.to !== this.state.to) {\n this._urlSync.performBrowserHistoryAction(() => {\n this.setState(update);\n });\n }\n };\n\n public onTimeZoneChange = (timeZone: TimeZone) => {\n this._urlSync.performBrowserHistoryAction(() => {\n this.setState({ timeZone });\n });\n };\n\n public onRefresh = () => {\n this.setState({\n value: evaluateTimeRange(\n this.state.from,\n this.state.to,\n this.getTimeZone(),\n this.state.fiscalYearStartMonth,\n this.state.UNSAFE_nowDelay\n ),\n });\n\n this.publishEvent(new RefreshEvent(), true);\n };\n\n public getUrlState() {\n const params = locationService.getSearchObject();\n const urlValues: SceneObjectUrlValues = { from: this.state.from, to: this.state.to, timezone: this.getTimeZone() };\n\n // Clear time and time.window once they are converted to from and to\n if (params.time && params['time.window']) {\n urlValues.time = null;\n urlValues['time.window'] = null;\n }\n\n return urlValues;\n }\n\n public updateFromUrl(values: SceneObjectUrlValues) {\n const update: Partial<SceneTimeRangeState> = {};\n\n let from = parseUrlParam(values.from);\n let to = parseUrlParam(values.to);\n\n if (values.time && values['time.window']) {\n const time = Array.isArray(values.time) ? values.time[0] : values.time;\n const timeWindow = Array.isArray(values['time.window']) ? values['time.window'][0] : values['time.window'];\n const timeRange = getTimeWindow(time, timeWindow);\n if (timeRange.from && isValid(timeRange.from)) {\n from = timeRange.from;\n }\n\n if (timeRange.to && isValid(timeRange.to)) {\n to = timeRange.to;\n }\n }\n\n if (from && isValid(from)) {\n update.from = from;\n }\n\n if (to && isValid(to)) {\n update.to = to;\n }\n\n if (typeof values.timezone === 'string') {\n update.timeZone = values.timezone !== '' ? values.timezone : undefined;\n }\n\n if (Object.keys(update).length === 0) {\n return;\n }\n\n update.value = evaluateTimeRange(\n update.from ?? this.state.from,\n update.to ?? this.state.to,\n update.timeZone ?? this.getTimeZone(),\n this.state.fiscalYearStartMonth,\n this.state.UNSAFE_nowDelay\n );\n\n return this.setState(update);\n }\n}\n\n/**\n * Calculates the duration of the time range from time-time.window/2 to time+time.window/2. Both be specified in ms. For example ?time=1500000000000&time.window=10000 results in a 10-second time range from 1499999995000 to 1500000005000`.\n * @param time - time in ms\n * @param timeWindow - time window in ms or interval string\n */\nfunction getTimeWindow(time: string, timeWindow: string) {\n // Parse the time, assuming it could be an ISO string or a number in milliseconds\n const valueTime = isNaN(Date.parse(time)) ? parseInt(time, 10) : Date.parse(time);\n\n let timeWindowMs;\n\n if (timeWindow.match(/^\\d+$/) && parseInt(timeWindow, 10)) {\n // when time window is specified in ms\n timeWindowMs = parseInt(timeWindow, 10);\n } else {\n timeWindowMs = rangeUtil.intervalToMs(timeWindow);\n }\n\n return {\n from: toUtc(valueTime - timeWindowMs / 2).toISOString(),\n to: toUtc(valueTime + timeWindowMs / 2).toISOString(),\n };\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAaO,MAAM,uBAAuB,eAAmE,CAAA;AAAA,EAG9F,WAAA,CAAY,KAAsC,GAAA,EAAI,EAAA;AAhB/D,IAAA,IAAA,EAAA,CAAA;AAiBI,IAAM,MAAA,IAAA,GAAO,MAAM,IAAQ,IAAA,OAAA,CAAQ,MAAM,IAAI,CAAA,GAAI,MAAM,IAAO,GAAA,QAAA,CAAA;AAC9D,IAAM,MAAA,EAAA,GAAK,MAAM,EAAM,IAAA,OAAA,CAAQ,MAAM,EAAE,CAAA,GAAI,MAAM,EAAK,GAAA,KAAA,CAAA;AAEtD,IAAA,MAAM,WAAW,KAAM,CAAA,QAAA,CAAA;AACvB,IAAA,MAAM,KAAQ,GAAA,iBAAA;AAAA,MACZ,IAAA;AAAA,MACA,EAAA;AAAA,MACA,YAAY,WAAY,EAAA;AAAA,MACxB,KAAM,CAAA,oBAAA;AAAA,MACN,KAAM,CAAA,eAAA;AAAA,KACR,CAAA;AACA,IAAA,MAAM,qBAAoB,EAAM,GAAA,KAAA,CAAA,iBAAA,KAAN,IAA2B,GA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EAAA;AAEzD,IAAe,YAAA,GAAA,QAAA,CAAS,YAAY,EAAE,CAAA,CAAA;AAAA,GACjC,MAAA;AACL,IAAe,YAAA,GAAA,SAAA,CAAU,aAAa,UAAU,CAAA,CAAA;AAAA,GAClD;AAEA,EAAO,OAAA;AAAA,IACL,MAAM,KAAM,CAAA,SAAA,GAAY,YAAe,GAAA,CAAC,EAAE,WAAY,EAAA;AAAA,IACtD,IAAI,KAAM,CAAA,SAAA,GAAY,YAAe,GAAA,CAAC,EAAE,WAAY,EAAA;AAAA,GACtD,CAAA;AACF;;;;"}
|
@@ -12,6 +12,9 @@ class UrlTimeRangeMacro {
|
|
12
12
|
var _a;
|
13
13
|
const timeRange = getTimeRange(this._sceneObject);
|
14
14
|
const urlState = (_a = timeRange.urlSync) == null ? void 0 : _a.getUrlState();
|
15
|
+
if ((urlState == null ? void 0 : urlState.timezone) === "browser") {
|
16
|
+
urlState.timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
17
|
+
}
|
15
18
|
return new SkipFormattingValue(urlUtil.toUrlParams(urlState));
|
16
19
|
}
|
17
20
|
getValueText() {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"timeMacros.js","sources":["../../../../src/variables/macros/timeMacros.ts"],"sourcesContent":["import { dateTimeFormat, urlUtil } from '@grafana/data';\nimport { getTimeRange } from '../../core/sceneGraph/getTimeRange';\nimport { getData } from '../../core/sceneGraph/sceneGraph';\nimport { SceneObject } from '../../core/types';\nimport { FormatVariable } from '../interpolation/formatRegistry';\nimport { SkipFormattingValue } from './types';\n\n/**\n * Handles expressions like $__url_time_range.\n */\nexport class UrlTimeRangeMacro implements FormatVariable {\n public state: { name: string; type: string };\n private _sceneObject: SceneObject;\n\n public constructor(name: string, sceneObject: SceneObject) {\n this.state = { name: name, type: 'url_variable' };\n this._sceneObject = sceneObject;\n }\n\n public getValue(): SkipFormattingValue {\n const timeRange = getTimeRange(this._sceneObject);\n const urlState = timeRange.urlSync?.getUrlState();\n return new SkipFormattingValue(urlUtil.toUrlParams(urlState));\n }\n\n public getValueText?(): string {\n return '';\n }\n}\n\n/**\n * Handles expressions like $__from and $__to.\n */\nexport class TimeFromAndToMacro implements FormatVariable {\n public state: { name: string; type: string };\n private _sceneObject: SceneObject;\n\n public constructor(name: string, sceneObject: SceneObject) {\n this.state = { name: name, type: 'time_macro' };\n this._sceneObject = sceneObject;\n }\n\n public getValue() {\n const timeRange = getTimeRange(this._sceneObject);\n if (this.state.name === '__from') {\n return timeRange.state.value.from.valueOf();\n } else {\n return timeRange.state.value.to.valueOf();\n }\n }\n\n public getValueText?(): string {\n const timeRange = getTimeRange(this._sceneObject);\n if (this.state.name === '__from') {\n return dateTimeFormat(timeRange.state.value.from, { timeZone: timeRange.getTimeZone() });\n } else {\n return dateTimeFormat(timeRange.state.value.to, { timeZone: timeRange.getTimeZone() });\n }\n }\n}\n\n/**\n * Handles $__timezone expression.\n */\nexport class TimezoneMacro implements FormatVariable {\n public state: { name: string; type: string };\n private _sceneObject: SceneObject;\n\n public constructor(name: string, sceneObject: SceneObject) {\n this.state = { name: name, type: 'time_macro' };\n this._sceneObject = sceneObject;\n }\n\n public getValue() {\n const timeRange = getTimeRange(this._sceneObject);\n const timeZone = timeRange.getTimeZone();\n\n if (timeZone === 'browser') {\n return Intl.DateTimeFormat().resolvedOptions().timeZone;\n }\n\n return timeZone;\n }\n\n public getValueText?(): string {\n return this.getValue();\n }\n}\n\n/**\n * Handles $__interval and $__intervalMs expression.\n */\nexport class IntervalMacro implements FormatVariable {\n public state: { name: string; type: string; match: string };\n private _sceneObject: SceneObject;\n\n public constructor(name: string, sceneObject: SceneObject, match: string) {\n this.state = { name: name, type: 'time_macro', match: match };\n this._sceneObject = sceneObject;\n }\n\n public getValue() {\n const data = getData(this._sceneObject);\n\n if (data) {\n const request = data.state.data?.request;\n if (!request) {\n return this.state.match;\n }\n if (this.state.name === '__interval_ms') {\n return request.intervalMs;\n }\n return request.interval;\n }\n\n return this.state.match;\n }\n}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AA,EAA0B,KAAe,EAAA;AACxE,IAAA,IAAA,CAAK,KAAQ,GAAA,EAAE,IAAY,EAAA,IAAA,EAAM,cAAc,KAAa,EAAA,CAAA;AAC5D,IAAA,IAAA,CAAK,YAAe,GAAA,WAAA,CAAA;AAAA,GACtB;AAAA,EAEO,QAAW,GAAA;
|
1
|
+
{"version":3,"file":"timeMacros.js","sources":["../../../../src/variables/macros/timeMacros.ts"],"sourcesContent":["import { dateTimeFormat, urlUtil } from '@grafana/data';\nimport { getTimeRange } from '../../core/sceneGraph/getTimeRange';\nimport { getData } from '../../core/sceneGraph/sceneGraph';\nimport { SceneObject } from '../../core/types';\nimport { FormatVariable } from '../interpolation/formatRegistry';\nimport { SkipFormattingValue } from './types';\n\n/**\n * Handles expressions like $__url_time_range.\n */\nexport class UrlTimeRangeMacro implements FormatVariable {\n public state: { name: string; type: string };\n private _sceneObject: SceneObject;\n\n public constructor(name: string, sceneObject: SceneObject) {\n this.state = { name: name, type: 'url_variable' };\n this._sceneObject = sceneObject;\n }\n\n public getValue(): SkipFormattingValue {\n const timeRange = getTimeRange(this._sceneObject);\n const urlState = timeRange.urlSync?.getUrlState();\n if (urlState?.timezone === 'browser') {\n urlState.timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;\n }\n return new SkipFormattingValue(urlUtil.toUrlParams(urlState));\n }\n\n public getValueText?(): string {\n return '';\n }\n}\n\n/**\n * Handles expressions like $__from and $__to.\n */\nexport class TimeFromAndToMacro implements FormatVariable {\n public state: { name: string; type: string };\n private _sceneObject: SceneObject;\n\n public constructor(name: string, sceneObject: SceneObject) {\n this.state = { name: name, type: 'time_macro' };\n this._sceneObject = sceneObject;\n }\n\n public getValue() {\n const timeRange = getTimeRange(this._sceneObject);\n if (this.state.name === '__from') {\n return timeRange.state.value.from.valueOf();\n } else {\n return timeRange.state.value.to.valueOf();\n }\n }\n\n public getValueText?(): string {\n const timeRange = getTimeRange(this._sceneObject);\n if (this.state.name === '__from') {\n return dateTimeFormat(timeRange.state.value.from, { timeZone: timeRange.getTimeZone() });\n } else {\n return dateTimeFormat(timeRange.state.value.to, { timeZone: timeRange.getTimeZone() });\n }\n }\n}\n\n/**\n * Handles $__timezone expression.\n */\nexport class TimezoneMacro implements FormatVariable {\n public state: { name: string; type: string };\n private _sceneObject: SceneObject;\n\n public constructor(name: string, sceneObject: SceneObject) {\n this.state = { name: name, type: 'time_macro' };\n this._sceneObject = sceneObject;\n }\n\n public getValue() {\n const timeRange = getTimeRange(this._sceneObject);\n const timeZone = timeRange.getTimeZone();\n\n if (timeZone === 'browser') {\n return Intl.DateTimeFormat().resolvedOptions().timeZone;\n }\n\n return timeZone;\n }\n\n public getValueText?(): string {\n return this.getValue();\n }\n}\n\n/**\n * Handles $__interval and $__intervalMs expression.\n */\nexport class IntervalMacro implements FormatVariable {\n public state: { name: string; type: string; match: string };\n private _sceneObject: SceneObject;\n\n public constructor(name: string, sceneObject: SceneObject, match: string) {\n this.state = { name: name, type: 'time_macro', match: match };\n this._sceneObject = sceneObject;\n }\n\n public getValue() {\n const data = getData(this._sceneObject);\n\n if (data) {\n const request = data.state.data?.request;\n if (!request) {\n return this.state.match;\n }\n if (this.state.name === '__interval_ms') {\n return request.intervalMs;\n }\n return request.interval;\n }\n\n return this.state.match;\n }\n}\n"],"names":[],"mappings":";;;;;AAUO,MAAM,iBAA4C,CAAA;AAAA,EAIhD,WAAA,CAAY,MAAc,WAA0B,EAAA;AACzD,IAAA,IAAA,CAAK,KAAQ,GAAA,EAAE,IAAY,EAAA,IAAA,EAAM,cAAe,EAAA,CAAA;AAChD,IAAA,IAAA,CAAK,YAAe,GAAA,WAAA,CAAA;AAAA,GACtB;AAAA,EAEO,QAAgC,GAAA;AAnBzC,IAAA,IAAA,EAAA,CAAA;AAoBI,IAAM,MAAA,SAAA,GAAY,YAAa,CAAA,IAAA,CAAK,YAAY,CAAA,CAAA;AAChD,IAAM,MAAA,QAAA,GAAA,CAAW,EAAU,GAAA,SAAA,CAAA,OAAA,KAAV,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AM,MAAA,IAAA,GAAO,OAAQ,CAAA,IAAA,CAAK,YAAY,CAAA,CAAA;AAEtC,IAAA,IAAI,IAAM,EAAA;AACR,MAAA,MAAM,OAAU,GAAA,CAAA,EAAA,GAAA,IAAA,CAAK,KAAM,CAAA,IAAA,KAAX,IAAiB,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,OAAA,CAAA;AACjC,MAAA,IAAI,CAAC,OAAS,EAAA;AACZ,QAAA,OAAO,KAAK,KAAM,CAAA,KAAA,CAAA;AAAA,OACpB;AACA,MAAI,IAAA,IAAA,CAAK,KAAM,CAAA,IAAA,KAAS,eAAiB,EAAA;AACvC,QAAA,OAAO,OAAQ,CAAA,UAAA,CAAA;AAAA,OACjB;AACA,MAAA,OAAO,OAAQ,CAAA,QAAA,CAAA;AAAA,KACjB;AAEA,IAAA,OAAO,KAAK,KAAM,CAAA,KAAA,CAAA;AAAA,GACpB;AACF;;;;"}
|
package/dist/index.js
CHANGED
@@ -893,10 +893,7 @@ class SceneTimeRange extends SceneObjectBase {
|
|
893
893
|
}
|
894
894
|
getUrlState() {
|
895
895
|
const params = runtime.locationService.getSearchObject();
|
896
|
-
const urlValues = { from: this.state.from, to: this.state.to };
|
897
|
-
if (this.state.timeZone) {
|
898
|
-
urlValues.timezone = this.state.timeZone;
|
899
|
-
}
|
896
|
+
const urlValues = { from: this.state.from, to: this.state.to, timezone: this.getTimeZone() };
|
900
897
|
if (params.time && params["time.window"]) {
|
901
898
|
urlValues.time = null;
|
902
899
|
urlValues["time.window"] = null;
|
@@ -1342,6 +1339,9 @@ class UrlTimeRangeMacro {
|
|
1342
1339
|
var _a;
|
1343
1340
|
const timeRange = getTimeRange(this._sceneObject);
|
1344
1341
|
const urlState = (_a = timeRange.urlSync) == null ? void 0 : _a.getUrlState();
|
1342
|
+
if ((urlState == null ? void 0 : urlState.timezone) === "browser") {
|
1343
|
+
urlState.timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
1344
|
+
}
|
1345
1345
|
return new SkipFormattingValue(data.urlUtil.toUrlParams(urlState));
|
1346
1346
|
}
|
1347
1347
|
getValueText() {
|