@grafana/scenes 5.20.2--canary.939.11364841148.0 → 5.20.2--canary.939.11368617130.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -183,7 +183,6 @@ class SceneTimeRange extends SceneObjectBase {
|
|
183
183
|
const update = {};
|
184
184
|
let from = parseUrlParam(values.from);
|
185
185
|
let to = parseUrlParam(values.to);
|
186
|
-
let timeZone = values.timezone;
|
187
186
|
if (values.time && values["time.window"]) {
|
188
187
|
const time = Array.isArray(values.time) ? values.time[0] : values.time;
|
189
188
|
const timeWindow = Array.isArray(values["time.window"]) ? values["time.window"][0] : values["time.window"];
|
@@ -195,9 +194,6 @@ class SceneTimeRange extends SceneObjectBase {
|
|
195
194
|
to = timeRange.to;
|
196
195
|
}
|
197
196
|
}
|
198
|
-
if (!from && !to && !timeZone) {
|
199
|
-
return;
|
200
|
-
}
|
201
197
|
if (from && isValid(from)) {
|
202
198
|
update.from = from;
|
203
199
|
}
|
@@ -207,6 +203,9 @@ class SceneTimeRange extends SceneObjectBase {
|
|
207
203
|
if (typeof values.timezone === "string") {
|
208
204
|
update.timeZone = values.timezone !== "" ? values.timezone : void 0;
|
209
205
|
}
|
206
|
+
if (Object.keys(update).length === 0) {
|
207
|
+
return;
|
208
|
+
}
|
210
209
|
update.value = evaluateTimeRange(
|
211
210
|
(_a = update.from) != null ? _a : this.state.from,
|
212
211
|
(_b = update.to) != null ? _b : this.state.to,
|
@@ -214,7 +213,7 @@ class SceneTimeRange extends SceneObjectBase {
|
|
214
213
|
this.state.fiscalYearStartMonth,
|
215
214
|
this.state.UNSAFE_nowDelay
|
216
215
|
);
|
217
|
-
this.setState(update);
|
216
|
+
return this.setState(update);
|
218
217
|
}
|
219
218
|
}
|
220
219
|
function getTimeWindow(time, timeWindow) {
|
@@ -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 let timeZone = values.timezone;\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 && !to && !timeZone) {\n return;\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 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 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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,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 };\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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eRange extends SceneObjectBase {
|
|
907
907
|
const update = {};
|
908
908
|
let from = parseUrlParam(values.from);
|
909
909
|
let to = parseUrlParam(values.to);
|
910
|
-
let timeZone = values.timezone;
|
911
910
|
if (values.time && values["time.window"]) {
|
912
911
|
const time = Array.isArray(values.time) ? values.time[0] : values.time;
|
913
912
|
const timeWindow = Array.isArray(values["time.window"]) ? values["time.window"][0] : values["time.window"];
|
@@ -919,9 +918,6 @@ class SceneTimeRange extends SceneObjectBase {
|
|
919
918
|
to = timeRange.to;
|
920
919
|
}
|
921
920
|
}
|
922
|
-
if (!from && !to && !timeZone) {
|
923
|
-
return;
|
924
|
-
}
|
925
921
|
if (from && isValid$1(from)) {
|
926
922
|
update.from = from;
|
927
923
|
}
|
@@ -931,6 +927,9 @@ class SceneTimeRange extends SceneObjectBase {
|
|
931
927
|
if (typeof values.timezone === "string") {
|
932
928
|
update.timeZone = values.timezone !== "" ? values.timezone : void 0;
|
933
929
|
}
|
930
|
+
if (Object.keys(update).length === 0) {
|
931
|
+
return;
|
932
|
+
}
|
934
933
|
update.value = evaluateTimeRange(
|
935
934
|
(_a = update.from) != null ? _a : this.state.from,
|
936
935
|
(_b = update.to) != null ? _b : this.state.to,
|
@@ -938,7 +937,7 @@ class SceneTimeRange extends SceneObjectBase {
|
|
938
937
|
this.state.fiscalYearStartMonth,
|
939
938
|
this.state.UNSAFE_nowDelay
|
940
939
|
);
|
941
|
-
this.setState(update);
|
940
|
+
return this.setState(update);
|
942
941
|
}
|
943
942
|
}
|
944
943
|
function getTimeWindow(time, timeWindow) {
|