@grafana/scenes 5.18.2 → 5.18.3

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # v5.18.3 (Tue Oct 08 2024)
2
+
3
+ #### 🐛 Bug Fix
4
+
5
+ - Add checks for valid dates before saving calculating values [#914](https://github.com/grafana/scenes/pull/914) ([@javiruiz01](https://github.com/javiruiz01))
6
+
7
+ #### Authors: 1
8
+
9
+ - Javier Ruiz ([@javiruiz01](https://github.com/javiruiz01))
10
+
11
+ ---
12
+
1
13
  # v5.18.2 (Mon Oct 07 2024)
2
14
 
3
15
  #### 🐛 Bug Fix
@@ -5,6 +5,7 @@ import { getClosest } from './sceneGraph/utils.js';
5
5
  import { parseUrlParam } from '../utils/parseUrlParam.js';
6
6
  import { evaluateTimeRange } from '../utils/evaluateTimeRange.js';
7
7
  import { RefreshEvent, locationService } from '@grafana/runtime';
8
+ import { isValid } from '../utils/date.js';
8
9
 
9
10
  var __defProp = Object.defineProperty;
10
11
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
@@ -24,9 +25,9 @@ var __spreadValues = (a, b) => {
24
25
  };
25
26
  class SceneTimeRange extends SceneObjectBase {
26
27
  constructor(state = {}) {
27
- var _a, _b, _c;
28
- const from = (_a = state.from) != null ? _a : "now-6h";
29
- const to = (_b = state.to) != null ? _b : "now";
28
+ var _a;
29
+ const from = state.from && isValid(state.from) ? state.from : "now-6h";
30
+ const to = state.to && isValid(state.to) ? state.to : "now";
30
31
  const timeZone = state.timeZone;
31
32
  const value = evaluateTimeRange(
32
33
  from,
@@ -35,7 +36,7 @@ class SceneTimeRange extends SceneObjectBase {
35
36
  state.fiscalYearStartMonth,
36
37
  state.UNSAFE_nowDelay
37
38
  );
38
- const refreshOnActivate = (_c = state.refreshOnActivate) != null ? _c : { percent: 10 };
39
+ const refreshOnActivate = (_a = state.refreshOnActivate) != null ? _a : { percent: 10 };
39
40
  super(__spreadValues({ from, to, timeZone, value, refreshOnActivate }, state));
40
41
  this._urlSync = new SceneObjectUrlSyncConfig(this, { keys: ["from", "to", "timezone", "time", "time.window"] });
41
42
  this.onTimeRangeChange = (timeRange) => {
@@ -186,16 +187,20 @@ class SceneTimeRange extends SceneObjectBase {
186
187
  const time = Array.isArray(values.time) ? values.time[0] : values.time;
187
188
  const timeWindow = Array.isArray(values["time.window"]) ? values["time.window"][0] : values["time.window"];
188
189
  const timeRange = getTimeWindow(time, timeWindow);
189
- from = timeRange.from;
190
- to = timeRange.to;
190
+ if (timeRange.from && isValid(timeRange.from)) {
191
+ from = timeRange.from;
192
+ }
193
+ if (timeRange.to && isValid(timeRange.to)) {
194
+ to = timeRange.to;
195
+ }
191
196
  }
192
197
  if (!from && !to) {
193
198
  return;
194
199
  }
195
- if (from) {
200
+ if (from && isValid(from)) {
196
201
  update.from = from;
197
202
  }
198
- if (to) {
203
+ if (to && isValid(to)) {
199
204
  update.to = to;
200
205
  }
201
206
  if (typeof values.timezone === "string") {
@@ -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';\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 ?? 'now-6h';\n const to = state.to ?? 'now';\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 from = timeRange.from;\n to = timeRange.to;\n }\n\n if (!from && !to) {\n return;\n }\n\n if (from) {\n update.from = from;\n }\n\n if (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":";;;;;;;;;;;;;;;;;;;;;;;;AAYO,M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,KAAK,KAAM,CAAA,eAAA;AAAA,KACb,CAAA;AAEA,IAAA,IAAA,CAAK,SAAS,MAAM,CAAA,CAAA;AAAA,GACtB;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 };\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 && !to) {\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,IAAA,MAAM,qBAAoB,EAAM,GAAA,KAAA,CAAA,iBAAA,KAAN,IAA2B,GAAA,EAAA,GAAA,EAAE,SAAS,EAAG,EAAA,CAAA;AACnE,IAAA,KAAA,CAAM,iBAAE,IAAM,EAAA,EAAA,EAAI,QAAU,EAAA,KAAA,EAAO,qBAAsB,KAAO,CAAA,CAAA,CAAA;AAflE,IAAA,IAAA,CAAU,QAAW,GAAA,IAAI,wBAAyB,CAAA,IAAA,EAAM,EAAE,IAAA,EAAM,CAAC,MA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AAA,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;;;;"}
@@ -0,0 +1,15 @@
1
+ import { isDateTime, dateMath, dateTimeParse } from '@grafana/data';
2
+
3
+ function isValid(value, roundUp, timeZone) {
4
+ if (isDateTime(value)) {
5
+ return value.isValid();
6
+ }
7
+ if (dateMath.isMathString(value)) {
8
+ return dateMath.isValid(value);
9
+ }
10
+ const parsed = dateTimeParse(value, { roundUp, timeZone });
11
+ return parsed.isValid();
12
+ }
13
+
14
+ export { isValid };
15
+ //# sourceMappingURL=date.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"date.js","sources":["../../../src/utils/date.ts"],"sourcesContent":["import { isDateTime, dateMath, dateTimeParse } from '@grafana/data';\nimport { TimeZone } from '@grafana/schema';\n\nexport function isValid(value: string, roundUp?: boolean, timeZone?: TimeZone): boolean {\n if (isDateTime(value)) {\n return value.isValid();\n }\n\n if (dateMath.isMathString(value)) {\n return dateMath.isValid(value);\n }\n\n const parsed = dateTimeParse(value, { roundUp, timeZone });\n return parsed.isValid();\n}\n"],"names":[],"mappings":";;AAGgB,SAAA,OAAA,CAAQ,KAAe,EAAA,OAAA,EAAmB,QAA8B,EAAA;AACtF,EAAI,IAAA,UAAA,CAAW,KAAK,CAAG,EAAA;AACrB,IAAA,OAAO,MAAM,OAAQ,EAAA,CAAA;AAAA,GACvB;AAEA,EAAI,IAAA,QAAA,CAAS,YAAa,CAAA,KAAK,CAAG,EAAA;AAChC,IAAO,OAAA,QAAA,CAAS,QAAQ,KAAK,CAAA,CAAA;AAAA,GAC/B;AAEA,EAAA,MAAM,SAAS,aAAc,CAAA,KAAA,EAAO,EAAE,OAAA,EAAS,UAAU,CAAA,CAAA;AACzD,EAAA,OAAO,OAAO,OAAQ,EAAA,CAAA;AACxB;;;;"}
@@ -21,6 +21,11 @@ function parseUrlParam(value) {
21
21
  if (utcValue.isValid()) {
22
22
  return utcValue.toISOString();
23
23
  }
24
+ } else if (value.length === 19) {
25
+ const utcValue = toUtc(value, "YYYY-MM-DD HH:mm:ss");
26
+ if (utcValue.isValid()) {
27
+ return utcValue.toISOString();
28
+ }
24
29
  } else if (value.length === 24) {
25
30
  const utcValue = toUtc(value);
26
31
  return utcValue.toISOString();
@@ -1 +1 @@
1
- {"version":3,"file":"parseUrlParam.js","sources":["../../../src/utils/parseUrlParam.ts"],"sourcesContent":["import { toUtc } from '@grafana/data';\nimport { SceneObjectUrlValue } from '../core/types';\n\nconst INTERVAL_STRING_REGEX = /^\\d+[yYmMsSwWhHdD]$/;\n\nexport function parseUrlParam(value: SceneObjectUrlValue): string | null {\n if (typeof value !== 'string') {\n return null;\n }\n\n if (value.indexOf('now') !== -1) {\n return value;\n }\n\n if (INTERVAL_STRING_REGEX.test(value)) {\n return value;\n }\n\n if (value.length === 8) {\n const utcValue = toUtc(value, 'YYYYMMDD');\n if (utcValue.isValid()) {\n return utcValue.toISOString();\n }\n } else if (value.length === 15) {\n const utcValue = toUtc(value, 'YYYYMMDDTHHmmss');\n if (utcValue.isValid()) {\n return utcValue.toISOString();\n }\n } else if (value.length === 24) {\n const utcValue = toUtc(value);\n return utcValue.toISOString();\n }\n\n const epoch = parseInt(value, 10);\n if (!isNaN(epoch)) {\n return toUtc(epoch).toISOString();\n }\n\n return null;\n}\n"],"names":[],"mappings":";;AAGA,MAAM,qBAAwB,GAAA,qBAAA,CAAA;AAEvB,SAAS,cAAc,KAA2C,EAAA;AACvE,EAAI,IAAA,OAAO,UAAU,QAAU,EAAA;AAC7B,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AAEA,EAAA,IAAI,KAAM,CAAA,OAAA,CAAQ,KAAK,CAAA,KAAM,CAAI,CAAA,EAAA;AAC/B,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AAEA,EAAI,IAAA,qBAAA,CAAsB,IAAK,CAAA,KAAK,CAAG,EAAA;AACrC,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AAEA,EAAI,IAAA,KAAA,CAAM,WAAW,CAAG,EAAA;AACtB,IAAM,MAAA,QAAA,GAAW,KAAM,CAAA,KAAA,EAAO,UAAU,CAAA,CAAA;AACxC,IAAI,IAAA,QAAA,CAAS,SAAW,EAAA;AACtB,MAAA,OAAO,SAAS,WAAY,EAAA,CAAA;AAAA,KAC9B;AAAA,GACF,MAAA,IAAW,KAAM,CAAA,MAAA,KAAW,EAAI,EAAA;AAC9B,IAAM,MAAA,QAAA,GAAW,KAAM,CAAA,KAAA,EAAO,iBAAiB,CAAA,CAAA;AAC/C,IAAI,IAAA,QAAA,CAAS,SAAW,EAAA;AACtB,MAAA,OAAO,SAAS,WAAY,EAAA,CAAA;AAAA,KAC9B;AAAA,GACF,MAAA,IAAW,KAAM,CAAA,MAAA,KAAW,EAAI,EAAA;AAC9B,IAAM,MAAA,QAAA,GAAW,MAAM,KAAK,CAAA,CAAA;AAC5B,IAAA,OAAO,SAAS,WAAY,EAAA,CAAA;AAAA,GAC9B;AAEA,EAAM,MAAA,KAAA,GAAQ,QAAS,CAAA,KAAA,EAAO,EAAE,CAAA,CAAA;AAChC,EAAI,IAAA,CAAC,KAAM,CAAA,KAAK,CAAG,EAAA;AACjB,IAAO,OAAA,KAAA,CAAM,KAAK,CAAA,CAAE,WAAY,EAAA,CAAA;AAAA,GAClC;AAEA,EAAO,OAAA,IAAA,CAAA;AACT;;;;"}
1
+ {"version":3,"file":"parseUrlParam.js","sources":["../../../src/utils/parseUrlParam.ts"],"sourcesContent":["import { toUtc } from '@grafana/data';\nimport { SceneObjectUrlValue } from '../core/types';\n\nconst INTERVAL_STRING_REGEX = /^\\d+[yYmMsSwWhHdD]$/;\n\nexport function parseUrlParam(value: SceneObjectUrlValue): string | null {\n if (typeof value !== 'string') {\n return null;\n }\n\n if (value.indexOf('now') !== -1) {\n return value;\n }\n\n if (INTERVAL_STRING_REGEX.test(value)) {\n return value;\n }\n\n if (value.length === 8) {\n const utcValue = toUtc(value, 'YYYYMMDD');\n if (utcValue.isValid()) {\n return utcValue.toISOString();\n }\n } else if (value.length === 15) {\n const utcValue = toUtc(value, 'YYYYMMDDTHHmmss');\n if (utcValue.isValid()) {\n return utcValue.toISOString();\n }\n } else if (value.length === 19) {\n const utcValue = toUtc(value, 'YYYY-MM-DD HH:mm:ss');\n if (utcValue.isValid()) {\n return utcValue.toISOString();\n }\n } else if (value.length === 24) {\n const utcValue = toUtc(value);\n return utcValue.toISOString();\n }\n\n const epoch = parseInt(value, 10);\n if (!isNaN(epoch)) {\n return toUtc(epoch).toISOString();\n }\n\n return null;\n}\n"],"names":[],"mappings":";;AAGA,MAAM,qBAAwB,GAAA,qBAAA,CAAA;AAEvB,SAAS,cAAc,KAA2C,EAAA;AACvE,EAAI,IAAA,OAAO,UAAU,QAAU,EAAA;AAC7B,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AAEA,EAAA,IAAI,KAAM,CAAA,OAAA,CAAQ,KAAK,CAAA,KAAM,CAAI,CAAA,EAAA;AAC/B,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AAEA,EAAI,IAAA,qBAAA,CAAsB,IAAK,CAAA,KAAK,CAAG,EAAA;AACrC,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AAEA,EAAI,IAAA,KAAA,CAAM,WAAW,CAAG,EAAA;AACtB,IAAM,MAAA,QAAA,GAAW,KAAM,CAAA,KAAA,EAAO,UAAU,CAAA,CAAA;AACxC,IAAI,IAAA,QAAA,CAAS,SAAW,EAAA;AACtB,MAAA,OAAO,SAAS,WAAY,EAAA,CAAA;AAAA,KAC9B;AAAA,GACF,MAAA,IAAW,KAAM,CAAA,MAAA,KAAW,EAAI,EAAA;AAC9B,IAAM,MAAA,QAAA,GAAW,KAAM,CAAA,KAAA,EAAO,iBAAiB,CAAA,CAAA;AAC/C,IAAI,IAAA,QAAA,CAAS,SAAW,EAAA;AACtB,MAAA,OAAO,SAAS,WAAY,EAAA,CAAA;AAAA,KAC9B;AAAA,GACF,MAAA,IAAW,KAAM,CAAA,MAAA,KAAW,EAAI,EAAA;AAC9B,IAAM,MAAA,QAAA,GAAW,KAAM,CAAA,KAAA,EAAO,qBAAqB,CAAA,CAAA;AACnD,IAAI,IAAA,QAAA,CAAS,SAAW,EAAA;AACtB,MAAA,OAAO,SAAS,WAAY,EAAA,CAAA;AAAA,KAC9B;AAAA,GACF,MAAA,IAAW,KAAM,CAAA,MAAA,KAAW,EAAI,EAAA;AAC9B,IAAM,MAAA,QAAA,GAAW,MAAM,KAAK,CAAA,CAAA;AAC5B,IAAA,OAAO,SAAS,WAAY,EAAA,CAAA;AAAA,GAC9B;AAEA,EAAM,MAAA,KAAA,GAAQ,QAAS,CAAA,KAAA,EAAO,EAAE,CAAA,CAAA;AAChC,EAAI,IAAA,CAAC,KAAM,CAAA,KAAK,CAAG,EAAA;AACjB,IAAO,OAAA,KAAA,CAAM,KAAK,CAAA,CAAE,WAAY,EAAA,CAAA;AAAA,GAClC;AAEA,EAAO,OAAA,IAAA,CAAA;AACT;;;;"}
package/dist/index.js CHANGED
@@ -692,6 +692,11 @@ function parseUrlParam(value) {
692
692
  if (utcValue.isValid()) {
693
693
  return utcValue.toISOString();
694
694
  }
695
+ } else if (value.length === 19) {
696
+ const utcValue = data.toUtc(value, "YYYY-MM-DD HH:mm:ss");
697
+ if (utcValue.isValid()) {
698
+ return utcValue.toISOString();
699
+ }
695
700
  } else if (value.length === 24) {
696
701
  const utcValue = data.toUtc(value);
697
702
  return utcValue.toISOString();
@@ -715,6 +720,17 @@ function evaluateTimeRange(from, to, timeZone, fiscalYearStartMonth, delay) {
715
720
  };
716
721
  }
717
722
 
723
+ function isValid$1(value, roundUp, timeZone) {
724
+ if (data.isDateTime(value)) {
725
+ return value.isValid();
726
+ }
727
+ if (data.dateMath.isMathString(value)) {
728
+ return data.dateMath.isValid(value);
729
+ }
730
+ const parsed = data.dateTimeParse(value, { roundUp, timeZone });
731
+ return parsed.isValid();
732
+ }
733
+
718
734
  var __defProp$I = Object.defineProperty;
719
735
  var __getOwnPropSymbols$I = Object.getOwnPropertySymbols;
720
736
  var __hasOwnProp$I = Object.prototype.hasOwnProperty;
@@ -733,9 +749,9 @@ var __spreadValues$I = (a, b) => {
733
749
  };
734
750
  class SceneTimeRange extends SceneObjectBase {
735
751
  constructor(state = {}) {
736
- var _a, _b, _c;
737
- const from = (_a = state.from) != null ? _a : "now-6h";
738
- const to = (_b = state.to) != null ? _b : "now";
752
+ var _a;
753
+ const from = state.from && isValid$1(state.from) ? state.from : "now-6h";
754
+ const to = state.to && isValid$1(state.to) ? state.to : "now";
739
755
  const timeZone = state.timeZone;
740
756
  const value = evaluateTimeRange(
741
757
  from,
@@ -744,7 +760,7 @@ class SceneTimeRange extends SceneObjectBase {
744
760
  state.fiscalYearStartMonth,
745
761
  state.UNSAFE_nowDelay
746
762
  );
747
- const refreshOnActivate = (_c = state.refreshOnActivate) != null ? _c : { percent: 10 };
763
+ const refreshOnActivate = (_a = state.refreshOnActivate) != null ? _a : { percent: 10 };
748
764
  super(__spreadValues$I({ from, to, timeZone, value, refreshOnActivate }, state));
749
765
  this._urlSync = new SceneObjectUrlSyncConfig(this, { keys: ["from", "to", "timezone", "time", "time.window"] });
750
766
  this.onTimeRangeChange = (timeRange) => {
@@ -895,16 +911,20 @@ class SceneTimeRange extends SceneObjectBase {
895
911
  const time = Array.isArray(values.time) ? values.time[0] : values.time;
896
912
  const timeWindow = Array.isArray(values["time.window"]) ? values["time.window"][0] : values["time.window"];
897
913
  const timeRange = getTimeWindow(time, timeWindow);
898
- from = timeRange.from;
899
- to = timeRange.to;
914
+ if (timeRange.from && isValid$1(timeRange.from)) {
915
+ from = timeRange.from;
916
+ }
917
+ if (timeRange.to && isValid$1(timeRange.to)) {
918
+ to = timeRange.to;
919
+ }
900
920
  }
901
921
  if (!from && !to) {
902
922
  return;
903
923
  }
904
- if (from) {
924
+ if (from && isValid$1(from)) {
905
925
  update.from = from;
906
926
  }
907
- if (to) {
927
+ if (to && isValid$1(to)) {
908
928
  update.to = to;
909
929
  }
910
930
  if (typeof values.timezone === "string") {