@grafana/scenes 5.16.0--canary.915.11033672449.0 → 5.16.0--canary.915.11034968022.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +14 -0
- package/dist/esm/components/SceneTimePicker.js +1 -1
- package/dist/esm/components/SceneTimePicker.js.map +1 -1
- package/dist/esm/core/SceneTimeRange.js +2 -7
- package/dist/esm/core/SceneTimeRange.js.map +1 -1
- package/dist/index.js +3 -8
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
# v5.15.1 (Wed Sep 25 2024)
|
2
|
+
|
3
|
+
#### 🐛 Bug Fix
|
4
|
+
|
5
|
+
- SceneTimeRange: Fixes inconsistent representation of time range [#907](https://github.com/grafana/scenes/pull/907) ([@torkelo](https://github.com/torkelo))
|
6
|
+
- Use locationService from context in UrlSyncManager [#899](https://github.com/grafana/scenes/pull/899) ([@aocenas](https://github.com/aocenas))
|
7
|
+
|
8
|
+
#### Authors: 2
|
9
|
+
|
10
|
+
- Andrej Ocenas ([@aocenas](https://github.com/aocenas))
|
11
|
+
- Torkel Ödegaard ([@torkelo](https://github.com/torkelo))
|
12
|
+
|
13
|
+
---
|
14
|
+
|
1
15
|
# v5.15.0 (Wed Sep 25 2024)
|
2
16
|
|
3
17
|
#### 🚀 Enhancement
|
@@ -113,7 +113,7 @@ function getShiftedTimeRange(dir, timeRange, upperLimit) {
|
|
113
113
|
raw: { from, to }
|
114
114
|
};
|
115
115
|
}
|
116
|
-
const HISTORY_LOCAL_STORAGE_KEY = "grafana.
|
116
|
+
const HISTORY_LOCAL_STORAGE_KEY = "grafana.dashboard.timepicker.history";
|
117
117
|
function deserializeHistory(value) {
|
118
118
|
const values = JSON.parse(value);
|
119
119
|
return values.map((item) => rangeUtil.convertRawToRange(item, "utc", void 0, "YYYY-MM-DD HH:mm:ss"));
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"SceneTimePicker.js","sources":["../../../src/components/SceneTimePicker.tsx"],"sourcesContent":["import React from 'react';\nimport { useLocalStorage } from 'react-use';\nimport { uniqBy } from 'lodash';\n\nimport { TimeRange, isDateTime, rangeUtil, toUtc } from '@grafana/data';\nimport { TimeRangePicker } from '@grafana/ui';\n\nimport { SceneObjectBase } from '../core/SceneObjectBase';\nimport { sceneGraph } from '../core/sceneGraph';\nimport { SceneComponentProps, SceneObjectState } from '../core/types';\n\nexport interface SceneTimePickerState extends SceneObjectState {\n hidePicker?: boolean;\n isOnCanvas?: boolean;\n}\n\nexport class SceneTimePicker extends SceneObjectBase<SceneTimePickerState> {\n public static Component = SceneTimePickerRenderer;\n\n public onZoom = () => {\n const timeRange = sceneGraph.getTimeRange(this);\n const zoomedTimeRange = getZoomedTimeRange(timeRange.state.value, 2);\n timeRange.onTimeRangeChange(zoomedTimeRange);\n };\n\n public onChangeFiscalYearStartMonth = (month: number) => {\n const timeRange = sceneGraph.getTimeRange(this);\n timeRange.setState({ fiscalYearStartMonth: month });\n };\n\n public toAbsolute = () => {\n const timeRange = sceneGraph.getTimeRange(this);\n const timeRangeVal = timeRange.state.value;\n const from = toUtc(timeRangeVal.from);\n const to = toUtc(timeRangeVal.to);\n timeRange.onTimeRangeChange({ from, to, raw: { from, to } });\n };\n\n public onMoveBackward = () => {\n const timeRange = sceneGraph.getTimeRange(this);\n const {\n state: { value: range },\n } = timeRange;\n\n timeRange.onTimeRangeChange(getShiftedTimeRange(TimeRangeDirection.Backward, range, Date.now()));\n };\n\n public onMoveForward = () => {\n const timeRange = sceneGraph.getTimeRange(this);\n const {\n state: { value: range },\n } = timeRange;\n\n timeRange.onTimeRangeChange(getShiftedTimeRange(TimeRangeDirection.Forward, range, Date.now()));\n };\n}\n\nfunction SceneTimePickerRenderer({ model }: SceneComponentProps<SceneTimePicker>) {\n const { hidePicker, isOnCanvas } = model.useState();\n const timeRange = sceneGraph.getTimeRange(model);\n const timeZone = timeRange.getTimeZone();\n const timeRangeState = timeRange.useState();\n const [timeRangeHistory, setTimeRangeHistory] = useLocalStorage<TimeRange[]>(HISTORY_LOCAL_STORAGE_KEY, [], {\n raw: false,\n serializer: serializeHistory,\n deserializer: deserializeHistory,\n });\n\n if (hidePicker) {\n return null;\n }\n\n return (\n <TimeRangePicker\n isOnCanvas={isOnCanvas ?? true}\n value={timeRangeState.value}\n onChange={(range) => {\n if (isAbsolute(range)) {\n setTimeRangeHistory([range, ...(timeRangeHistory ?? [])]);\n }\n\n timeRange.onTimeRangeChange(range);\n }}\n timeZone={timeZone}\n fiscalYearStartMonth={timeRangeState.fiscalYearStartMonth}\n onMoveBackward={model.onMoveBackward}\n onMoveForward={model.onMoveForward}\n onZoom={model.onZoom}\n onChangeTimeZone={timeRange.onTimeZoneChange}\n onChangeFiscalYearStartMonth={model.onChangeFiscalYearStartMonth}\n // @ts-ignore TODO remove after grafana/ui update to 11.2.0\n weekStart={timeRangeState.weekStart}\n history={timeRangeHistory}\n />\n );\n}\n\nexport function getZoomedTimeRange(timeRange: TimeRange, factor: number): TimeRange {\n const timespan = timeRange.to.valueOf() - timeRange.from.valueOf();\n const center = timeRange.to.valueOf() - timespan / 2;\n // If the timepsan is 0, zooming out would do nothing, so we force a zoom out to 30s\n const newTimespan = timespan === 0 ? 30000 : timespan * factor;\n\n const to = center + newTimespan / 2;\n const from = center - newTimespan / 2;\n\n return { from: toUtc(from), to: toUtc(to), raw: { from: toUtc(from), to: toUtc(to) } };\n}\n\nexport enum TimeRangeDirection {\n Backward,\n Forward,\n}\n\nexport function getShiftedTimeRange(dir: TimeRangeDirection, timeRange: TimeRange, upperLimit: number): TimeRange {\n const oldTo = timeRange.to.valueOf();\n const oldFrom = timeRange.from.valueOf();\n const halfSpan = (oldTo - oldFrom) / 2;\n\n let fromRaw: number;\n let toRaw: number;\n if (dir === TimeRangeDirection.Backward) {\n fromRaw = oldFrom - halfSpan;\n toRaw = oldTo - halfSpan;\n } else {\n fromRaw = oldFrom + halfSpan;\n toRaw = oldTo + halfSpan;\n\n if (toRaw > upperLimit && oldTo < upperLimit) {\n toRaw = upperLimit;\n fromRaw = oldFrom;\n }\n }\n\n const from = toUtc(fromRaw);\n const to = toUtc(toRaw);\n return {\n from,\n to,\n raw: { from, to },\n };\n}\n\nconst HISTORY_LOCAL_STORAGE_KEY = 'grafana.scenes.dashboard.timepicker.history';\n\n// Simplified object to store in local storage\ninterface TimePickerHistoryItem {\n from: string;\n to: string;\n}\n\nfunction deserializeHistory(value: string): TimeRange[] {\n const values: TimePickerHistoryItem[] = JSON.parse(value);\n // The history is saved in UTC and with the default date format, so we need to pass those values to the convertRawToRange\n return values.map((item) => rangeUtil.convertRawToRange(item, 'utc', undefined, 'YYYY-MM-DD HH:mm:ss'));\n}\n\nfunction serializeHistory(values: TimeRange[]) {\n return JSON.stringify(\n limit(\n values.map((v) => ({\n from: typeof v.raw.from === 'string' ? v.raw.from : v.raw.from.toISOString(),\n to: typeof v.raw.to === 'string' ? v.raw.to : v.raw.to.toISOString(),\n }))\n )\n );\n}\n\nfunction limit(value: TimePickerHistoryItem[]): TimePickerHistoryItem[] {\n return uniqBy(value, (v) => v.from + v.to).slice(0, 4);\n}\n\nfunction isAbsolute(value: TimeRange): boolean {\n return isDateTime(value.raw.from) || isDateTime(value.raw.to);\n}\n"],"names":["TimeRangeDirection"],"mappings":";;;;;;;;AAgBO,MAAM,wBAAwB,eAAsC,CAAA;AAAA,EAApE,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA,CAAA;AAGL,IAAA,IAAA,CAAO,SAAS,MAAM;AACpB,MAAM,MAAA,SAAA,GAAY,UAAW,CAAA,YAAA,CAAa,IAAI,CAAA,CAAA;AAC9C,MAAA,MAAM,eAAkB,GAAA,kBAAA,CAAmB,SAAU,CAAA,KAAA,CAAM,OAAO,CAAC,CAAA,CAAA;AACnE,MAAA,SAAA,CAAU,kBAAkB,eAAe,CAAA,CAAA;AAAA,KAC7C,CAAA;AAEA,IAAO,IAAA,CAAA,4BAAA,GAA+B,CAAC,KAAkB,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A,CAAC,IAAS,KAAA,SAAA,CAAU,kBAAkB,IAAM,EAAA,KAAA,EAAO,KAAW,CAAA,EAAA,qBAAqB,CAAC,CAAA,CAAA;AACxG,CAAA;AAEA,SAAS,iBAAiB,MAAqB,EAAA;AAC7C,EAAA,OAAO,IAAK,CAAA,SAAA;AAAA,IACV,KAAA;AAAA,MACE,MAAA,CAAO,GAAI,CAAA,CAAC,CAAO,MAAA;AAAA,QACjB,IAAM,EAAA,OAAO,CAAE,CAAA,GAAA,CAAI,IAAS,KAAA,QAAA,GAAW,CAAE,CAAA,GAAA,CAAI,IAAO,GAAA,CAAA,CAAE,GAAI,CAAA,IAAA,CAAK,WAAY,EAAA;AAAA,QAC3E,EAAI,EAAA,OAAO,CAAE,CAAA,GAAA,CAAI,EAAO,KAAA,QAAA,GAAW,CAAE,CAAA,GAAA,CAAI,EAAK,GAAA,CAAA,CAAE,GAAI,CAAA,EAAA,CAAG,WAAY,EAAA;AAAA,OACnE,CAAA,CAAA;AAAA,KACJ;AAAA,GACF,CAAA;AACF,CAAA;AAEA,SAAS,MAAM,KAAyD,EAAA;AACtE,EAAO,OAAA,MAAA,CAAO,KAAO,EAAA,CAAC,CAAM,KAAA,CAAA,CAAE,IAAO,GAAA,CAAA,CAAE,EAAE,CAAA,CAAE,KAAM,CAAA,CAAA,EAAG,CAAC,CAAA,CAAA;AACvD,CAAA;AAEA,SAAS,WAAW,KAA2B,EAAA;AAC7C,EAAO,OAAA,UAAA,CAAW,MAAM,GAAI,CAAA,IAAI,KAAK,UAAW,CAAA,KAAA,CAAM,IAAI,EAAE,CAAA,CAAA;AAC9D;;;;"}
|
1
|
+
{"version":3,"file":"SceneTimePicker.js","sources":["../../../src/components/SceneTimePicker.tsx"],"sourcesContent":["import React from 'react';\nimport { useLocalStorage } from 'react-use';\nimport { uniqBy } from 'lodash';\n\nimport { TimeRange, isDateTime, rangeUtil, toUtc } from '@grafana/data';\nimport { TimeRangePicker } from '@grafana/ui';\n\nimport { SceneObjectBase } from '../core/SceneObjectBase';\nimport { sceneGraph } from '../core/sceneGraph';\nimport { SceneComponentProps, SceneObjectState } from '../core/types';\n\nexport interface SceneTimePickerState extends SceneObjectState {\n hidePicker?: boolean;\n isOnCanvas?: boolean;\n}\n\nexport class SceneTimePicker extends SceneObjectBase<SceneTimePickerState> {\n public static Component = SceneTimePickerRenderer;\n\n public onZoom = () => {\n const timeRange = sceneGraph.getTimeRange(this);\n const zoomedTimeRange = getZoomedTimeRange(timeRange.state.value, 2);\n timeRange.onTimeRangeChange(zoomedTimeRange);\n };\n\n public onChangeFiscalYearStartMonth = (month: number) => {\n const timeRange = sceneGraph.getTimeRange(this);\n timeRange.setState({ fiscalYearStartMonth: month });\n };\n\n public toAbsolute = () => {\n const timeRange = sceneGraph.getTimeRange(this);\n const timeRangeVal = timeRange.state.value;\n const from = toUtc(timeRangeVal.from);\n const to = toUtc(timeRangeVal.to);\n timeRange.onTimeRangeChange({ from, to, raw: { from, to } });\n };\n\n public onMoveBackward = () => {\n const timeRange = sceneGraph.getTimeRange(this);\n const {\n state: { value: range },\n } = timeRange;\n\n timeRange.onTimeRangeChange(getShiftedTimeRange(TimeRangeDirection.Backward, range, Date.now()));\n };\n\n public onMoveForward = () => {\n const timeRange = sceneGraph.getTimeRange(this);\n const {\n state: { value: range },\n } = timeRange;\n\n timeRange.onTimeRangeChange(getShiftedTimeRange(TimeRangeDirection.Forward, range, Date.now()));\n };\n}\n\nfunction SceneTimePickerRenderer({ model }: SceneComponentProps<SceneTimePicker>) {\n const { hidePicker, isOnCanvas } = model.useState();\n const timeRange = sceneGraph.getTimeRange(model);\n const timeZone = timeRange.getTimeZone();\n const timeRangeState = timeRange.useState();\n const [timeRangeHistory, setTimeRangeHistory] = useLocalStorage<TimeRange[]>(HISTORY_LOCAL_STORAGE_KEY, [], {\n raw: false,\n serializer: serializeHistory,\n deserializer: deserializeHistory,\n });\n\n if (hidePicker) {\n return null;\n }\n\n return (\n <TimeRangePicker\n isOnCanvas={isOnCanvas ?? true}\n value={timeRangeState.value}\n onChange={(range) => {\n if (isAbsolute(range)) {\n setTimeRangeHistory([range, ...(timeRangeHistory ?? [])]);\n }\n\n timeRange.onTimeRangeChange(range);\n }}\n timeZone={timeZone}\n fiscalYearStartMonth={timeRangeState.fiscalYearStartMonth}\n onMoveBackward={model.onMoveBackward}\n onMoveForward={model.onMoveForward}\n onZoom={model.onZoom}\n onChangeTimeZone={timeRange.onTimeZoneChange}\n onChangeFiscalYearStartMonth={model.onChangeFiscalYearStartMonth}\n // @ts-ignore TODO remove after grafana/ui update to 11.2.0\n weekStart={timeRangeState.weekStart}\n history={timeRangeHistory}\n />\n );\n}\n\nexport function getZoomedTimeRange(timeRange: TimeRange, factor: number): TimeRange {\n const timespan = timeRange.to.valueOf() - timeRange.from.valueOf();\n const center = timeRange.to.valueOf() - timespan / 2;\n // If the timepsan is 0, zooming out would do nothing, so we force a zoom out to 30s\n const newTimespan = timespan === 0 ? 30000 : timespan * factor;\n\n const to = center + newTimespan / 2;\n const from = center - newTimespan / 2;\n\n return { from: toUtc(from), to: toUtc(to), raw: { from: toUtc(from), to: toUtc(to) } };\n}\n\nexport enum TimeRangeDirection {\n Backward,\n Forward,\n}\n\nexport function getShiftedTimeRange(dir: TimeRangeDirection, timeRange: TimeRange, upperLimit: number): TimeRange {\n const oldTo = timeRange.to.valueOf();\n const oldFrom = timeRange.from.valueOf();\n const halfSpan = (oldTo - oldFrom) / 2;\n\n let fromRaw: number;\n let toRaw: number;\n if (dir === TimeRangeDirection.Backward) {\n fromRaw = oldFrom - halfSpan;\n toRaw = oldTo - halfSpan;\n } else {\n fromRaw = oldFrom + halfSpan;\n toRaw = oldTo + halfSpan;\n\n if (toRaw > upperLimit && oldTo < upperLimit) {\n toRaw = upperLimit;\n fromRaw = oldFrom;\n }\n }\n\n const from = toUtc(fromRaw);\n const to = toUtc(toRaw);\n return {\n from,\n to,\n raw: { from, to },\n };\n}\n\nconst HISTORY_LOCAL_STORAGE_KEY = 'grafana.dashboard.timepicker.history';\n\n// Simplified object to store in local storage\ninterface TimePickerHistoryItem {\n from: string;\n to: string;\n}\n\nfunction deserializeHistory(value: string): TimeRange[] {\n const values: TimePickerHistoryItem[] = JSON.parse(value);\n // The history is saved in UTC and with the default date format, so we need to pass those values to the convertRawToRange\n return values.map((item) => rangeUtil.convertRawToRange(item, 'utc', undefined, 'YYYY-MM-DD HH:mm:ss'));\n}\n\nfunction serializeHistory(values: TimeRange[]) {\n return JSON.stringify(\n limit(\n values.map((v) => ({\n from: typeof v.raw.from === 'string' ? v.raw.from : v.raw.from.toISOString(),\n to: typeof v.raw.to === 'string' ? v.raw.to : v.raw.to.toISOString(),\n }))\n )\n );\n}\n\nfunction limit(value: TimePickerHistoryItem[]): TimePickerHistoryItem[] {\n return uniqBy(value, (v) => v.from + v.to).slice(0, 4);\n}\n\nfunction isAbsolute(value: TimeRange): boolean {\n return isDateTime(value.raw.from) || isDateTime(value.raw.to);\n}\n"],"names":["TimeRangeDirection"],"mappings":";;;;;;;;AAgBO,MAAM,wBAAwB,eAAsC,CAAA;AAAA,EAApE,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA,CAAA;AAGL,IAAA,IAAA,CAAO,SAAS,MAAM;AACpB,MAAM,MAAA,SAAA,GAAY,UAAW,CAAA,YAAA,CAAa,IAAI,CAAA,CAAA;AAC9C,MAAA,MAAM,eAAkB,GAAA,kBAAA,CAAmB,SAAU,CAAA,KAAA,CAAM,OAAO,CAAC,CAAA,CAAA;AACnE,MAAA,SAAA,CAAU,kBAAkB,eAAe,CAAA,CAAA;AAAA,KAC7C,CAAA;AAEA,IAAO,IAAA,CAAA,4BAAA,GAA+B,CAAC,KAAkB,KAAA;AACvD,MAAM,MAAA,SAAA,GAAY,UAAW,CAAA,YAAA,CAAa,IAAI,CAAA,CAAA;AAC9C,MAAA,SAAA,CAAU,QAAS,CAAA,EAAE,oBAAsB,EAAA,KAAA,EAAO,CAAA,CAAA;AAAA,KACpD,CA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IAAK,CAAA,SAAA;AAAA,IACV,KAAA;AAAA,MACE,MAAA,CAAO,GAAI,CAAA,CAAC,CAAO,MAAA;AAAA,QACjB,IAAM,EAAA,OAAO,CAAE,CAAA,GAAA,CAAI,IAAS,KAAA,QAAA,GAAW,CAAE,CAAA,GAAA,CAAI,IAAO,GAAA,CAAA,CAAE,GAAI,CAAA,IAAA,CAAK,WAAY,EAAA;AAAA,QAC3E,EAAI,EAAA,OAAO,CAAE,CAAA,GAAA,CAAI,EAAO,KAAA,QAAA,GAAW,CAAE,CAAA,GAAA,CAAI,EAAK,GAAA,CAAA,CAAE,GAAI,CAAA,EAAA,CAAG,WAAY,EAAA;AAAA,OACnE,CAAA,CAAA;AAAA,KACJ;AAAA,GACF,CAAA;AACF,CAAA;AAEA,SAAS,MAAM,KAAyD,EAAA;AACtE,EAAO,OAAA,MAAA,CAAO,KAAO,EAAA,CAAC,CAAM,KAAA,CAAA,CAAE,IAAO,GAAA,CAAA,CAAE,EAAE,CAAA,CAAE,KAAM,CAAA,CAAA,EAAG,CAAC,CAAA,CAAA;AACvD,CAAA;AAEA,SAAS,WAAW,KAA2B,EAAA;AAC7C,EAAO,OAAA,UAAA,CAAW,MAAM,GAAI,CAAA,IAAI,KAAK,UAAW,CAAA,KAAA,CAAM,IAAI,EAAE,CAAA,CAAA;AAC9D;;;;"}
|
@@ -40,24 +40,19 @@ class SceneTimeRange extends SceneObjectBase {
|
|
40
40
|
this._urlSync = new SceneObjectUrlSyncConfig(this, { keys: ["from", "to", "timezone", "time", "time.window"] });
|
41
41
|
this.onTimeRangeChange = (timeRange) => {
|
42
42
|
const update = {};
|
43
|
-
const updateToEval = {};
|
44
43
|
if (typeof timeRange.raw.from === "string") {
|
45
44
|
update.from = timeRange.raw.from;
|
46
|
-
updateToEval.from = timeRange.raw.from;
|
47
45
|
} else {
|
48
46
|
update.from = timeRange.raw.from.toISOString();
|
49
|
-
updateToEval.from = timeRange.raw.from.toISOString(true);
|
50
47
|
}
|
51
48
|
if (typeof timeRange.raw.to === "string") {
|
52
49
|
update.to = timeRange.raw.to;
|
53
|
-
updateToEval.to = timeRange.raw.to;
|
54
50
|
} else {
|
55
51
|
update.to = timeRange.raw.to.toISOString();
|
56
|
-
updateToEval.to = timeRange.raw.to.toISOString(true);
|
57
52
|
}
|
58
53
|
update.value = evaluateTimeRange(
|
59
|
-
|
60
|
-
|
54
|
+
update.from,
|
55
|
+
update.to,
|
61
56
|
this.getTimeZone(),
|
62
57
|
this.state.fiscalYearStartMonth,
|
63
58
|
this.state.UNSAFE_nowDelay
|
@@ -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 const updateToEval: Partial<SceneTimeRangeState> = {};\n\n if (typeof timeRange.raw.from === 'string') {\n update.from = timeRange.raw.from;\n updateToEval.from = timeRange.raw.from;\n } else {\n update.from = timeRange.raw.from.toISOString();\n updateToEval.from = timeRange.raw.from.toISOString(true);\n }\n\n if (typeof timeRange.raw.to === 'string') {\n update.to = timeRange.raw.to;\n updateToEval.to = timeRange.raw.to;\n } else {\n update.to = timeRange.raw.to.toISOString();\n updateToEval.to = timeRange.raw.to.toISOString(true);\n }\n\n update.value = evaluateTimeRange(\n updateToEval.from,\n updateToEval.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,MAAM,uBAAuB,eAAmE,CAAA;AAAA,EAG9F,WAAA,CAAY,KAAsC,GAAA,EAAI,EAAA;A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AAA,CAAK,KAAM,CAAA,IAAA;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,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';\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,MAAM,uBAAuB,eAAmE,CAAA;AAAA,EAG9F,WAAA,CAAY,KAAsC,GAAA,EAAI,EAAA;AAf/D,IAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA,CAAA;AAgBI,IAAM,MAAA,IAAA,GAAA,CAAO,EAAM,GAAA,KAAA,CAAA,IAAA,KAAN,IAAc,GAAA,EAAA,GAAA,QAAA,CAAA;AAC3B,IAAM,MAAA,EAAA,GAAA,CAAK,EAAM,GAAA,KAAA,CAAA,EAAA,KAAN,IAAY,GAAA,EAAA,GAAA,KAAA,CAAA;AACvB,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,E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,GAAA,CAAC,EAAE,WAAY,EAAA;AAAA,GACtD,CAAA;AACF;;;;"}
|
package/dist/index.js
CHANGED
@@ -749,24 +749,19 @@ class SceneTimeRange extends SceneObjectBase {
|
|
749
749
|
this._urlSync = new SceneObjectUrlSyncConfig(this, { keys: ["from", "to", "timezone", "time", "time.window"] });
|
750
750
|
this.onTimeRangeChange = (timeRange) => {
|
751
751
|
const update = {};
|
752
|
-
const updateToEval = {};
|
753
752
|
if (typeof timeRange.raw.from === "string") {
|
754
753
|
update.from = timeRange.raw.from;
|
755
|
-
updateToEval.from = timeRange.raw.from;
|
756
754
|
} else {
|
757
755
|
update.from = timeRange.raw.from.toISOString();
|
758
|
-
updateToEval.from = timeRange.raw.from.toISOString(true);
|
759
756
|
}
|
760
757
|
if (typeof timeRange.raw.to === "string") {
|
761
758
|
update.to = timeRange.raw.to;
|
762
|
-
updateToEval.to = timeRange.raw.to;
|
763
759
|
} else {
|
764
760
|
update.to = timeRange.raw.to.toISOString();
|
765
|
-
updateToEval.to = timeRange.raw.to.toISOString(true);
|
766
761
|
}
|
767
762
|
update.value = evaluateTimeRange(
|
768
|
-
|
769
|
-
|
763
|
+
update.from,
|
764
|
+
update.to,
|
770
765
|
this.getTimeZone(),
|
771
766
|
this.state.fiscalYearStartMonth,
|
772
767
|
this.state.UNSAFE_nowDelay
|
@@ -10682,7 +10677,7 @@ function getShiftedTimeRange(dir, timeRange, upperLimit) {
|
|
10682
10677
|
raw: { from, to }
|
10683
10678
|
};
|
10684
10679
|
}
|
10685
|
-
const HISTORY_LOCAL_STORAGE_KEY = "grafana.
|
10680
|
+
const HISTORY_LOCAL_STORAGE_KEY = "grafana.dashboard.timepicker.history";
|
10686
10681
|
function deserializeHistory(value) {
|
10687
10682
|
const values = JSON.parse(value);
|
10688
10683
|
return values.map((item) => data.rangeUtil.convertRawToRange(item, "utc", void 0, "YYYY-MM-DD HH:mm:ss"));
|