@grafana/scenes 5.3.5--canary.811.9767690637.0 → 5.3.5--canary.814.9776702793.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -68,10 +68,10 @@ class SceneRefreshPicker extends SceneObjectBase {
|
|
68
68
|
const resolution = (_a = window == null ? void 0 : window.innerWidth) != null ? _a : 2e3;
|
69
69
|
return rangeUtil.calculateInterval(timeRange.state.value, resolution, this.state.autoMinInterval);
|
70
70
|
};
|
71
|
-
this.setupIntervalTimer = (
|
71
|
+
this.setupIntervalTimer = () => {
|
72
72
|
var _a;
|
73
73
|
const timeRange = sceneGraph.getTimeRange(this);
|
74
|
-
const { refresh, intervals } =
|
74
|
+
const { refresh, intervals } = this.state;
|
75
75
|
if (this._intervalTimer || refresh === "") {
|
76
76
|
clearInterval(this._intervalTimer);
|
77
77
|
}
|
@@ -98,31 +98,27 @@ class SceneRefreshPicker extends SceneObjectBase {
|
|
98
98
|
}, intervalMs);
|
99
99
|
};
|
100
100
|
this.addActivationHandler(() => {
|
101
|
-
|
102
|
-
this.setupIntervalTimer({
|
103
|
-
refresh: (_a2 = state.refresh) != null ? _a2 : "",
|
104
|
-
intervals: (_b2 = state.intervals) != null ? _b2 : DEFAULT_INTERVALS
|
105
|
-
});
|
101
|
+
this.setupIntervalTimer();
|
106
102
|
return () => {
|
107
|
-
var
|
103
|
+
var _a2;
|
108
104
|
if (this._intervalTimer) {
|
109
105
|
clearInterval(this._intervalTimer);
|
110
106
|
}
|
111
|
-
(
|
107
|
+
(_a2 = this._autoTimeRangeListener) == null ? void 0 : _a2.unsubscribe();
|
112
108
|
};
|
113
109
|
});
|
114
110
|
}
|
115
111
|
getUrlState() {
|
116
112
|
return {
|
117
|
-
refresh: this.state.refresh
|
113
|
+
refresh: this.state.refresh
|
118
114
|
};
|
119
115
|
}
|
120
116
|
updateFromUrl(values) {
|
121
117
|
const refresh = values.refresh;
|
122
|
-
if (typeof refresh === "string") {
|
123
|
-
this.setState({
|
124
|
-
|
125
|
-
|
118
|
+
if (refresh && typeof refresh === "string") {
|
119
|
+
this.setState({
|
120
|
+
refresh
|
121
|
+
});
|
126
122
|
}
|
127
123
|
}
|
128
124
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"SceneRefreshPicker.js","sources":["../../../src/components/SceneRefreshPicker.tsx"],"sourcesContent":["import React from 'react';\nimport { Unsubscribable } from 'rxjs';\nimport { rangeUtil } from '@grafana/data';\nimport { config } from '@grafana/runtime';\nimport { RefreshPicker } from '@grafana/ui';\n\nimport { SceneObjectBase } from '../core/SceneObjectBase';\nimport { sceneGraph } from '../core/sceneGraph';\nimport { SceneComponentProps, SceneObject, SceneObjectState, SceneObjectUrlValues } from '../core/types';\nimport { SceneObjectUrlSyncConfig } from '../services/SceneObjectUrlSyncConfig';\n\nexport const DEFAULT_INTERVALS = ['5s', '10s', '30s', '1m', '5m', '15m', '30m', '1h', '2h', '1d'];\n\nexport interface SceneRefreshPickerState extends SceneObjectState {\n // Refresh interval, e.g. 5s, 1m, 2h\n refresh: string;\n autoEnabled?: boolean;\n autoMinInterval?: string;\n autoValue?: string;\n // List of allowed refresh intervals, e.g. ['5s', '1m']\n intervals?: string[];\n isOnCanvas?: boolean;\n primary?: boolean;\n withText?: boolean;\n}\n\nexport class SceneRefreshPicker extends SceneObjectBase<SceneRefreshPickerState> {\n public static Component = SceneRefreshPickerRenderer;\n protected _urlSync = new SceneObjectUrlSyncConfig(this, { keys: ['refresh'] });\n private _intervalTimer: ReturnType<typeof setInterval> | undefined;\n private _autoTimeRangeListener: Unsubscribable | undefined;\n\n public constructor(state: Partial<SceneRefreshPickerState>) {\n super({\n refresh: '',\n ...state,\n autoValue: undefined,\n autoEnabled: state.autoEnabled ?? true,\n autoMinInterval: state.autoMinInterval ?? config.minRefreshInterval,\n intervals: state.intervals ?? DEFAULT_INTERVALS,\n });\n\n this.addActivationHandler(() => {\n this.setupIntervalTimer({\n refresh: state.refresh ?? '',\n intervals: state.intervals ?? DEFAULT_INTERVALS,\n });\n\n return () => {\n if (this._intervalTimer) {\n clearInterval(this._intervalTimer);\n }\n\n this._autoTimeRangeListener?.unsubscribe();\n };\n });\n }\n\n public onRefresh = () => {\n const queryController = sceneGraph.getQueryController(this);\n if (queryController?.state.isRunning) {\n queryController.cancelAll();\n return;\n }\n\n const timeRange = sceneGraph.getTimeRange(this);\n\n if (this._intervalTimer) {\n clearInterval(this._intervalTimer);\n }\n\n timeRange.onRefresh();\n this.setupIntervalTimer();\n };\n\n public onIntervalChanged = (interval: string) => {\n this.setState({ refresh: interval });\n this.setupIntervalTimer();\n };\n\n public getUrlState() {\n return {\n refresh: this.state.refresh !== '' ? this.state.refresh : undefined,\n };\n }\n\n public updateFromUrl(values: SceneObjectUrlValues) {\n const refresh = values.refresh;\n\n if (typeof refresh === 'string') {\n this.setState({ refresh });\n } else if (refresh == null) {\n this.setState({ refresh: '' });\n }\n }\n\n private setupAutoTimeRangeListener = () => {\n // If the time range has changed, we need to recalculate the auto interval but prevent unnecessary processing\n return sceneGraph.getTimeRange(this).subscribeToState((newState, prevState) => {\n if (newState.from !== prevState.from || newState.to !== prevState.to) {\n this.setupIntervalTimer();\n }\n });\n };\n\n private calculateAutoRefreshInterval = () => {\n const timeRange = sceneGraph.getTimeRange(this);\n const resolution = window?.innerWidth ?? 2000;\n return rangeUtil.calculateInterval(timeRange.state.value, resolution, this.state.autoMinInterval);\n };\n\n private setupIntervalTimer = (partialState?: Pick<SceneRefreshPickerState, 'refresh' | 'intervals'>) => {\n const timeRange = sceneGraph.getTimeRange(this);\n // when calling setupIntervalTimer inside constructor this.state is out of sync with constructor state,\n // therefore passing partialState from constructor manually\n const { refresh, intervals } = partialState || this.state;\n\n if (this._intervalTimer || refresh === '') {\n clearInterval(this._intervalTimer);\n }\n\n if (refresh === '') {\n return;\n }\n\n // If the provided interval is not allowed\n if (refresh !== RefreshPicker.autoOption.value && intervals && !intervals.includes(refresh)) {\n return;\n }\n\n let intervalMs: number;\n\n // Unsubscribe from previous listener no matter what\n this._autoTimeRangeListener?.unsubscribe();\n\n if (refresh === RefreshPicker.autoOption.value) {\n const autoRefreshInterval = this.calculateAutoRefreshInterval();\n\n intervalMs = autoRefreshInterval.intervalMs;\n\n this._autoTimeRangeListener = this.setupAutoTimeRangeListener();\n\n if (autoRefreshInterval.interval !== this.state.autoValue) {\n this.setState({ autoValue: autoRefreshInterval.interval });\n }\n } else {\n intervalMs = rangeUtil.intervalToMs(refresh);\n }\n\n this._intervalTimer = setInterval(() => {\n timeRange.onRefresh();\n }, intervalMs);\n };\n}\n\nexport function SceneRefreshPickerRenderer({ model }: SceneComponentProps<SceneRefreshPicker>) {\n const { refresh, intervals, autoEnabled, autoValue, isOnCanvas, primary, withText } = model.useState();\n const isRunning = useQueryControllerState(model);\n\n let text = refresh === RefreshPicker.autoOption?.value ? autoValue : withText ? 'Refresh' : undefined;\n let tooltip: string | undefined;\n let width: string | undefined;\n\n if (isRunning) {\n tooltip = 'Cancel all queries';\n\n if (withText) {\n text = 'Cancel';\n }\n }\n\n if (withText) {\n width = '96px';\n }\n\n return (\n <RefreshPicker\n showAutoInterval={autoEnabled}\n value={refresh}\n intervals={intervals}\n tooltip={tooltip}\n width={width}\n text={text}\n onRefresh={model.onRefresh}\n primary={primary}\n onIntervalChanged={model.onIntervalChanged}\n isLoading={isRunning}\n isOnCanvas={isOnCanvas ?? true}\n />\n );\n}\n\nfunction useQueryControllerState(model: SceneObject): boolean {\n const queryController = sceneGraph.getQueryController(model);\n if (!queryController) {\n return false;\n }\n\n return queryController.useState().isRunning;\n}\n"],"names":["_a","_b"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAWa,MAAA,iBAAA,GAAoB,CAAC,IAAA,EAAM,KAAO,EAAA,KAAA,EAAO,IAAM,EAAA,IAAA,EAAM,KAAO,EAAA,KAAA,EAAO,IAAM,EAAA,IAAA,EAAM,IAAI,EAAA;AAezF,MAAM,2BAA2B,eAAyC,CAAA;AAAA,EAMxE,YAAY,KAAyC,EAAA;AAhC9D,IAAA,IAAA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AW,CAAA,SAAA,CAAA;AACpC;;;;"}
|
1
|
+
{"version":3,"file":"SceneRefreshPicker.js","sources":["../../../src/components/SceneRefreshPicker.tsx"],"sourcesContent":["import React from 'react';\nimport { Unsubscribable } from 'rxjs';\nimport { rangeUtil } from '@grafana/data';\nimport { config } from '@grafana/runtime';\nimport { RefreshPicker } from '@grafana/ui';\n\nimport { SceneObjectBase } from '../core/SceneObjectBase';\nimport { sceneGraph } from '../core/sceneGraph';\nimport { SceneComponentProps, SceneObject, SceneObjectState, SceneObjectUrlValues } from '../core/types';\nimport { SceneObjectUrlSyncConfig } from '../services/SceneObjectUrlSyncConfig';\n\nexport const DEFAULT_INTERVALS = ['5s', '10s', '30s', '1m', '5m', '15m', '30m', '1h', '2h', '1d'];\n\nexport interface SceneRefreshPickerState extends SceneObjectState {\n // Refresh interval, e.g. 5s, 1m, 2h\n refresh: string;\n autoEnabled?: boolean;\n autoMinInterval?: string;\n autoValue?: string;\n // List of allowed refresh intervals, e.g. ['5s', '1m']\n intervals?: string[];\n isOnCanvas?: boolean;\n primary?: boolean;\n withText?: boolean;\n}\n\nexport class SceneRefreshPicker extends SceneObjectBase<SceneRefreshPickerState> {\n public static Component = SceneRefreshPickerRenderer;\n protected _urlSync = new SceneObjectUrlSyncConfig(this, { keys: ['refresh'] });\n private _intervalTimer: ReturnType<typeof setInterval> | undefined;\n private _autoTimeRangeListener: Unsubscribable | undefined;\n\n public constructor(state: Partial<SceneRefreshPickerState>) {\n super({\n refresh: '',\n ...state,\n autoValue: undefined,\n autoEnabled: state.autoEnabled ?? true,\n autoMinInterval: state.autoMinInterval ?? config.minRefreshInterval,\n intervals: state.intervals ?? DEFAULT_INTERVALS,\n });\n\n this.addActivationHandler(() => {\n this.setupIntervalTimer();\n\n return () => {\n if (this._intervalTimer) {\n clearInterval(this._intervalTimer);\n }\n\n this._autoTimeRangeListener?.unsubscribe();\n };\n });\n }\n\n public onRefresh = () => {\n const queryController = sceneGraph.getQueryController(this);\n if (queryController?.state.isRunning) {\n queryController.cancelAll();\n return;\n }\n\n const timeRange = sceneGraph.getTimeRange(this);\n\n if (this._intervalTimer) {\n clearInterval(this._intervalTimer);\n }\n\n timeRange.onRefresh();\n this.setupIntervalTimer();\n };\n\n public onIntervalChanged = (interval: string) => {\n this.setState({ refresh: interval });\n this.setupIntervalTimer();\n };\n\n public getUrlState() {\n return {\n refresh: this.state.refresh,\n };\n }\n\n public updateFromUrl(values: SceneObjectUrlValues) {\n const refresh = values.refresh;\n\n if (refresh && typeof refresh === 'string') {\n this.setState({\n refresh,\n });\n }\n }\n\n private setupAutoTimeRangeListener = () => {\n // If the time range has changed, we need to recalculate the auto interval but prevent unnecessary processing\n return sceneGraph.getTimeRange(this).subscribeToState((newState, prevState) => {\n if (newState.from !== prevState.from || newState.to !== prevState.to) {\n this.setupIntervalTimer();\n }\n });\n };\n\n private calculateAutoRefreshInterval = () => {\n const timeRange = sceneGraph.getTimeRange(this);\n const resolution = window?.innerWidth ?? 2000;\n return rangeUtil.calculateInterval(timeRange.state.value, resolution, this.state.autoMinInterval);\n };\n\n private setupIntervalTimer = () => {\n const timeRange = sceneGraph.getTimeRange(this);\n const { refresh, intervals } = this.state;\n\n if (this._intervalTimer || refresh === '') {\n clearInterval(this._intervalTimer);\n }\n\n if (refresh === '') {\n return;\n }\n\n // If the provided interval is not allowed\n if (refresh !== RefreshPicker.autoOption.value && intervals && !intervals.includes(refresh)) {\n return;\n }\n\n let intervalMs: number;\n\n // Unsubscribe from previous listener no matter what\n this._autoTimeRangeListener?.unsubscribe();\n\n if (refresh === RefreshPicker.autoOption.value) {\n const autoRefreshInterval = this.calculateAutoRefreshInterval();\n\n intervalMs = autoRefreshInterval.intervalMs;\n\n this._autoTimeRangeListener = this.setupAutoTimeRangeListener();\n\n if (autoRefreshInterval.interval !== this.state.autoValue) {\n this.setState({ autoValue: autoRefreshInterval.interval });\n }\n } else {\n intervalMs = rangeUtil.intervalToMs(refresh);\n }\n\n this._intervalTimer = setInterval(() => {\n timeRange.onRefresh();\n }, intervalMs);\n };\n}\n\nexport function SceneRefreshPickerRenderer({ model }: SceneComponentProps<SceneRefreshPicker>) {\n const { refresh, intervals, autoEnabled, autoValue, isOnCanvas, primary, withText } = model.useState();\n const isRunning = useQueryControllerState(model);\n\n let text = refresh === RefreshPicker.autoOption?.value ? autoValue : withText ? 'Refresh' : undefined;\n let tooltip: string | undefined;\n let width: string | undefined;\n\n if (isRunning) {\n tooltip = 'Cancel all queries';\n\n if (withText) {\n text = 'Cancel';\n }\n }\n\n if (withText) {\n width = '96px';\n }\n\n return (\n <RefreshPicker\n showAutoInterval={autoEnabled}\n value={refresh}\n intervals={intervals}\n tooltip={tooltip}\n width={width}\n text={text}\n onRefresh={model.onRefresh}\n primary={primary}\n onIntervalChanged={model.onIntervalChanged}\n isLoading={isRunning}\n isOnCanvas={isOnCanvas ?? true}\n />\n );\n}\n\nfunction useQueryControllerState(model: SceneObject): boolean {\n const queryController = sceneGraph.getQueryController(model);\n if (!queryController) {\n return false;\n }\n\n return queryController.useState().isRunning;\n}\n"],"names":["_a"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAWa,MAAA,iBAAA,GAAoB,CAAC,IAAA,EAAM,KAAO,EAAA,KAAA,EAAO,IAAM,EAAA,IAAA,EAAM,KAAO,EAAA,KAAA,EAAO,IAAM,EAAA,IAAA,EAAM,IAAI,EAAA;AAezF,MAAM,2BAA2B,eAAyC,CAAA;AAAA,EAMxE,YAAY,KAAyC,EAAA;AAhC9D,IAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA,CAAA;AAiCI,IAAM,KAAA,CAAA,aAAA,CAAA,cAAA,CAAA;AAAA,MACJ,OAAS,EAAA,EAAA;AAAA,KAAA,EACN,KAFC,CAAA,EAAA;AAAA,MAGJ,SAAW,EAAA,KAAA,CAAA;AAAA,MACX,WAAA,EAAA,CAAa,EAAM,GAAA,KAAA,CAAA,WAAA,KAAN,IAAqB,GAAA,EAAA,GAAA,IAAA;AAA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,SAAA;AAAA,IACA,OAAA;AAAA,IACA,KAAA;AAAA,IACA,IAAA;AAAA,IACA,WAAW,KAAM,CAAA,SAAA;AAAA,IACjB,OAAA;AAAA,IACA,mBAAmB,KAAM,CAAA,iBAAA;AAAA,IACzB,SAAW,EAAA,SAAA;AAAA,IACX,YAAY,UAAc,IAAA,IAAA,GAAA,UAAA,GAAA,IAAA;AAAA,GAC5B,CAAA,CAAA;AAEJ,CAAA;AAEA,SAAS,wBAAwB,KAA6B,EAAA;AAC5D,EAAM,MAAA,eAAA,GAAkB,UAAW,CAAA,kBAAA,CAAmB,KAAK,CAAA,CAAA;AAC3D,EAAA,IAAI,CAAC,eAAiB,EAAA;AACpB,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AAEA,EAAO,OAAA,eAAA,CAAgB,UAAW,CAAA,SAAA,CAAA;AACpC;;;;"}
|
package/dist/index.d.ts
CHANGED
@@ -1805,7 +1805,7 @@ declare class SceneRefreshPicker extends SceneObjectBase<SceneRefreshPickerState
|
|
1805
1805
|
onRefresh: () => void;
|
1806
1806
|
onIntervalChanged: (interval: string) => void;
|
1807
1807
|
getUrlState(): {
|
1808
|
-
refresh: string
|
1808
|
+
refresh: string;
|
1809
1809
|
};
|
1810
1810
|
updateFromUrl(values: SceneObjectUrlValues): void;
|
1811
1811
|
private setupAutoTimeRangeListener;
|
package/dist/index.js
CHANGED
@@ -9116,10 +9116,10 @@ class SceneRefreshPicker extends SceneObjectBase {
|
|
9116
9116
|
const resolution = (_a = window == null ? void 0 : window.innerWidth) != null ? _a : 2e3;
|
9117
9117
|
return data.rangeUtil.calculateInterval(timeRange.state.value, resolution, this.state.autoMinInterval);
|
9118
9118
|
};
|
9119
|
-
this.setupIntervalTimer = (
|
9119
|
+
this.setupIntervalTimer = () => {
|
9120
9120
|
var _a;
|
9121
9121
|
const timeRange = sceneGraph.getTimeRange(this);
|
9122
|
-
const { refresh, intervals } =
|
9122
|
+
const { refresh, intervals } = this.state;
|
9123
9123
|
if (this._intervalTimer || refresh === "") {
|
9124
9124
|
clearInterval(this._intervalTimer);
|
9125
9125
|
}
|
@@ -9146,31 +9146,27 @@ class SceneRefreshPicker extends SceneObjectBase {
|
|
9146
9146
|
}, intervalMs);
|
9147
9147
|
};
|
9148
9148
|
this.addActivationHandler(() => {
|
9149
|
-
|
9150
|
-
this.setupIntervalTimer({
|
9151
|
-
refresh: (_a2 = state.refresh) != null ? _a2 : "",
|
9152
|
-
intervals: (_b2 = state.intervals) != null ? _b2 : DEFAULT_INTERVALS
|
9153
|
-
});
|
9149
|
+
this.setupIntervalTimer();
|
9154
9150
|
return () => {
|
9155
|
-
var
|
9151
|
+
var _a2;
|
9156
9152
|
if (this._intervalTimer) {
|
9157
9153
|
clearInterval(this._intervalTimer);
|
9158
9154
|
}
|
9159
|
-
(
|
9155
|
+
(_a2 = this._autoTimeRangeListener) == null ? void 0 : _a2.unsubscribe();
|
9160
9156
|
};
|
9161
9157
|
});
|
9162
9158
|
}
|
9163
9159
|
getUrlState() {
|
9164
9160
|
return {
|
9165
|
-
refresh: this.state.refresh
|
9161
|
+
refresh: this.state.refresh
|
9166
9162
|
};
|
9167
9163
|
}
|
9168
9164
|
updateFromUrl(values) {
|
9169
9165
|
const refresh = values.refresh;
|
9170
|
-
if (typeof refresh === "string") {
|
9171
|
-
this.setState({
|
9172
|
-
|
9173
|
-
|
9166
|
+
if (refresh && typeof refresh === "string") {
|
9167
|
+
this.setState({
|
9168
|
+
refresh
|
9169
|
+
});
|
9174
9170
|
}
|
9175
9171
|
}
|
9176
9172
|
}
|