@grafana/scenes 4.30.0 → 4.31.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +13 -0
- package/dist/esm/components/SceneRefreshPicker.js +5 -5
- package/dist/esm/components/SceneRefreshPicker.js.map +1 -1
- package/dist/esm/variables/interpolation/sceneInterpolator.js +8 -5
- package/dist/esm/variables/interpolation/sceneInterpolator.js.map +1 -1
- package/dist/esm/variables/macros/index.js +19 -19
- package/dist/esm/variables/macros/index.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +32 -29
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
# v4.31.0 (Tue Jun 11 2024)
|
2
|
+
|
3
|
+
#### 🚀 Enhancement
|
4
|
+
|
5
|
+
- Variables: Fixes sceneInterpolator when string contains variables with object prototype function names [#785](https://github.com/grafana/scenes/pull/785) ([@torkelo](https://github.com/torkelo))
|
6
|
+
- SceneRefreshPicker: Fixes url state issue [#784](https://github.com/grafana/scenes/pull/784) ([@torkelo](https://github.com/torkelo))
|
7
|
+
|
8
|
+
#### Authors: 1
|
9
|
+
|
10
|
+
- Torkel Ödegaard ([@torkelo](https://github.com/torkelo))
|
11
|
+
|
12
|
+
---
|
13
|
+
|
1
14
|
# v4.30.0 (Tue Jun 11 2024)
|
2
15
|
|
3
16
|
#### 🚀 Enhancement
|
@@ -110,15 +110,15 @@ class SceneRefreshPicker extends SceneObjectBase {
|
|
110
110
|
}
|
111
111
|
getUrlState() {
|
112
112
|
return {
|
113
|
-
refresh: this.state.refresh
|
113
|
+
refresh: this.state.refresh !== "" ? this.state.refresh : void 0
|
114
114
|
};
|
115
115
|
}
|
116
116
|
updateFromUrl(values) {
|
117
117
|
const refresh = values.refresh;
|
118
|
-
if (
|
119
|
-
this.setState({
|
120
|
-
|
121
|
-
});
|
118
|
+
if (typeof refresh === "string") {
|
119
|
+
this.setState({ refresh });
|
120
|
+
} else if (refresh == null) {
|
121
|
+
this.setState({ refresh: "" });
|
122
122
|
}
|
123
123
|
}
|
124
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\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,KA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AAA,IAClB,KAAO,EAAA,OAAA;AAAA,IACP,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;;;;"}
|
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 !== '' ? 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 = () => {\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;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,UAAW,CAAA,SAAA,CAAA;AACpC;;;;"}
|
@@ -29,16 +29,19 @@ function sceneInterpolator(sceneObject, target, scopedVars, format, interpolatio
|
|
29
29
|
});
|
30
30
|
}
|
31
31
|
function lookupFormatVariable(name, match, scopedVars, sceneObject) {
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
if (scopedVars && scopedVars.hasOwnProperty(name)) {
|
33
|
+
const scopedVar = scopedVars[name];
|
34
|
+
if (scopedVar) {
|
35
|
+
return getSceneVariableForScopedVar(name, scopedVar);
|
36
|
+
}
|
35
37
|
}
|
36
38
|
const variable = lookupVariable(name, sceneObject);
|
37
39
|
if (variable) {
|
38
40
|
return variable;
|
39
41
|
}
|
40
|
-
|
41
|
-
|
42
|
+
const Macro = macrosIndex.get(name);
|
43
|
+
if (Macro) {
|
44
|
+
return new Macro(name, sceneObject, match, scopedVars);
|
42
45
|
}
|
43
46
|
return null;
|
44
47
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"sceneInterpolator.js","sources":["../../../../src/variables/interpolation/sceneInterpolator.ts"],"sourcesContent":["import { ScopedVars } from '@grafana/data';\nimport { VariableInterpolation } from '@grafana/runtime';\nimport { VariableType, VariableFormatID } from '@grafana/schema';\n\nimport { SceneObject } from '../../core/types';\nimport { InterpolationFormatParameter, isCustomVariableValue, VariableValue } from '../types';\n\nimport { getSceneVariableForScopedVar } from './ScopedVarsVariable';\nimport { formatRegistry, FormatVariable } from './formatRegistry';\nimport { VARIABLE_REGEX } from '../constants';\nimport { lookupVariable } from '../lookupVariable';\nimport { macrosIndex } from '../macros';\n\n/**\n * This function will try to parse and replace any variable expression found in the target string. The sceneObject will be used as the source of variables. It will\n * use the scene graph and walk up the parent tree until it finds the closest variable.\n *\n * ScopedVars should not really be needed much in the new scene architecture as they can be added to the local scene node instead of passed in interpolate function.\n * It is supported here for backward compatibility and some edge cases where adding scoped vars to local scene node is not practical.\n */\nexport function sceneInterpolator(\n sceneObject: SceneObject,\n target: string | undefined | null,\n scopedVars?: ScopedVars,\n format?: InterpolationFormatParameter,\n interpolations?: VariableInterpolation[]\n): string {\n if (!target) {\n return target ?? '';\n }\n\n VARIABLE_REGEX.lastIndex = 0;\n\n return target.replace(VARIABLE_REGEX, (match, var1, var2, fmt2, var3, fieldPath, fmt3) => {\n const variableName = var1 || var2 || var3;\n const fmt = fmt2 || fmt3 || format;\n const variable = lookupFormatVariable(variableName, match, scopedVars, sceneObject);\n\n if (!variable) {\n if (interpolations) {\n // Set `value` equal to `match` as documented in the `VariableInterpolation` interface.\n interpolations.push({ match, variableName, fieldPath, format: fmt, value: match, found: false });\n }\n return match;\n }\n\n const value = formatValue(sceneObject, variable, variable.getValue(fieldPath), fmt);\n\n if (interpolations) {\n interpolations.push({ match, variableName, fieldPath, format: fmt, value, found: value !== match });\n }\n\n return value;\n });\n}\n\nfunction lookupFormatVariable(\n name: string,\n match: string,\n scopedVars: ScopedVars | undefined,\n sceneObject: SceneObject\n): FormatVariable | null {\n const scopedVar = scopedVars
|
1
|
+
{"version":3,"file":"sceneInterpolator.js","sources":["../../../../src/variables/interpolation/sceneInterpolator.ts"],"sourcesContent":["import { ScopedVars } from '@grafana/data';\nimport { VariableInterpolation } from '@grafana/runtime';\nimport { VariableType, VariableFormatID } from '@grafana/schema';\n\nimport { SceneObject } from '../../core/types';\nimport { InterpolationFormatParameter, isCustomVariableValue, VariableValue } from '../types';\n\nimport { getSceneVariableForScopedVar } from './ScopedVarsVariable';\nimport { formatRegistry, FormatVariable } from './formatRegistry';\nimport { VARIABLE_REGEX } from '../constants';\nimport { lookupVariable } from '../lookupVariable';\nimport { macrosIndex } from '../macros';\n\n/**\n * This function will try to parse and replace any variable expression found in the target string. The sceneObject will be used as the source of variables. It will\n * use the scene graph and walk up the parent tree until it finds the closest variable.\n *\n * ScopedVars should not really be needed much in the new scene architecture as they can be added to the local scene node instead of passed in interpolate function.\n * It is supported here for backward compatibility and some edge cases where adding scoped vars to local scene node is not practical.\n */\nexport function sceneInterpolator(\n sceneObject: SceneObject,\n target: string | undefined | null,\n scopedVars?: ScopedVars,\n format?: InterpolationFormatParameter,\n interpolations?: VariableInterpolation[]\n): string {\n if (!target) {\n return target ?? '';\n }\n\n VARIABLE_REGEX.lastIndex = 0;\n\n return target.replace(VARIABLE_REGEX, (match, var1, var2, fmt2, var3, fieldPath, fmt3) => {\n const variableName = var1 || var2 || var3;\n const fmt = fmt2 || fmt3 || format;\n const variable = lookupFormatVariable(variableName, match, scopedVars, sceneObject);\n\n if (!variable) {\n if (interpolations) {\n // Set `value` equal to `match` as documented in the `VariableInterpolation` interface.\n interpolations.push({ match, variableName, fieldPath, format: fmt, value: match, found: false });\n }\n return match;\n }\n\n const value = formatValue(sceneObject, variable, variable.getValue(fieldPath), fmt);\n\n if (interpolations) {\n interpolations.push({ match, variableName, fieldPath, format: fmt, value, found: value !== match });\n }\n\n return value;\n });\n}\n\nfunction lookupFormatVariable(\n name: string,\n match: string,\n scopedVars: ScopedVars | undefined,\n sceneObject: SceneObject\n): FormatVariable | null {\n if (scopedVars && scopedVars.hasOwnProperty(name)) {\n const scopedVar = scopedVars[name];\n\n if (scopedVar) {\n return getSceneVariableForScopedVar(name, scopedVar);\n }\n }\n\n const variable = lookupVariable(name, sceneObject);\n if (variable) {\n return variable;\n }\n\n const Macro = macrosIndex.get(name);\n if (Macro) {\n return new Macro(name, sceneObject, match, scopedVars);\n }\n\n return null;\n}\n\nfunction formatValue(\n context: SceneObject,\n variable: FormatVariable,\n value: VariableValue | undefined | null,\n formatNameOrFn?: InterpolationFormatParameter\n): string {\n if (value === null || value === undefined) {\n return '';\n }\n\n // Variable can return a custom value that handles formatting\n // This is useful for customAllValue and macros that return values that are already formatted or need special formatting\n if (isCustomVariableValue(value)) {\n return sceneInterpolator(context, value.formatter(formatNameOrFn));\n }\n\n // if it's an object transform value to string\n if (!Array.isArray(value) && typeof value === 'object') {\n value = `${value}`;\n }\n\n if (typeof formatNameOrFn === 'function') {\n return formatNameOrFn(value, {\n name: variable.state.name,\n type: variable.state.type as VariableType,\n multi: variable.state.isMulti,\n includeAll: variable.state.includeAll,\n });\n }\n\n let args: string[] = [];\n\n if (!formatNameOrFn) {\n formatNameOrFn = VariableFormatID.Glob;\n } else {\n // some formats have arguments that come after ':' character\n args = formatNameOrFn.split(':');\n if (args.length > 1) {\n formatNameOrFn = args[0];\n args = args.slice(1);\n } else {\n args = [];\n }\n }\n\n let formatter = formatRegistry.getIfExists(formatNameOrFn);\n\n if (!formatter) {\n console.error(`Variable format ${formatNameOrFn} not found. Using glob format as fallback.`);\n formatter = formatRegistry.get(VariableFormatID.Glob);\n }\n\n return formatter.formatter(value, args, variable);\n}\n"],"names":[],"mappings":";;;;;;;;AAoBO,SAAS,iBACd,CAAA,WAAA,EACA,MACA,EAAA,UAAA,EACA,QACA,cACQ,EAAA;AACR,EAAA,IAAI,CAAC,MAAQ,EAAA;AACX,IAAA,OAAO,MAAU,IAAA,IAAA,GAAA,MAAA,GAAA,EAAA,CAAA;AAAA,GACnB;AAEA,EAAA,cAAA,CAAe,SAAY,GAAA,CAAA,CAAA;AAE3B,EAAO,OAAA,MAAA,CAAO,OAAQ,CAAA,cAAA,EAAgB,CAAC,KAAA,EAAO,MAAM,IAAM,EAAA,IAAA,EAAM,IAAM,EAAA,SAAA,EAAW,IAAS,KAAA;AACxF,IAAM,MAAA,YAAA,GAAe,QAAQ,IAAQ,IAAA,IAAA,CAAA;AACrC,IAAM,MAAA,GAAA,GAAM,QAAQ,IAAQ,IAAA,MAAA,CAAA;AAC5B,IAAA,MAAM,QAAW,GAAA,oBAAA,CAAqB,YAAc,EAAA,KAAA,EAAO,YAAY,WAAW,CAAA,CAAA;AAElF,IAAA,IAAI,CAAC,QAAU,EAAA;AACb,MAAA,IAAI,cAAgB,EAAA;AAElB,QAAe,cAAA,CAAA,IAAA,CAAK,EAAE,KAAA,EAAO,YAAc,EAAA,SAAA,EAAW,MAAQ,EAAA,GAAA,EAAK,KAAO,EAAA,KAAA,EAAO,KAA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c,CAAA,CAAA;AAEzD,EAAA,IAAI,CAAC,SAAW,EAAA;AACd,IAAQ,OAAA,CAAA,KAAA,CAAM,mBAAmB,cAA0D,CAAA,0CAAA,CAAA,CAAA,CAAA;AAC3F,IAAY,SAAA,GAAA,cAAA,CAAe,GAAI,CAAA,gBAAA,CAAiB,IAAI,CAAA,CAAA;AAAA,GACtD;AAEA,EAAA,OAAO,SAAU,CAAA,SAAA,CAAU,KAAO,EAAA,IAAA,EAAM,QAAQ,CAAA,CAAA;AAClD;;;;"}
|
@@ -5,29 +5,29 @@ import { ValueMacro, DataMacro, SeriesMacro, FieldMacro } from './dataMacros.js'
|
|
5
5
|
import { UrlMacro } from './urlMacros.js';
|
6
6
|
import { UserMacro, OrgMacro } from './contextMacros.js';
|
7
7
|
|
8
|
-
const macrosIndex =
|
9
|
-
[DataLinkBuiltInVars.includeVars
|
10
|
-
[DataLinkBuiltInVars.keepTime
|
11
|
-
["__value"
|
12
|
-
["__data"
|
13
|
-
["__series"
|
14
|
-
["__field"
|
15
|
-
["__url"
|
16
|
-
["__from"
|
17
|
-
["__to"
|
18
|
-
["__timezone"
|
19
|
-
["__user"
|
20
|
-
["__org"
|
21
|
-
["__interval"
|
22
|
-
["__interval_ms"
|
23
|
-
|
8
|
+
const macrosIndex = /* @__PURE__ */ new Map([
|
9
|
+
[DataLinkBuiltInVars.includeVars, AllVariablesMacro],
|
10
|
+
[DataLinkBuiltInVars.keepTime, UrlTimeRangeMacro],
|
11
|
+
["__value", ValueMacro],
|
12
|
+
["__data", DataMacro],
|
13
|
+
["__series", SeriesMacro],
|
14
|
+
["__field", FieldMacro],
|
15
|
+
["__url", UrlMacro],
|
16
|
+
["__from", TimeFromAndToMacro],
|
17
|
+
["__to", TimeFromAndToMacro],
|
18
|
+
["__timezone", TimezoneMacro],
|
19
|
+
["__user", UserMacro],
|
20
|
+
["__org", OrgMacro],
|
21
|
+
["__interval", IntervalMacro],
|
22
|
+
["__interval_ms", IntervalMacro]
|
23
|
+
]);
|
24
24
|
function registerVariableMacro(name, macro) {
|
25
|
-
if (macrosIndex
|
25
|
+
if (macrosIndex.get(name)) {
|
26
26
|
throw new Error(`Macro already registered ${name}`);
|
27
27
|
}
|
28
|
-
macrosIndex
|
28
|
+
macrosIndex.set(name, macro);
|
29
29
|
return () => {
|
30
|
-
delete
|
30
|
+
macrosIndex.delete(name);
|
31
31
|
};
|
32
32
|
}
|
33
33
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/variables/macros/index.ts"],"sourcesContent":["import { DataLinkBuiltInVars } from '@grafana/data';\nimport { MacroVariableConstructor } from './types';\nimport { IntervalMacro, TimeFromAndToMacro, TimezoneMacro, UrlTimeRangeMacro } from './timeMacros';\nimport { AllVariablesMacro } from './AllVariablesMacro';\nimport { DataMacro, FieldMacro, SeriesMacro, ValueMacro } from './dataMacros';\nimport { UrlMacro } from './urlMacros';\nimport { OrgMacro, UserMacro } from './contextMacros';\n\nexport const macrosIndex
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/variables/macros/index.ts"],"sourcesContent":["import { DataLinkBuiltInVars } from '@grafana/data';\nimport { MacroVariableConstructor } from './types';\nimport { IntervalMacro, TimeFromAndToMacro, TimezoneMacro, UrlTimeRangeMacro } from './timeMacros';\nimport { AllVariablesMacro } from './AllVariablesMacro';\nimport { DataMacro, FieldMacro, SeriesMacro, ValueMacro } from './dataMacros';\nimport { UrlMacro } from './urlMacros';\nimport { OrgMacro, UserMacro } from './contextMacros';\n\nexport const macrosIndex = new Map<string, MacroVariableConstructor>([\n [DataLinkBuiltInVars.includeVars, AllVariablesMacro],\n [DataLinkBuiltInVars.keepTime, UrlTimeRangeMacro],\n ['__value', ValueMacro],\n ['__data', DataMacro],\n ['__series', SeriesMacro],\n ['__field', FieldMacro],\n ['__url', UrlMacro],\n ['__from', TimeFromAndToMacro],\n ['__to', TimeFromAndToMacro],\n ['__timezone', TimezoneMacro],\n ['__user', UserMacro],\n ['__org', OrgMacro],\n ['__interval', IntervalMacro],\n ['__interval_ms', IntervalMacro],\n]);\n\n/**\n * Allows you to register a variable expression macro that can then be used in strings with syntax ${<macro_name>.<fieldPath>}\n * Call this on app activation and unregister the macro on deactivation.\n * @returns a function that unregisters the macro\n */\nexport function registerVariableMacro(name: string, macro: MacroVariableConstructor): () => void {\n if (macrosIndex.get(name)) {\n throw new Error(`Macro already registered ${name}`);\n }\n\n macrosIndex.set(name, macro);\n\n return () => {\n macrosIndex.delete(name);\n };\n}\n"],"names":[],"mappings":";;;;;;;AAQa,MAAA,WAAA,uBAAkB,GAAsC,CAAA;AAAA,EACnE,CAAC,mBAAoB,CAAA,WAAA,EAAa,iBAAiB,CAAA;AAAA,EACnD,CAAC,mBAAoB,CAAA,QAAA,EAAU,iBAAiB,CAAA;AAAA,EAChD,CAAC,WAAW,UAAU,CAAA;AAAA,EACtB,CAAC,UAAU,SAAS,CAAA;AAAA,EACpB,CAAC,YAAY,WAAW,CAAA;AAAA,EACxB,CAAC,WAAW,UAAU,CAAA;AAAA,EACtB,CAAC,SAAS,QAAQ,CAAA;AAAA,EAClB,CAAC,UAAU,kBAAkB,CAAA;AAAA,EAC7B,CAAC,QAAQ,kBAAkB,CAAA;AAAA,EAC3B,CAAC,cAAc,aAAa,CAAA;AAAA,EAC5B,CAAC,UAAU,SAAS,CAAA;AAAA,EACpB,CAAC,SAAS,QAAQ,CAAA;AAAA,EAClB,CAAC,cAAc,aAAa,CAAA;AAAA,EAC5B,CAAC,iBAAiB,aAAa,CAAA;AACjC,CAAC,EAAA;AAOe,SAAA,qBAAA,CAAsB,MAAc,KAA6C,EAAA;AAC/F,EAAI,IAAA,WAAA,CAAY,GAAI,CAAA,IAAI,CAAG,EAAA;AACzB,IAAM,MAAA,IAAI,KAAM,CAAA,CAAA,yBAAA,EAA4B,IAAM,CAAA,CAAA,CAAA,CAAA;AAAA,GACpD;AAEA,EAAY,WAAA,CAAA,GAAA,CAAI,MAAM,KAAK,CAAA,CAAA;AAE3B,EAAA,OAAO,MAAM;AACX,IAAA,WAAA,CAAY,OAAO,IAAI,CAAA,CAAA;AAAA,GACzB,CAAA;AACF;;;;"}
|
package/dist/index.d.ts
CHANGED
@@ -1795,7 +1795,7 @@ declare class SceneRefreshPicker extends SceneObjectBase<SceneRefreshPickerState
|
|
1795
1795
|
onRefresh: () => void;
|
1796
1796
|
onIntervalChanged: (interval: string) => void;
|
1797
1797
|
getUrlState(): {
|
1798
|
-
refresh: string;
|
1798
|
+
refresh: string | undefined;
|
1799
1799
|
};
|
1800
1800
|
updateFromUrl(values: SceneObjectUrlValues): void;
|
1801
1801
|
private setupAutoTimeRangeListener;
|
package/dist/index.js
CHANGED
@@ -1355,16 +1355,19 @@ function sceneInterpolator(sceneObject, target, scopedVars, format, interpolatio
|
|
1355
1355
|
});
|
1356
1356
|
}
|
1357
1357
|
function lookupFormatVariable(name, match, scopedVars, sceneObject) {
|
1358
|
-
|
1359
|
-
|
1360
|
-
|
1358
|
+
if (scopedVars && scopedVars.hasOwnProperty(name)) {
|
1359
|
+
const scopedVar = scopedVars[name];
|
1360
|
+
if (scopedVar) {
|
1361
|
+
return getSceneVariableForScopedVar(name, scopedVar);
|
1362
|
+
}
|
1361
1363
|
}
|
1362
1364
|
const variable = lookupVariable(name, sceneObject);
|
1363
1365
|
if (variable) {
|
1364
1366
|
return variable;
|
1365
1367
|
}
|
1366
|
-
|
1367
|
-
|
1368
|
+
const Macro = macrosIndex.get(name);
|
1369
|
+
if (Macro) {
|
1370
|
+
return new Macro(name, sceneObject, match, scopedVars);
|
1368
1371
|
}
|
1369
1372
|
return null;
|
1370
1373
|
}
|
@@ -2017,29 +2020,29 @@ class OrgMacro {
|
|
2017
2020
|
}
|
2018
2021
|
}
|
2019
2022
|
|
2020
|
-
const macrosIndex =
|
2021
|
-
[data.DataLinkBuiltInVars.includeVars
|
2022
|
-
[data.DataLinkBuiltInVars.keepTime
|
2023
|
-
["__value"
|
2024
|
-
["__data"
|
2025
|
-
["__series"
|
2026
|
-
["__field"
|
2027
|
-
["__url"
|
2028
|
-
["__from"
|
2029
|
-
["__to"
|
2030
|
-
["__timezone"
|
2031
|
-
["__user"
|
2032
|
-
["__org"
|
2033
|
-
["__interval"
|
2034
|
-
["__interval_ms"
|
2035
|
-
|
2023
|
+
const macrosIndex = /* @__PURE__ */ new Map([
|
2024
|
+
[data.DataLinkBuiltInVars.includeVars, AllVariablesMacro],
|
2025
|
+
[data.DataLinkBuiltInVars.keepTime, UrlTimeRangeMacro],
|
2026
|
+
["__value", ValueMacro],
|
2027
|
+
["__data", DataMacro],
|
2028
|
+
["__series", SeriesMacro],
|
2029
|
+
["__field", FieldMacro],
|
2030
|
+
["__url", UrlMacro],
|
2031
|
+
["__from", TimeFromAndToMacro],
|
2032
|
+
["__to", TimeFromAndToMacro],
|
2033
|
+
["__timezone", TimezoneMacro],
|
2034
|
+
["__user", UserMacro],
|
2035
|
+
["__org", OrgMacro],
|
2036
|
+
["__interval", IntervalMacro],
|
2037
|
+
["__interval_ms", IntervalMacro]
|
2038
|
+
]);
|
2036
2039
|
function registerVariableMacro(name, macro) {
|
2037
|
-
if (macrosIndex
|
2040
|
+
if (macrosIndex.get(name)) {
|
2038
2041
|
throw new Error(`Macro already registered ${name}`);
|
2039
2042
|
}
|
2040
|
-
macrosIndex
|
2043
|
+
macrosIndex.set(name, macro);
|
2041
2044
|
return () => {
|
2042
|
-
delete
|
2045
|
+
macrosIndex.delete(name);
|
2043
2046
|
};
|
2044
2047
|
}
|
2045
2048
|
|
@@ -9042,15 +9045,15 @@ class SceneRefreshPicker extends SceneObjectBase {
|
|
9042
9045
|
}
|
9043
9046
|
getUrlState() {
|
9044
9047
|
return {
|
9045
|
-
refresh: this.state.refresh
|
9048
|
+
refresh: this.state.refresh !== "" ? this.state.refresh : void 0
|
9046
9049
|
};
|
9047
9050
|
}
|
9048
9051
|
updateFromUrl(values) {
|
9049
9052
|
const refresh = values.refresh;
|
9050
|
-
if (
|
9051
|
-
this.setState({
|
9052
|
-
|
9053
|
-
});
|
9053
|
+
if (typeof refresh === "string") {
|
9054
|
+
this.setState({ refresh });
|
9055
|
+
} else if (refresh == null) {
|
9056
|
+
this.setState({ refresh: "" });
|
9054
9057
|
}
|
9055
9058
|
}
|
9056
9059
|
}
|