@grafana/scenes 5.1.1 → 5.2.0--canary.800.9594766304.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +12 -0
- package/dist/esm/components/SceneApp/SceneAppPageView.js +2 -0
- package/dist/esm/components/SceneApp/SceneAppPageView.js.map +1 -1
- package/dist/esm/components/SceneTimePicker.js +7 -0
- package/dist/esm/components/SceneTimePicker.js.map +1 -1
- package/dist/esm/variables/interpolation/sceneInterpolator.js +1 -1
- package/dist/esm/variables/interpolation/sceneInterpolator.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
# v5.1.2 (Wed Jun 19 2024)
|
2
|
+
|
3
|
+
#### 🐛 Bug Fix
|
4
|
+
|
5
|
+
- Scenes: Return value if not string in interpolator [#796](https://github.com/grafana/scenes/pull/796) ([@mdvictor](https://github.com/mdvictor))
|
6
|
+
|
7
|
+
#### Authors: 1
|
8
|
+
|
9
|
+
- Victor Marin ([@mdvictor](https://github.com/mdvictor))
|
10
|
+
|
11
|
+
---
|
12
|
+
|
1
13
|
# v5.1.1 (Wed Jun 19 2024)
|
2
14
|
|
3
15
|
#### 🐛 Bug Fix
|
@@ -11,6 +11,7 @@ function SceneAppPageView({ page, routeProps }) {
|
|
11
11
|
const params = useAppQueryParams();
|
12
12
|
const scene = page.getScene(routeProps.match);
|
13
13
|
const isInitialized = containerState.initializedScene === scene;
|
14
|
+
const { layout } = page.state;
|
14
15
|
useLayoutEffect(() => {
|
15
16
|
if (!isInitialized) {
|
16
17
|
containerPage.initializeScene(scene);
|
@@ -58,6 +59,7 @@ function SceneAppPageView({ page, routeProps }) {
|
|
58
59
|
}));
|
59
60
|
}
|
60
61
|
return /* @__PURE__ */ React.createElement(PluginPage, {
|
62
|
+
layout,
|
61
63
|
pageNav,
|
62
64
|
actions: pageActions,
|
63
65
|
renderTitle: containerState.renderTitle,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"SceneAppPageView.js","sources":["../../../../src/components/SceneApp/SceneAppPageView.tsx"],"sourcesContent":["import { NavModelItem, UrlQueryMap } from '@grafana/data';\nimport { PluginPage } from '@grafana/runtime';\nimport React, { useEffect, useLayoutEffect } from 'react';\n\nimport { RouteComponentProps } from 'react-router-dom';\nimport { SceneObject } from '../../core/types';\nimport { SceneDebugger } from '../SceneDebugger/SceneDebugger';\nimport { SceneAppPage } from './SceneAppPage';\nimport { SceneAppDrilldownView, SceneAppPageLike } from './types';\nimport { getUrlWithAppState, renderSceneComponentWithRouteProps, useAppQueryParams } from './utils';\nimport { useUrlSync } from '../../services/useUrlSync';\n\nexport interface Props {\n page: SceneAppPageLike;\n // activeTab?: SceneAppPageLike;\n routeProps: RouteComponentProps;\n}\n\nexport function SceneAppPageView({ page, routeProps }: Props) {\n const containerPage = getParentPageIfTab(page);\n const containerState = containerPage.useState();\n const params = useAppQueryParams();\n const scene = page.getScene(routeProps.match);\n const isInitialized = containerState.initializedScene === scene;\n\n useLayoutEffect(() => {\n // Before rendering scene components, we are making sure the URL sync is enabled for.\n if (!isInitialized) {\n containerPage.initializeScene(scene);\n }\n }, [scene, containerPage, isInitialized]);\n\n useEffect(() => {\n // Clear initializedScene when unmounting\n return () => containerPage.setState({ initializedScene: undefined });\n }, [containerPage]);\n\n const urlSyncInitialized = useUrlSync(containerPage);\n\n if (!isInitialized && !urlSyncInitialized) {\n return null;\n }\n\n const pageNav: NavModelItem = {\n text: containerState.title,\n img: containerState.titleImg,\n icon: containerState.titleIcon,\n url: getUrlWithAppState(containerState.url, containerState.preserveUrlKeys),\n hideFromBreadcrumbs: containerState.hideFromBreadcrumbs,\n parentItem: getParentBreadcrumbs(\n containerState.getParentPage ? containerState.getParentPage() : containerPage.parent,\n params\n ),\n };\n\n if (containerState.tabs) {\n pageNav.children = containerState.tabs.map((tab) => {\n return {\n text: tab.state.title,\n icon: tab.state.titleIcon,\n tabSuffix: tab.state.tabSuffix,\n active: page === tab,\n url: getUrlWithAppState(tab.state.url, tab.state.preserveUrlKeys),\n parentItem: pageNav,\n };\n });\n }\n\n let pageActions: React.ReactNode[] = [];\n if (containerState.controls) {\n pageActions = containerState.controls.map((control) => (\n <control.Component model={control} key={control.state.key} />\n ));\n }\n\n if (params['scene-debugger']) {\n pageActions.push(<SceneDebugger scene={containerPage} key={'scene-debugger'} />);\n }\n\n return (\n <PluginPage\n pageNav={pageNav}\n actions={pageActions}\n renderTitle={containerState.renderTitle}\n subTitle={containerState.subTitle}\n >\n <scene.Component model={scene} />\n </PluginPage>\n );\n}\n\n/**\n * For pages that are \"tabs\" this will return the parent page\n */\nfunction getParentPageIfTab(page: SceneAppPageLike) {\n if (page.parent instanceof SceneAppPage) {\n return page.parent;\n }\n\n return page;\n}\n\nfunction getParentBreadcrumbs(parent: SceneObject | undefined, params: UrlQueryMap): NavModelItem | undefined {\n if (parent instanceof SceneAppPage) {\n return {\n text: parent.state.title,\n url: getUrlWithAppState(parent.state.url, parent.state.preserveUrlKeys),\n hideFromBreadcrumbs: parent.state.hideFromBreadcrumbs,\n parentItem: getParentBreadcrumbs(\n parent.state.getParentPage ? parent.state.getParentPage() : parent.parent,\n params\n ),\n };\n }\n\n return undefined;\n}\n\nexport interface SceneAppDrilldownViewRenderProps {\n drilldown: SceneAppDrilldownView;\n parent: SceneAppPageLike;\n routeProps: RouteComponentProps;\n}\n\nexport function SceneAppDrilldownViewRender({ drilldown, parent, routeProps }: SceneAppDrilldownViewRenderProps) {\n return renderSceneComponentWithRouteProps(parent.getDrilldownPage(drilldown, routeProps.match), routeProps);\n}\n"],"names":[],"mappings":";;;;;;;AAkBO,SAAS,gBAAiB,CAAA,EAAE,IAAM,EAAA,UAAA,EAAqB,EAAA;AAC5D,EAAM,MAAA,aAAA,GAAgB,mBAAmB,IAAI,CAAA,CAAA;AAC7C,EAAM,MAAA,cAAA,GAAiB,cAAc,QAAS,EAAA,CAAA;AAC9C,EAAA,MAAM,SAAS,iBAAkB,EAAA,CAAA;AACjC,EAAA,MAAM,KAAQ,GAAA,IAAA,CAAK,QAAS,CAAA,UAAA,CAAW,KAAK,CAAA,CAAA;AAC5C,EAAM,MAAA,aAAA,GAAgB,eAAe,gBAAqB,KAAA,KAAA,CAAA;
|
1
|
+
{"version":3,"file":"SceneAppPageView.js","sources":["../../../../src/components/SceneApp/SceneAppPageView.tsx"],"sourcesContent":["import { NavModelItem, UrlQueryMap } from '@grafana/data';\nimport { PluginPage } from '@grafana/runtime';\nimport React, { useEffect, useLayoutEffect } from 'react';\n\nimport { RouteComponentProps } from 'react-router-dom';\nimport { SceneObject } from '../../core/types';\nimport { SceneDebugger } from '../SceneDebugger/SceneDebugger';\nimport { SceneAppPage } from './SceneAppPage';\nimport { SceneAppDrilldownView, SceneAppPageLike } from './types';\nimport { getUrlWithAppState, renderSceneComponentWithRouteProps, useAppQueryParams } from './utils';\nimport { useUrlSync } from '../../services/useUrlSync';\n\nexport interface Props {\n page: SceneAppPageLike;\n // activeTab?: SceneAppPageLike;\n routeProps: RouteComponentProps;\n}\n\nexport function SceneAppPageView({ page, routeProps }: Props) {\n const containerPage = getParentPageIfTab(page);\n const containerState = containerPage.useState();\n const params = useAppQueryParams();\n const scene = page.getScene(routeProps.match);\n const isInitialized = containerState.initializedScene === scene;\n const {layout} = page.state;\n\n useLayoutEffect(() => {\n // Before rendering scene components, we are making sure the URL sync is enabled for.\n if (!isInitialized) {\n containerPage.initializeScene(scene);\n }\n }, [scene, containerPage, isInitialized]);\n\n useEffect(() => {\n // Clear initializedScene when unmounting\n return () => containerPage.setState({ initializedScene: undefined });\n }, [containerPage]);\n\n const urlSyncInitialized = useUrlSync(containerPage);\n\n if (!isInitialized && !urlSyncInitialized) {\n return null;\n }\n\n const pageNav: NavModelItem = {\n text: containerState.title,\n img: containerState.titleImg,\n icon: containerState.titleIcon,\n url: getUrlWithAppState(containerState.url, containerState.preserveUrlKeys),\n hideFromBreadcrumbs: containerState.hideFromBreadcrumbs,\n parentItem: getParentBreadcrumbs(\n containerState.getParentPage ? containerState.getParentPage() : containerPage.parent,\n params\n ),\n };\n\n if (containerState.tabs) {\n pageNav.children = containerState.tabs.map((tab) => {\n return {\n text: tab.state.title,\n icon: tab.state.titleIcon,\n tabSuffix: tab.state.tabSuffix,\n active: page === tab,\n url: getUrlWithAppState(tab.state.url, tab.state.preserveUrlKeys),\n parentItem: pageNav,\n };\n });\n }\n\n let pageActions: React.ReactNode[] = [];\n if (containerState.controls) {\n pageActions = containerState.controls.map((control) => (\n <control.Component model={control} key={control.state.key} />\n ));\n }\n\n if (params['scene-debugger']) {\n pageActions.push(<SceneDebugger scene={containerPage} key={'scene-debugger'} />);\n }\n\n return (\n <PluginPage\n layout={layout}\n pageNav={pageNav}\n actions={pageActions}\n renderTitle={containerState.renderTitle}\n subTitle={containerState.subTitle}\n >\n <scene.Component model={scene} />\n </PluginPage>\n );\n}\n\n/**\n * For pages that are \"tabs\" this will return the parent page\n */\nfunction getParentPageIfTab(page: SceneAppPageLike) {\n if (page.parent instanceof SceneAppPage) {\n return page.parent;\n }\n\n return page;\n}\n\nfunction getParentBreadcrumbs(parent: SceneObject | undefined, params: UrlQueryMap): NavModelItem | undefined {\n if (parent instanceof SceneAppPage) {\n return {\n text: parent.state.title,\n url: getUrlWithAppState(parent.state.url, parent.state.preserveUrlKeys),\n hideFromBreadcrumbs: parent.state.hideFromBreadcrumbs,\n parentItem: getParentBreadcrumbs(\n parent.state.getParentPage ? parent.state.getParentPage() : parent.parent,\n params\n ),\n };\n }\n\n return undefined;\n}\n\nexport interface SceneAppDrilldownViewRenderProps {\n drilldown: SceneAppDrilldownView;\n parent: SceneAppPageLike;\n routeProps: RouteComponentProps;\n}\n\nexport function SceneAppDrilldownViewRender({ drilldown, parent, routeProps }: SceneAppDrilldownViewRenderProps) {\n return renderSceneComponentWithRouteProps(parent.getDrilldownPage(drilldown, routeProps.match), routeProps);\n}\n"],"names":[],"mappings":";;;;;;;AAkBO,SAAS,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: month });
|
18
18
|
};
|
19
|
+
this.toAbsolute = () => {
|
20
|
+
const timeRange = sceneGraph.getTimeRange(this);
|
21
|
+
const timeRangeVal = timeRange.state.value;
|
22
|
+
const from = toUtc(timeRangeVal.from);
|
23
|
+
const to = toUtc(timeRangeVal.to);
|
24
|
+
timeRange.onTimeRangeChange({ from, to, raw: { from, to } });
|
25
|
+
};
|
19
26
|
this.onMoveBackward = () => {
|
20
27
|
const timeRange = sceneGraph.getTimeRange(this);
|
21
28
|
const {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"SceneTimePicker.js","sources":["../../../src/components/SceneTimePicker.tsx"],"sourcesContent":["import React from 'react';\n\nimport { TimeRangePicker } from '@grafana/ui';\n\nimport { SceneObjectBase } from '../core/SceneObjectBase';\nimport { sceneGraph } from '../core/sceneGraph';\nimport { SceneComponentProps, SceneObjectState } from '../core/types';\nimport { TimeRange, toUtc } from '@grafana/data';\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 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\n if (hidePicker) {\n return null;\n }\n\n return (\n <TimeRangePicker\n isOnCanvas={isOnCanvas ?? true}\n value={timeRangeState.value}\n onChange={timeRange.onTimeRangeChange}\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 />\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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,MAAU,SAAA,CAAA,iBAAA,CAAkB,oBAAoB,kBAAmB,CAAA,OAAA,EAAS,OAAO,IAAK,CAAA,GAAA,EAAK,CAAC,CAAA,CAAA;AAAA,KAChG,CAAA;AAAA,GAAA;AACF,CAAA;
|
1
|
+
{"version":3,"file":"SceneTimePicker.js","sources":["../../../src/components/SceneTimePicker.tsx"],"sourcesContent":["import React from 'react';\n\nimport { TimeRangePicker } from '@grafana/ui';\n\nimport { SceneObjectBase } from '../core/SceneObjectBase';\nimport { sceneGraph } from '../core/sceneGraph';\nimport { SceneComponentProps, SceneObjectState } from '../core/types';\nimport { TimeRange, toUtc } from '@grafana/data';\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\n if (hidePicker) {\n return null;\n }\n\n return (\n <TimeRangePicker\n isOnCanvas={isOnCanvas ?? true}\n value={timeRangeState.value}\n onChange={timeRange.onTimeRangeChange}\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 />\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}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A,mBAAA,CAAoB,GAAyB,EAAA,SAAA,EAAsB,UAA+B,EAAA;AAChH,EAAM,MAAA,KAAA,GAAQ,SAAU,CAAA,EAAA,CAAG,OAAQ,EAAA,CAAA;AACnC,EAAM,MAAA,OAAA,GAAU,SAAU,CAAA,IAAA,CAAK,OAAQ,EAAA,CAAA;AACvC,EAAM,MAAA,QAAA,GAAA,CAAY,QAAQ,OAAW,IAAA,CAAA,CAAA;AAErC,EAAI,IAAA,OAAA,CAAA;AACJ,EAAI,IAAA,KAAA,CAAA;AACJ,EAAA,IAAI,QAAQ,CAA6B,iBAAA;AACvC,IAAA,OAAA,GAAU,OAAU,GAAA,QAAA,CAAA;AACpB,IAAA,KAAA,GAAQ,KAAQ,GAAA,QAAA,CAAA;AAAA,GACX,MAAA;AACL,IAAA,OAAA,GAAU,OAAU,GAAA,QAAA,CAAA;AACpB,IAAA,KAAA,GAAQ,KAAQ,GAAA,QAAA,CAAA;AAEhB,IAAI,IAAA,KAAA,GAAQ,UAAc,IAAA,KAAA,GAAQ,UAAY,EAAA;AAC5C,MAAQ,KAAA,GAAA,UAAA,CAAA;AACR,MAAU,OAAA,GAAA,OAAA,CAAA;AAAA,KACZ;AAAA,GACF;AAEA,EAAM,MAAA,IAAA,GAAO,MAAM,OAAO,CAAA,CAAA;AAC1B,EAAM,MAAA,EAAA,GAAK,MAAM,KAAK,CAAA,CAAA;AACtB,EAAO,OAAA;AAAA,IACL,IAAA;AAAA,IACA,EAAA;AAAA,IACA,GAAA,EAAK,EAAE,IAAA,EAAM,EAAG,EAAA;AAAA,GAClB,CAAA;AACF;;;;"}
|
@@ -7,7 +7,7 @@ import { lookupVariable } from '../lookupVariable.js';
|
|
7
7
|
import { macrosIndex } from '../macros/index.js';
|
8
8
|
|
9
9
|
function sceneInterpolator(sceneObject, target, scopedVars, format, interpolations) {
|
10
|
-
if (!target) {
|
10
|
+
if (!target || typeof target !== "string") {
|
11
11
|
return target != null ? target : "";
|
12
12
|
}
|
13
13
|
VARIABLE_REGEX.lastIndex = 0;
|
@@ -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 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,
|
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 || typeof target !== 'string') {\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,MAAA,IAAU,OAAO,MAAA,KAAW,QAAU,EAAA;AACzC,IAAA,OAAO,MAAU,IAAA,IAAA,GAAA,MAAA,GAAA,EAAA,CAAA;AAAA,GACnB;AAEA,EA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AAA,OAAA;AAAA,MACtB,UAAA,EAAY,SAAS,KAAM,CAAA,UAAA;AAAA,KAC5B,CAAA,CAAA;AAAA,GACH;AAEA,EAAA,IAAI,OAAiB,EAAC,CAAA;AAEtB,EAAA,IAAI,CAAC,cAAgB,EAAA;AACnB,IAAA,cAAA,GAAiB,gBAAiB,CAAA,IAAA,CAAA;AAAA,GAC7B,MAAA;AAEL,IAAO,IAAA,GAAA,cAAA,CAAe,MAAM,GAAG,CAAA,CAAA;AAC/B,IAAI,IAAA,IAAA,CAAK,SAAS,CAAG,EAAA;AACnB,MAAA,cAAA,GAAiB,IAAK,CAAA,CAAA,CAAA,CAAA;AACtB,MAAO,IAAA,GAAA,IAAA,CAAK,MAAM,CAAC,CAAA,CAAA;AAAA,KACd,MAAA;AACL,MAAA,IAAA,GAAO,EAAC,CAAA;AAAA,KACV;AAAA,GACF;AAEA,EAAI,IAAA,SAAA,GAAY,cAAe,CAAA,WAAA,CAAY,cAAc,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;;;;"}
|
package/dist/index.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import * as _grafana_data from '@grafana/data';
|
2
|
-
import { BusEventWithPayload, PanelData, BusEvent, BusEventType, BusEventHandler, TimeRange, DataQueryRequest, DataSourceGetTagKeysOptions, DataSourceGetTagValuesOptions, DataTransformContext, DataFrame, PanelPlugin, EventBus, DataQuery as DataQuery$1, DataSourceApi, Registry, RegistryItem, ScopedVars, AdHocVariableFilter, SelectableValue, MetricFindValue, GetTagResponse, VariableRefresh as VariableRefresh$1, VariableSort, EventFilterOptions, AnnotationEvent, AnnotationQuery, DataTransformerConfig, PanelMenuItem, FieldConfigSource, PanelModel, AbsoluteTimeRange, InterpolateFunction, IconName as IconName$1, FieldConfig, FieldType, FieldValueMatcherConfig } from '@grafana/data';
|
2
|
+
import { BusEventWithPayload, PanelData, BusEvent, BusEventType, BusEventHandler, TimeRange, DataQueryRequest, DataSourceGetTagKeysOptions, DataSourceGetTagValuesOptions, DataTransformContext, DataFrame, PanelPlugin, EventBus, DataQuery as DataQuery$1, DataSourceApi, Registry, RegistryItem, ScopedVars, AdHocVariableFilter, SelectableValue, MetricFindValue, GetTagResponse, VariableRefresh as VariableRefresh$1, VariableSort, EventFilterOptions, AnnotationEvent, AnnotationQuery, DataTransformerConfig, PanelMenuItem, FieldConfigSource, PanelModel, AbsoluteTimeRange, InterpolateFunction, IconName as IconName$1, PageLayoutType, FieldConfig, FieldType, FieldValueMatcherConfig } from '@grafana/data';
|
3
3
|
import * as React$1 from 'react';
|
4
4
|
import React__default, { CSSProperties, ComponentType } from 'react';
|
5
5
|
import * as rxjs from 'rxjs';
|
@@ -1780,6 +1780,7 @@ declare class SceneTimePicker extends SceneObjectBase<SceneTimePickerState> {
|
|
1780
1780
|
static Component: typeof SceneTimePickerRenderer;
|
1781
1781
|
onZoom: () => void;
|
1782
1782
|
onChangeFiscalYearStartMonth: (month: number) => void;
|
1783
|
+
toAbsolute: () => void;
|
1783
1784
|
onMoveBackward: () => void;
|
1784
1785
|
onMoveForward: () => void;
|
1785
1786
|
}
|
@@ -2153,6 +2154,7 @@ interface SceneAppPageState extends SceneObjectState {
|
|
2153
2154
|
* to be rendered when url does not match current page exactly or any of tabs or drilldowns.
|
2154
2155
|
*/
|
2155
2156
|
getFallbackPage?: () => SceneAppPageLike;
|
2157
|
+
layout?: PageLayoutType;
|
2156
2158
|
}
|
2157
2159
|
interface SceneAppPageLike extends SceneObject<SceneAppPageState>, DataRequestEnricher {
|
2158
2160
|
initializeScene(scene: SceneObject): void;
|
package/dist/index.js
CHANGED
@@ -1655,7 +1655,7 @@ function registerVariableMacro(name, macro) {
|
|
1655
1655
|
}
|
1656
1656
|
|
1657
1657
|
function sceneInterpolator(sceneObject, target, scopedVars, format, interpolations) {
|
1658
|
-
if (!target) {
|
1658
|
+
if (!target || typeof target !== "string") {
|
1659
1659
|
return target != null ? target : "";
|
1660
1660
|
}
|
1661
1661
|
VARIABLE_REGEX.lastIndex = 0;
|
@@ -8966,6 +8966,13 @@ class SceneTimePicker extends SceneObjectBase {
|
|
8966
8966
|
const timeRange = sceneGraph.getTimeRange(this);
|
8967
8967
|
timeRange.setState({ fiscalYearStartMonth: month });
|
8968
8968
|
};
|
8969
|
+
this.toAbsolute = () => {
|
8970
|
+
const timeRange = sceneGraph.getTimeRange(this);
|
8971
|
+
const timeRangeVal = timeRange.state.value;
|
8972
|
+
const from = data.toUtc(timeRangeVal.from);
|
8973
|
+
const to = data.toUtc(timeRangeVal.to);
|
8974
|
+
timeRange.onTimeRangeChange({ from, to, raw: { from, to } });
|
8975
|
+
};
|
8969
8976
|
this.onMoveBackward = () => {
|
8970
8977
|
const timeRange = sceneGraph.getTimeRange(this);
|
8971
8978
|
const {
|
@@ -10451,6 +10458,7 @@ function SceneAppPageView({ page, routeProps }) {
|
|
10451
10458
|
const params = useAppQueryParams();
|
10452
10459
|
const scene = page.getScene(routeProps.match);
|
10453
10460
|
const isInitialized = containerState.initializedScene === scene;
|
10461
|
+
const { layout } = page.state;
|
10454
10462
|
React.useLayoutEffect(() => {
|
10455
10463
|
if (!isInitialized) {
|
10456
10464
|
containerPage.initializeScene(scene);
|
@@ -10498,6 +10506,7 @@ function SceneAppPageView({ page, routeProps }) {
|
|
10498
10506
|
}));
|
10499
10507
|
}
|
10500
10508
|
return /* @__PURE__ */ React__default["default"].createElement(runtime.PluginPage, {
|
10509
|
+
layout,
|
10501
10510
|
pageNav,
|
10502
10511
|
actions: pageActions,
|
10503
10512
|
renderTitle: containerState.renderTitle,
|