@grafana/scenes 5.12.0 → 5.13.0--canary.878.10702174754.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/esm/components/SceneApp/SceneApp.js +7 -4
- package/dist/esm/components/SceneApp/SceneApp.js.map +1 -1
- package/dist/esm/components/SceneApp/SceneAppPageView.js +4 -2
- package/dist/esm/components/SceneApp/SceneAppPageView.js.map +1 -1
- package/dist/esm/core/SceneTimeRange.js +6 -2
- package/dist/esm/core/SceneTimeRange.js.map +1 -1
- package/dist/esm/core/sceneGraph/index.js +3 -2
- package/dist/esm/core/sceneGraph/index.js.map +1 -1
- package/dist/esm/core/sceneGraph/sceneGraph.js +11 -1
- package/dist/esm/core/sceneGraph/sceneGraph.js.map +1 -1
- package/dist/esm/core/types.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/services/SceneObjectUrlSyncConfig.js +9 -0
- package/dist/esm/services/SceneObjectUrlSyncConfig.js.map +1 -1
- package/dist/esm/services/UrlSyncContextProvider.js +7 -2
- package/dist/esm/services/UrlSyncContextProvider.js.map +1 -1
- package/dist/esm/services/UrlSyncManager.js +71 -37
- package/dist/esm/services/UrlSyncManager.js.map +1 -1
- package/dist/esm/services/useUrlSync.js +3 -3
- package/dist/esm/services/useUrlSync.js.map +1 -1
- package/dist/index.d.ts +61 -29
- package/dist/index.js +110 -46
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
@@ -1,4 +1,4 @@
|
|
1
|
-
import React from 'react';
|
1
|
+
import React, { createContext } from 'react';
|
2
2
|
import { Switch, Route } from 'react-router-dom';
|
3
3
|
import { SceneObjectBase } from '../../core/SceneObjectBase.js';
|
4
4
|
import { renderSceneComponentWithRouteProps } from './utils.js';
|
@@ -12,13 +12,16 @@ class SceneApp extends SceneObjectBase {
|
|
12
12
|
}
|
13
13
|
SceneApp.Component = ({ model }) => {
|
14
14
|
const { pages } = model.useState();
|
15
|
-
return /* @__PURE__ */ React.createElement(
|
15
|
+
return /* @__PURE__ */ React.createElement(SceneAppContext.Provider, {
|
16
|
+
value: model
|
17
|
+
}, /* @__PURE__ */ React.createElement(Switch, null, pages.map((page) => /* @__PURE__ */ React.createElement(Route, {
|
16
18
|
key: page.state.url,
|
17
19
|
exact: false,
|
18
20
|
path: page.state.url,
|
19
21
|
render: (props) => renderSceneComponentWithRouteProps(page, props)
|
20
|
-
})));
|
22
|
+
}))));
|
21
23
|
};
|
24
|
+
const SceneAppContext = createContext(null);
|
22
25
|
const sceneAppCache = /* @__PURE__ */ new Map();
|
23
26
|
function useSceneApp(factory) {
|
24
27
|
const cachedApp = sceneAppCache.get(factory);
|
@@ -30,5 +33,5 @@ function useSceneApp(factory) {
|
|
30
33
|
return newApp;
|
31
34
|
}
|
32
35
|
|
33
|
-
export { SceneApp, useSceneApp };
|
36
|
+
export { SceneApp, SceneAppContext, useSceneApp };
|
34
37
|
//# sourceMappingURL=SceneApp.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"SceneApp.js","sources":["../../../../src/components/SceneApp/SceneApp.tsx"],"sourcesContent":["import React from 'react';\nimport { Route, Switch } from 'react-router-dom';\n\nimport { DataRequestEnricher, SceneComponentProps } from '../../core/types';\nimport { SceneObjectBase } from '../../core/SceneObjectBase';\nimport { SceneAppState } from './types';\nimport { renderSceneComponentWithRouteProps } from './utils';\n\n/**\n * Responsible for top level pages routing\n */\nexport class SceneApp extends SceneObjectBase<SceneAppState> implements DataRequestEnricher {\n public enrichDataRequest() {\n return {\n app: this.state.name || 'app',\n };\n }\n\n public static Component = ({ model }: SceneComponentProps<SceneApp>) => {\n const { pages } = model.useState();\n\n return (\n <Switch>\n
|
1
|
+
{"version":3,"file":"SceneApp.js","sources":["../../../../src/components/SceneApp/SceneApp.tsx"],"sourcesContent":["import React, { createContext } from 'react';\nimport { Route, Switch } from 'react-router-dom';\n\nimport { DataRequestEnricher, SceneComponentProps } from '../../core/types';\nimport { SceneObjectBase } from '../../core/SceneObjectBase';\nimport { SceneAppState } from './types';\nimport { renderSceneComponentWithRouteProps } from './utils';\n\n/**\n * Responsible for top level pages routing\n */\nexport class SceneApp extends SceneObjectBase<SceneAppState> implements DataRequestEnricher {\n public enrichDataRequest() {\n return {\n app: this.state.name || 'app',\n };\n }\n\n public static Component = ({ model }: SceneComponentProps<SceneApp>) => {\n const { pages } = model.useState();\n\n return (\n <SceneAppContext.Provider value={model}>\n <Switch>\n {pages.map((page) => (\n <Route\n key={page.state.url}\n exact={false}\n path={page.state.url}\n render={(props) => renderSceneComponentWithRouteProps(page, props)}\n ></Route>\n ))}\n </Switch>\n </SceneAppContext.Provider>\n );\n };\n}\n\nexport const SceneAppContext = createContext<SceneApp | null>(null);\n\nconst sceneAppCache = new Map<object, SceneApp>();\n\n/**\n * Caches the the resulting SceneApp returned by the factory function so that it's only called once during the lifetime of the browser tab\n */\nexport function useSceneApp(factory: () => SceneApp) {\n const cachedApp = sceneAppCache.get(factory);\n\n if (cachedApp) {\n return cachedApp;\n }\n\n const newApp = factory();\n sceneAppCache.set(factory, newApp);\n\n return newApp;\n}\n"],"names":[],"mappings":";;;;;AAWO,MAAM,iBAAiB,eAA8D,CAAA;AAAA,EACnF,iBAAoB,GAAA;AACzB,IAAO,OAAA;AAAA,MACL,GAAA,EAAK,IAAK,CAAA,KAAA,CAAM,IAAQ,IAAA,KAAA;AAAA,KAC1B,CAAA;AAAA,GACF;AAoBF,CAAA;AAzBa,QAAA,CAOG,SAAY,GAAA,CAAC,EAAE,KAAA,EAA2C,KAAA;AACtE,EAAA,MAAM,EAAE,KAAA,EAAU,GAAA,KAAA,CAAM,QAAS,EAAA,CAAA;AAEjC,EACE,uBAAA,KAAA,CAAA,aAAA,CAAC,gBAAgB,QAAhB,EAAA;AAAA,IAAyB,KAAO,EAAA,KAAA;AAAA,GAAA,sCAC9B,MACE,EAAA,IAAA,EAAA,KAAA,CAAM,GAAI,CAAA,CAAC,yBACT,KAAA,CAAA,aAAA,CAAA,KAAA,EAAA;AAAA,IACC,GAAA,EAAK,KAAK,KAAM,CAAA,GAAA;AAAA,IAChB,KAAO,EAAA,KAAA;AAAA,IACP,IAAA,EAAM,KAAK,KAAM,CAAA,GAAA;AAAA,IACjB,MAAQ,EAAA,CAAC,KAAU,KAAA,kCAAA,CAAmC,MAAM,KAAK,CAAA;AAAA,GAClE,CACF,CACH,CACF,CAAA,CAAA;AAEJ,CAAA,CAAA;AAGW,MAAA,eAAA,GAAkB,cAA+B,IAAI,EAAA;AAElE,MAAM,aAAA,uBAAoB,GAAsB,EAAA,CAAA;AAKzC,SAAS,YAAY,OAAyB,EAAA;AACnD,EAAM,MAAA,SAAA,GAAY,aAAc,CAAA,GAAA,CAAI,OAAO,CAAA,CAAA;AAE3C,EAAA,IAAI,SAAW,EAAA;AACb,IAAO,OAAA,SAAA,CAAA;AAAA,GACT;AAEA,EAAA,MAAM,SAAS,OAAQ,EAAA,CAAA;AACvB,EAAc,aAAA,CAAA,GAAA,CAAI,SAAS,MAAM,CAAA,CAAA;AAEjC,EAAO,OAAA,MAAA,CAAA;AACT;;;;"}
|
@@ -1,15 +1,17 @@
|
|
1
1
|
import { PluginPage } from '@grafana/runtime';
|
2
|
-
import React, { useLayoutEffect, useEffect } from 'react';
|
2
|
+
import React, { useContext, useLayoutEffect, useEffect } from 'react';
|
3
3
|
import { SceneDebugger } from '../SceneDebugger/SceneDebugger.js';
|
4
4
|
import { SceneAppPage } from './SceneAppPage.js';
|
5
5
|
import { useAppQueryParams, getUrlWithAppState, renderSceneComponentWithRouteProps } from './utils.js';
|
6
6
|
import { useUrlSync } from '../../services/useUrlSync.js';
|
7
|
+
import { SceneAppContext } from './SceneApp.js';
|
7
8
|
|
8
9
|
function SceneAppPageView({ page, routeProps }) {
|
9
10
|
const containerPage = getParentPageIfTab(page);
|
10
11
|
const containerState = containerPage.useState();
|
11
12
|
const params = useAppQueryParams();
|
12
13
|
const scene = page.getScene(routeProps.match);
|
14
|
+
const appContext = useContext(SceneAppContext);
|
13
15
|
const isInitialized = containerState.initializedScene === scene;
|
14
16
|
const { layout } = page.state;
|
15
17
|
useLayoutEffect(() => {
|
@@ -20,7 +22,7 @@ function SceneAppPageView({ page, routeProps }) {
|
|
20
22
|
useEffect(() => {
|
21
23
|
return () => containerPage.setState({ initializedScene: void 0 });
|
22
24
|
}, [containerPage]);
|
23
|
-
const urlSyncInitialized = useUrlSync(containerPage);
|
25
|
+
const urlSyncInitialized = useUrlSync(containerPage, appContext == null ? void 0 : appContext.state.urlSyncOptions);
|
24
26
|
if (!isInitialized && !urlSyncInitialized) {
|
25
27
|
return null;
|
26
28
|
}
|
@@ -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
|
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, { useContext, 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';\nimport { SceneAppContext } from './SceneApp';\n\nexport interface Props {\n page: 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 appContext = useContext(SceneAppContext);\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, appContext?.state.urlSyncOptions);\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,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,UAAA,GAAa,WAAW,eAAe,CAAA,CAAA;AAC7C,EAAM,MAAA,aAAA,GAAgB,eAAe,gBAAqB,KAAA,KAAA,CAAA;AAC1D,EAAM,MAAA,EAAE,MAAO,EAAA,GAAI,IAAK,CAAA,KAAA,CAAA;AAExB,EAAA,eAAA,CAAgB,MAAM;AAEpB,IAAA,IAAI,CA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CAAA;AACT,CAAA;AAEA,SAAS,oBAAA,CAAqB,QAAiC,MAA+C,EAAA;AAC5G,EAAA,IAAI,kBAAkB,YAAc,EAAA;AAClC,IAAO,OAAA;AAAA,MACL,IAAA,EAAM,OAAO,KAAM,CAAA,KAAA;AAAA,MACnB,KAAK,kBAAmB,CAAA,MAAA,CAAO,MAAM,GAAK,EAAA,MAAA,CAAO,MAAM,eAAe,CAAA;AAAA,MACtE,mBAAA,EAAqB,OAAO,KAAM,CAAA,mBAAA;AAAA,MAClC,UAAY,EAAA,oBAAA;AAAA,QACV,OAAO,KAAM,CAAA,aAAA,GAAgB,OAAO,KAAM,CAAA,aAAA,KAAkB,MAAO,CAAA,MAErE,CAAA;AAAA,KACF,CAAA;AAAA,GACF;AAEA,EAAO,OAAA,KAAA,CAAA,CAAA;AACT,CAAA;AAQO,SAAS,2BAA4B,CAAA,EAAE,SAAW,EAAA,MAAA,EAAQ,YAAgD,EAAA;AAC/G,EAAA,OAAO,mCAAmC,MAAO,CAAA,gBAAA,CAAiB,WAAW,UAAW,CAAA,KAAK,GAAG,UAAU,CAAA,CAAA;AAC5G;;;;"}
|
@@ -63,11 +63,15 @@ class SceneTimeRange extends SceneObjectBase {
|
|
63
63
|
this.state.UNSAFE_nowDelay
|
64
64
|
);
|
65
65
|
if (update.from !== this.state.from || update.to !== this.state.to) {
|
66
|
-
this.
|
66
|
+
this._urlSync.performBrowserHistoryAction(() => {
|
67
|
+
this.setState(update);
|
68
|
+
});
|
67
69
|
}
|
68
70
|
};
|
69
71
|
this.onTimeZoneChange = (timeZone) => {
|
70
|
-
this.
|
72
|
+
this._urlSync.performBrowserHistoryAction(() => {
|
73
|
+
this.setState({ timeZone });
|
74
|
+
});
|
71
75
|
};
|
72
76
|
this.onRefresh = () => {
|
73
77
|
this.setState({
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"SceneTimeRange.js","sources":["../../../src/core/SceneTimeRange.tsx"],"sourcesContent":["import { getTimeZone, rangeUtil, setWeekStart, 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 { config, 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 (this.state.weekStart) {\n setWeekStart(this.state.weekStart);\n }\n\n if (rangeUtil.isRelativeTimeRange(this.state.value.raw)) {\n this.refreshIfStale();\n }\n\n // Deactivation handler that restore weekStart if it was changed\n return () => {\n if (this.state.weekStart) {\n setWeekStart(config.bootData.user.weekStart);\n }\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.setState(update);\n }\n };\n\n public onTimeZoneChange = (timeZone: TimeZone) => {\n this.setState({ timeZone });\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,MAC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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, setWeekStart, 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 { config, 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 (this.state.weekStart) {\n setWeekStart(this.state.weekStart);\n }\n\n if (rangeUtil.isRelativeTimeRange(this.state.value.raw)) {\n this.refreshIfStale();\n }\n\n // Deactivation handler that restore weekStart if it was changed\n return () => {\n if (this.state.weekStart) {\n setWeekStart(config.bootData.user.weekStart);\n }\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;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,E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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,6 +1,6 @@
|
|
1
1
|
import { lookupVariable } from '../../variables/lookupVariable.js';
|
2
2
|
import { getTimeRange } from './getTimeRange.js';
|
3
|
-
import { getVariables, getData, getLayout, getDataLayers, interpolate, hasVariableDependencyInLoadingState, findByKey, findByKeyAndType, findObject, findAllObjects, getAncestor, getQueryController } from './sceneGraph.js';
|
3
|
+
import { getVariables, getData, getLayout, getDataLayers, interpolate, hasVariableDependencyInLoadingState, findByKey, findByKeyAndType, findObject, findAllObjects, getAncestor, getQueryController, getUrlSyncManager } from './sceneGraph.js';
|
4
4
|
|
5
5
|
const sceneGraph = {
|
6
6
|
getVariables,
|
@@ -16,7 +16,8 @@ const sceneGraph = {
|
|
16
16
|
findObject,
|
17
17
|
findAllObjects,
|
18
18
|
getAncestor,
|
19
|
-
getQueryController
|
19
|
+
getQueryController,
|
20
|
+
getUrlSyncManager
|
20
21
|
};
|
21
22
|
|
22
23
|
export { sceneGraph };
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/core/sceneGraph/index.ts"],"sourcesContent":["import { lookupVariable } from '../../variables/lookupVariable';\nimport { getTimeRange } from './getTimeRange';\nimport {\n findByKey,\n findByKeyAndType,\n findObject,\n findAllObjects,\n getData,\n getLayout,\n getVariables,\n getDataLayers,\n hasVariableDependencyInLoadingState,\n interpolate,\n getAncestor,\n getQueryController,\n} from './sceneGraph';\n\nexport const sceneGraph = {\n getVariables,\n getData,\n getTimeRange,\n getLayout,\n getDataLayers,\n interpolate,\n lookupVariable,\n hasVariableDependencyInLoadingState,\n findByKey,\n findByKeyAndType,\n findObject,\n findAllObjects,\n getAncestor,\n getQueryController,\n};\n"],"names":[],"mappings":";;;;
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/core/sceneGraph/index.ts"],"sourcesContent":["import { lookupVariable } from '../../variables/lookupVariable';\nimport { getTimeRange } from './getTimeRange';\nimport {\n findByKey,\n findByKeyAndType,\n findObject,\n findAllObjects,\n getData,\n getLayout,\n getVariables,\n getDataLayers,\n hasVariableDependencyInLoadingState,\n interpolate,\n getAncestor,\n getQueryController,\n getUrlSyncManager,\n} from './sceneGraph';\n\nexport const sceneGraph = {\n getVariables,\n getData,\n getTimeRange,\n getLayout,\n getDataLayers,\n interpolate,\n lookupVariable,\n hasVariableDependencyInLoadingState,\n findByKey,\n findByKeyAndType,\n findObject,\n findAllObjects,\n getAncestor,\n getQueryController,\n getUrlSyncManager,\n};\n"],"names":[],"mappings":";;;;AAkBO,MAAM,UAAa,GAAA;AAAA,EACxB,YAAA;AAAA,EACA,OAAA;AAAA,EACA,YAAA;AAAA,EACA,SAAA;AAAA,EACA,aAAA;AAAA,EACA,WAAA;AAAA,EACA,cAAA;AAAA,EACA,mCAAA;AAAA,EACA,SAAA;AAAA,EACA,gBAAA;AAAA,EACA,UAAA;AAAA,EACA,cAAA;AAAA,EACA,WAAA;AAAA,EACA,kBAAA;AAAA,EACA,iBAAA;AACF;;;;"}
|
@@ -156,6 +156,16 @@ function getQueryController(sceneObject) {
|
|
156
156
|
}
|
157
157
|
return void 0;
|
158
158
|
}
|
159
|
+
function getUrlSyncManager(sceneObject) {
|
160
|
+
let parent = sceneObject;
|
161
|
+
while (parent) {
|
162
|
+
if ("urlSyncManager" in parent.state) {
|
163
|
+
return parent.state.urlSyncManager;
|
164
|
+
}
|
165
|
+
parent = parent.parent;
|
166
|
+
}
|
167
|
+
return void 0;
|
168
|
+
}
|
159
169
|
|
160
|
-
export { findAllObjects, findByKey, findByKeyAndType, findObject, getAncestor, getData, getDataLayers, getLayout, getQueryController, getVariables, hasVariableDependencyInLoadingState, interpolate };
|
170
|
+
export { findAllObjects, findByKey, findByKeyAndType, findObject, getAncestor, getData, getDataLayers, getLayout, getQueryController, getUrlSyncManager, getVariables, hasVariableDependencyInLoadingState, interpolate };
|
161
171
|
//# sourceMappingURL=sceneGraph.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"sceneGraph.js","sources":["../../../../src/core/sceneGraph/sceneGraph.ts"],"sourcesContent":["import { ScopedVars } from '@grafana/data';\nimport { EmptyDataNode, EmptyVariableSet } from '../../variables/interpolation/defaults';\n\nimport { sceneInterpolator } from '../../variables/interpolation/sceneInterpolator';\nimport { VariableCustomFormatterFn, SceneVariables } from '../../variables/types';\n\nimport { isDataLayer, SceneDataLayerProvider, SceneDataProvider, SceneLayout, SceneObject } from '../types';\nimport { lookupVariable } from '../../variables/lookupVariable';\nimport { getClosest } from './utils';\nimport { SceneQueryControllerLike, isQueryController } from '../../behaviors/SceneQueryController';\nimport { VariableInterpolation } from '@grafana/runtime';\nimport { QueryVariable } from '../../variables/variants/query/QueryVariable';\n\n/**\n * Get the closest node with variables\n */\nexport function getVariables(sceneObject: SceneObject): SceneVariables {\n return getClosest(sceneObject, (s) => s.state.$variables) ?? EmptyVariableSet;\n}\n\n/**\n * Will walk up the scene object graph to the closest $data scene object\n */\nexport function getData(sceneObject: SceneObject): SceneDataProvider {\n return getClosest(sceneObject, (s) => s.state.$data) ?? EmptyDataNode;\n}\n\nfunction isSceneLayout(s: SceneObject): s is SceneLayout {\n return 'isDraggable' in s;\n}\n\n/**\n * Will walk up the scene object graph to the closest $layout scene object\n */\nexport function getLayout(scene: SceneObject): SceneLayout | null {\n const parent = getClosest(scene, (s) => (isSceneLayout(s) ? s : undefined));\n if (parent) {\n return parent;\n }\n\n return null;\n}\n\n/**\n * Interpolates the given string using the current scene object as context. *\n *\n * Note: the interpolations array will be mutated by adding information about variables that\n * have been interpolated during replacement. Variables that were specified in the target but not found in\n * the list of available variables are also added to the array. See {@link VariableInterpolation} for more details.\n *\n * @param {VariableInterpolation[]} interpolations an optional array that is updated with interpolated variables.\n */\nexport function interpolate(\n sceneObject: SceneObject,\n value: string | undefined | null,\n scopedVars?: ScopedVars,\n format?: string | VariableCustomFormatterFn,\n interpolations?: VariableInterpolation[]\n): string {\n if (value === '' || value == null) {\n return '';\n }\n\n return sceneInterpolator(sceneObject, value, scopedVars, format, interpolations);\n}\n\n/**\n * Checks if the variable is currently loading or waiting to update.\n * It also returns true if a dependency of the variable is loading.\n *\n * For example if C depends on variable B which depends on variable A and A is loading this returns true for variable C and B.\n */\nexport function hasVariableDependencyInLoadingState(sceneObject: SceneObject) {\n if (!sceneObject.variableDependency) {\n return false;\n }\n\n for (const name of sceneObject.variableDependency.getNames()) {\n // This is for backwards compability. In the old architecture query variables could reference itself in a query without breaking.\n if (sceneObject instanceof QueryVariable && sceneObject.state.name === name) {\n console.warn('Query variable is referencing itself');\n continue;\n }\n\n const variable = lookupVariable(name, sceneObject);\n if (!variable) {\n continue;\n }\n\n const set = variable.parent as SceneVariables;\n if (set.isVariableLoadingOrWaitingToUpdate(variable)) {\n return true;\n }\n }\n\n return false;\n}\n\nfunction findObjectInternal(\n scene: SceneObject,\n check: (obj: SceneObject) => boolean,\n alreadySearchedChild?: SceneObject,\n shouldSearchUp?: boolean\n): SceneObject | null {\n if (check(scene)) {\n return scene;\n }\n\n let found: SceneObject | null = null;\n\n scene.forEachChild((child) => {\n if (child === alreadySearchedChild) {\n return;\n }\n\n let maybe = findObjectInternal(child, check);\n if (maybe) {\n found = maybe;\n }\n });\n\n if (found) {\n return found;\n }\n\n if (shouldSearchUp && scene.parent) {\n return findObjectInternal(scene.parent, check, scene, true);\n }\n\n return null;\n}\n\n/**\n * Returns a scene object from the scene graph with the requested key.\n *\n * Throws error if no key-matching scene object found.\n */\nexport function findByKey(sceneObject: SceneObject, key: string) {\n const found = findObject(sceneObject, (sceneToCheck) => {\n return sceneToCheck.state.key === key;\n });\n if (!found) {\n throw new Error('Unable to find scene with key ' + key);\n }\n return found;\n}\n\n/**\n * Returns a scene object from the scene graph with the requested key and type.\n *\n * Throws error if no key-matching scene object found.\n * Throws error if the given type does not match.\n */\nexport function findByKeyAndType<TargetType extends SceneObject>(\n sceneObject: SceneObject,\n key: string,\n targetType: { new (...args: never[]): TargetType }\n) {\n const found = findObject(sceneObject, (sceneToCheck) => {\n return sceneToCheck.state.key === key;\n });\n if (!found) {\n throw new Error('Unable to find scene with key ' + key);\n }\n if (!(found instanceof targetType)) {\n throw new Error(`Found scene object with key ${key} does not match type ${targetType.name}`);\n }\n return found;\n}\n\n/**\n * This will search the full scene graph, starting with the scene node passed in, then walking up the parent chain. *\n */\nexport function findObject(scene: SceneObject, check: (obj: SceneObject) => boolean): SceneObject | null {\n return findObjectInternal(scene, check, undefined, true);\n}\n\n/**\n * This will search down the full scene graph, looking for objects that match the provided predicate.\n */\nexport function findAllObjects(scene: SceneObject, check: (obj: SceneObject) => boolean): SceneObject[] {\n const found: SceneObject[] = [];\n\n scene.forEachChild((child) => {\n if (check(child)) {\n found.push(child);\n }\n\n found.push(...findAllObjects(child, check));\n });\n\n return found;\n}\n\n/**\n * Will walk up the scene object graph up until the root and collect all SceneDataLayerProvider objects.\n * When localOnly set to true, it will only collect the closest layers.\n */\nexport function getDataLayers(sceneObject: SceneObject, localOnly = false): SceneDataLayerProvider[] {\n let currentLevel: SceneObject | undefined = sceneObject;\n let collected: SceneDataLayerProvider[] = [];\n\n while (currentLevel) {\n const dataProvider = currentLevel.state.$data;\n if (!dataProvider) {\n currentLevel = currentLevel.parent;\n continue;\n }\n\n // Check if data layer exists nested inside another data provider\n if (isDataLayer(dataProvider)) {\n collected = collected.concat(dataProvider);\n } else {\n if (dataProvider.state.$data && isDataLayer(dataProvider.state.$data)) {\n collected = collected.concat(dataProvider.state.$data);\n }\n }\n\n if (localOnly && collected.length > 0) {\n break;\n }\n\n currentLevel = currentLevel.parent;\n }\n\n return collected;\n}\n\n/**\n * A utility function to find the closest ancestor of a given type. This function expects\n * to find it and will throw an error if it does not.\n */\nexport function getAncestor<ParentType>(\n sceneObject: SceneObject,\n ancestorType: { new (...args: never[]): ParentType }\n): ParentType {\n let parent: SceneObject | undefined = sceneObject;\n\n while (parent) {\n if (parent instanceof ancestorType) {\n return parent;\n }\n parent = parent.parent;\n }\n\n if (!parent) {\n throw new Error('Unable to find parent of type ' + ancestorType.name);\n }\n\n return parent as ParentType;\n}\n\n/**\n * Returns the closest query controller undefined if none found\n */\nexport function getQueryController(sceneObject: SceneObject): SceneQueryControllerLike | undefined {\n let parent: SceneObject | undefined = sceneObject;\n\n while (parent) {\n if (parent.state.$behaviors) {\n for (const behavior of parent.state.$behaviors) {\n if (isQueryController(behavior)) {\n return behavior;\n }\n }\n }\n parent = parent.parent;\n }\n\n return undefined;\n}\n"],"names":[],"mappings":";;;;;;;;AAgBO,SAAS,aAAa,WAA0C,EAAA;AAhBvE,EAAA,IAAA,EAAA,CAAA;AAiBE,EAAO,OAAA,CAAA,EAAA,GAAA,UAAA,CAAW,aAAa,CAAC,CAAA,KAAM,EAAE,KAAM,CAAA,UAAU,MAA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AAA;AAAA,KACT;AACA,IAAA,MAAA,GAAS,MAAO,CAAA,MAAA,CAAA;AAAA,GAClB;AAEA,EAAA,IAAI,CAAC,MAAQ,EAAA;AACX,IAAA,MAAM,IAAI,KAAA,CAAM,gCAAmC,GAAA,YAAA,CAAa,IAAI,CAAA,CAAA;AAAA,GACtE;AAEA,EAAO,OAAA,MAAA,CAAA;AACT,CAAA;AAKO,SAAS,mBAAmB,WAAgE,EAAA;AACjG,EAAA,IAAI,MAAkC,GAAA,WAAA,CAAA;AAEtC,EAAA,OAAO,MAAQ,EAAA;AACb,IAAI,IAAA,MAAA,CAAO,MAAM,UAAY,EAAA;AAC3B,MAAW,KAAA,MAAA,QAAA,IAAY,MAAO,CAAA,KAAA,CAAM,UAAY,EAAA;AAC9C,QAAI,IAAA,iBAAA,CAAkB,QAAQ,CAAG,EAAA;AAC/B,UAAO,OAAA,QAAA,CAAA;AAAA,SACT;AAAA,OACF;AAAA,KACF;AACA,IAAA,MAAA,GAAS,MAAO,CAAA,MAAA,CAAA;AAAA,GAClB;AAEA,EAAO,OAAA,KAAA,CAAA,CAAA;AACT;;;;"}
|
1
|
+
{"version":3,"file":"sceneGraph.js","sources":["../../../../src/core/sceneGraph/sceneGraph.ts"],"sourcesContent":["import { ScopedVars } from '@grafana/data';\nimport { EmptyDataNode, EmptyVariableSet } from '../../variables/interpolation/defaults';\n\nimport { sceneInterpolator } from '../../variables/interpolation/sceneInterpolator';\nimport { VariableCustomFormatterFn, SceneVariables } from '../../variables/types';\n\nimport { isDataLayer, SceneDataLayerProvider, SceneDataProvider, SceneLayout, SceneObject } from '../types';\nimport { lookupVariable } from '../../variables/lookupVariable';\nimport { getClosest } from './utils';\nimport { SceneQueryControllerLike, isQueryController } from '../../behaviors/SceneQueryController';\nimport { VariableInterpolation } from '@grafana/runtime';\nimport { QueryVariable } from '../../variables/variants/query/QueryVariable';\nimport { UrlSyncManagerLike } from '../../services/UrlSyncManager';\n\n/**\n * Get the closest node with variables\n */\nexport function getVariables(sceneObject: SceneObject): SceneVariables {\n return getClosest(sceneObject, (s) => s.state.$variables) ?? EmptyVariableSet;\n}\n\n/**\n * Will walk up the scene object graph to the closest $data scene object\n */\nexport function getData(sceneObject: SceneObject): SceneDataProvider {\n return getClosest(sceneObject, (s) => s.state.$data) ?? EmptyDataNode;\n}\n\nfunction isSceneLayout(s: SceneObject): s is SceneLayout {\n return 'isDraggable' in s;\n}\n\n/**\n * Will walk up the scene object graph to the closest $layout scene object\n */\nexport function getLayout(scene: SceneObject): SceneLayout | null {\n const parent = getClosest(scene, (s) => (isSceneLayout(s) ? s : undefined));\n if (parent) {\n return parent;\n }\n\n return null;\n}\n\n/**\n * Interpolates the given string using the current scene object as context. *\n *\n * Note: the interpolations array will be mutated by adding information about variables that\n * have been interpolated during replacement. Variables that were specified in the target but not found in\n * the list of available variables are also added to the array. See {@link VariableInterpolation} for more details.\n *\n * @param {VariableInterpolation[]} interpolations an optional array that is updated with interpolated variables.\n */\nexport function interpolate(\n sceneObject: SceneObject,\n value: string | undefined | null,\n scopedVars?: ScopedVars,\n format?: string | VariableCustomFormatterFn,\n interpolations?: VariableInterpolation[]\n): string {\n if (value === '' || value == null) {\n return '';\n }\n\n return sceneInterpolator(sceneObject, value, scopedVars, format, interpolations);\n}\n\n/**\n * Checks if the variable is currently loading or waiting to update.\n * It also returns true if a dependency of the variable is loading.\n *\n * For example if C depends on variable B which depends on variable A and A is loading this returns true for variable C and B.\n */\nexport function hasVariableDependencyInLoadingState(sceneObject: SceneObject) {\n if (!sceneObject.variableDependency) {\n return false;\n }\n\n for (const name of sceneObject.variableDependency.getNames()) {\n // This is for backwards compability. In the old architecture query variables could reference itself in a query without breaking.\n if (sceneObject instanceof QueryVariable && sceneObject.state.name === name) {\n console.warn('Query variable is referencing itself');\n continue;\n }\n\n const variable = lookupVariable(name, sceneObject);\n if (!variable) {\n continue;\n }\n\n const set = variable.parent as SceneVariables;\n if (set.isVariableLoadingOrWaitingToUpdate(variable)) {\n return true;\n }\n }\n\n return false;\n}\n\nfunction findObjectInternal(\n scene: SceneObject,\n check: (obj: SceneObject) => boolean,\n alreadySearchedChild?: SceneObject,\n shouldSearchUp?: boolean\n): SceneObject | null {\n if (check(scene)) {\n return scene;\n }\n\n let found: SceneObject | null = null;\n\n scene.forEachChild((child) => {\n if (child === alreadySearchedChild) {\n return;\n }\n\n let maybe = findObjectInternal(child, check);\n if (maybe) {\n found = maybe;\n }\n });\n\n if (found) {\n return found;\n }\n\n if (shouldSearchUp && scene.parent) {\n return findObjectInternal(scene.parent, check, scene, true);\n }\n\n return null;\n}\n\n/**\n * Returns a scene object from the scene graph with the requested key.\n *\n * Throws error if no key-matching scene object found.\n */\nexport function findByKey(sceneObject: SceneObject, key: string) {\n const found = findObject(sceneObject, (sceneToCheck) => {\n return sceneToCheck.state.key === key;\n });\n if (!found) {\n throw new Error('Unable to find scene with key ' + key);\n }\n return found;\n}\n\n/**\n * Returns a scene object from the scene graph with the requested key and type.\n *\n * Throws error if no key-matching scene object found.\n * Throws error if the given type does not match.\n */\nexport function findByKeyAndType<TargetType extends SceneObject>(\n sceneObject: SceneObject,\n key: string,\n targetType: { new (...args: never[]): TargetType }\n) {\n const found = findObject(sceneObject, (sceneToCheck) => {\n return sceneToCheck.state.key === key;\n });\n if (!found) {\n throw new Error('Unable to find scene with key ' + key);\n }\n if (!(found instanceof targetType)) {\n throw new Error(`Found scene object with key ${key} does not match type ${targetType.name}`);\n }\n return found;\n}\n\n/**\n * This will search the full scene graph, starting with the scene node passed in, then walking up the parent chain. *\n */\nexport function findObject(scene: SceneObject, check: (obj: SceneObject) => boolean): SceneObject | null {\n return findObjectInternal(scene, check, undefined, true);\n}\n\n/**\n * This will search down the full scene graph, looking for objects that match the provided predicate.\n */\nexport function findAllObjects(scene: SceneObject, check: (obj: SceneObject) => boolean): SceneObject[] {\n const found: SceneObject[] = [];\n\n scene.forEachChild((child) => {\n if (check(child)) {\n found.push(child);\n }\n\n found.push(...findAllObjects(child, check));\n });\n\n return found;\n}\n\n/**\n * Will walk up the scene object graph up until the root and collect all SceneDataLayerProvider objects.\n * When localOnly set to true, it will only collect the closest layers.\n */\nexport function getDataLayers(sceneObject: SceneObject, localOnly = false): SceneDataLayerProvider[] {\n let currentLevel: SceneObject | undefined = sceneObject;\n let collected: SceneDataLayerProvider[] = [];\n\n while (currentLevel) {\n const dataProvider = currentLevel.state.$data;\n if (!dataProvider) {\n currentLevel = currentLevel.parent;\n continue;\n }\n\n // Check if data layer exists nested inside another data provider\n if (isDataLayer(dataProvider)) {\n collected = collected.concat(dataProvider);\n } else {\n if (dataProvider.state.$data && isDataLayer(dataProvider.state.$data)) {\n collected = collected.concat(dataProvider.state.$data);\n }\n }\n\n if (localOnly && collected.length > 0) {\n break;\n }\n\n currentLevel = currentLevel.parent;\n }\n\n return collected;\n}\n\n/**\n * A utility function to find the closest ancestor of a given type. This function expects\n * to find it and will throw an error if it does not.\n */\nexport function getAncestor<ParentType>(\n sceneObject: SceneObject,\n ancestorType: { new (...args: never[]): ParentType }\n): ParentType {\n let parent: SceneObject | undefined = sceneObject;\n\n while (parent) {\n if (parent instanceof ancestorType) {\n return parent;\n }\n parent = parent.parent;\n }\n\n if (!parent) {\n throw new Error('Unable to find parent of type ' + ancestorType.name);\n }\n\n return parent as ParentType;\n}\n\n/**\n * Returns the closest query controller undefined if none found\n */\nexport function getQueryController(sceneObject: SceneObject): SceneQueryControllerLike | undefined {\n let parent: SceneObject | undefined = sceneObject;\n\n while (parent) {\n if (parent.state.$behaviors) {\n for (const behavior of parent.state.$behaviors) {\n if (isQueryController(behavior)) {\n return behavior;\n }\n }\n }\n parent = parent.parent;\n }\n\n return undefined;\n}\n\n/**\n * Returns the closest SceneObject that has a state property with the\n * name urlSyncManager that is of type UrlSyncManager\n */\nexport function getUrlSyncManager(sceneObject: SceneObject): UrlSyncManagerLike | undefined {\n let parent: SceneObject | undefined = sceneObject;\n\n while (parent) {\n if ('urlSyncManager' in parent.state) {\n return parent.state.urlSyncManager as Url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KAAA,CAAA,CAAA;AACT;;;;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.js","sources":["../../../src/core/types.ts"],"sourcesContent":["import React from 'react';\nimport { MonoTypeOperatorFunction, Observable, Unsubscribable } from 'rxjs';\n\nimport {\n BusEvent,\n BusEventHandler,\n BusEventType,\n DataFrame,\n DataQueryRequest,\n DataSourceGetTagKeysOptions,\n DataSourceGetTagValuesOptions,\n DataTransformContext,\n PanelData,\n TimeRange,\n} from '@grafana/data';\nimport { DataQuery, DataTopic, TimeZone } from '@grafana/schema';\n\nimport { SceneVariableDependencyConfigLike, SceneVariables } from '../variables/types';\nimport { SceneObjectRef } from './SceneObjectRef';\n\nexport interface SceneObjectState {\n key?: string;\n $timeRange?: SceneTimeRangeLike;\n $data?: SceneDataProvider;\n $variables?: SceneVariables;\n /**\n * @experimental\n * Can be used to add extra behaviors to a scene object.\n * These are activated when the their parent scene object is activated.\n */\n $behaviors?: Array<SceneObject | SceneStatelessBehavior>;\n}\n\nexport interface SceneLayoutChildOptions {\n width?: number | string;\n height?: number | string;\n xSizing?: 'fill' | 'content';\n ySizing?: 'fill' | 'content';\n x?: number;\n y?: number;\n minWidth?: number | string;\n minHeight?: number | string;\n isDraggable?: boolean;\n isResizable?: boolean;\n}\n\nexport interface SceneComponentProps<T> {\n model: T;\n}\n\nexport type SceneComponent<TModel> = (props: SceneComponentProps<TModel>) => React.ReactElement | null;\n\nexport interface SceneDataState extends SceneObjectState {\n data?: PanelData;\n}\n\nexport interface SceneObject<TState extends SceneObjectState = SceneObjectState> {\n /** The current state */\n readonly state: TState;\n\n /** True when there is a React component mounted for this Object */\n readonly isActive: boolean;\n\n /** SceneObject parent */\n readonly parent?: SceneObject;\n\n /** This abtractions declares what variables the scene object depends on and how to handle when they change value. **/\n readonly variableDependency?: SceneVariableDependencyConfigLike;\n\n /** This abstraction declares URL sync dependencies of a scene object. **/\n readonly urlSync?: SceneObjectUrlSyncHandler;\n\n /** Subscribe to state changes */\n subscribeToState(handler: SceneStateChangedHandler<TState>): Unsubscribable;\n\n /** Subscribe to a scene event */\n subscribeToEvent<T extends BusEvent>(typeFilter: BusEventType<T>, handler: BusEventHandler<T>): Unsubscribable;\n\n /** Publish an event and optionally bubble it up the scene */\n publishEvent(event: BusEvent, bubble?: boolean): void;\n\n /** Utility hook that wraps useObservable. Used by React components to subscribes to state changes */\n useState(): TState;\n\n /** How to modify state */\n setState(state: Partial<TState>): void;\n\n /**\n * Called when the Component is mounted. This will also activate any $data, $variables or $timeRange scene object on this level.\n * Don't override this in your custom SceneObjects, instead use addActivationHandler from the constructor.\n **/\n activate(): CancelActivationHandler;\n\n /** Get the scene root */\n getRoot(): SceneObject;\n\n /** Returns a deep clone this object and all its children */\n clone(state?: Partial<TState>): this;\n\n /** A React component to use for rendering the object */\n Component(props: SceneComponentProps<SceneObject<TState>>): React.ReactElement | null;\n\n /** Force a re-render, should only be needed when variable values change */\n forceRender(): void;\n\n /** Returns a SceneObjectRef that will resolve to this object */\n getRef(): SceneObjectRef<this>;\n\n /**\n * Allows external code to register code that is executed on activate and deactivate. This allow you\n * to wire up scene objects that need to respond to state changes in other objects from the outside.\n **/\n addActivationHandler(handler: SceneActivationHandler): void;\n\n /**\n * Loop through state and call callback for each direct child scene object.\n * Checks 1 level deep properties and arrays. So a scene object hidden in a nested plain object will not be detected.\n */\n forEachChild(callback: (child: SceneObject) => void): void;\n}\n\nexport type SceneActivationHandler = () => SceneDeactivationHandler | void;\nexport type SceneDeactivationHandler = () => void;\n\n/**\n * Function returned by activate() that when called will deactivate the object if it's the last activator\n **/\nexport type CancelActivationHandler = () => void;\n\nexport interface SceneLayoutState extends SceneObjectState {\n children: SceneObject[];\n}\n\nexport interface SceneLayout<T extends SceneLayoutState = SceneLayoutState> extends SceneObject<T> {\n isDraggable(): boolean;\n getDragClass?(): string;\n getDragClassCancel?(): string;\n}\n\nexport interface SceneTimeRangeState extends SceneObjectState {\n from: string;\n to: string;\n fiscalYearStartMonth?: number;\n value: TimeRange;\n timeZone?: TimeZone;\n /** weekStart will change the global date locale so having multiple different weekStart values is not supported */\n weekStart?: string;\n /**\n * @internal\n * To enable feature parity with the old time range picker, not sure if it will be kept.\n * Override the now time by entering a time delay. Use this option to accommodate known delays in data aggregation to avoid null values.\n * */\n UNSAFE_nowDelay?: string;\n\n refreshOnActivate?: {\n /**\n * When set, the time range will invalidate relative ranges after the specified interval has elapsed\n */\n afterMs?: number;\n /**\n * When set, the time range will invalidate relative ranges after the specified percentage of the current interval has elapsed.\n * If both invalidate values are set, the smaller value will be used for the given interval.\n */\n percent?: number;\n };\n}\n\nexport interface SceneTimeRangeLike extends SceneObject<SceneTimeRangeState> {\n onTimeZoneChange(timeZone: TimeZone): void;\n onTimeRangeChange(timeRange: TimeRange): void;\n onRefresh(): void;\n getTimeZone(): TimeZone;\n}\n\nexport function isSceneObject(obj: any): obj is SceneObject {\n return obj.useState !== undefined;\n}\n\nexport interface SceneObjectWithUrlSync extends SceneObject {\n getUrlState(): SceneObjectUrlValues;\n updateFromUrl(values: SceneObjectUrlValues): void;\n}\n\nexport interface SceneObjectUrlSyncHandler {\n getKeys(): string[];\n getUrlState(): SceneObjectUrlValues;\n updateFromUrl(values: SceneObjectUrlValues): void;\n}\n\nexport interface DataRequestEnricher {\n // Return partial data query request that will be merged with the original request provided by SceneQueryRunner\n enrichDataRequest(source: SceneObject): Partial<DataQueryRequest> | null;\n}\n\nexport interface FiltersRequestEnricher {\n // Return partial getTagKeys or getTagValues query request that will be merged with the original request provided by ad hoc or group by variable\n enrichFiltersRequest(\n source: SceneObject\n ): Partial<DataSourceGetTagKeysOptions | DataSourceGetTagValuesOptions> | null;\n}\n\nexport function isDataRequestEnricher(obj: any): obj is DataRequestEnricher {\n return 'enrichDataRequest' in obj;\n}\n\nexport function isFiltersRequestEnricher(obj: any): obj is FiltersRequestEnricher {\n return 'enrichFiltersRequest' in obj;\n}\n\nexport type SceneObjectUrlValue = string | string[] | undefined | null;\nexport type SceneObjectUrlValues = Record<string, SceneObjectUrlValue>;\n\nexport type CustomTransformOperator = (context: DataTransformContext) => MonoTypeOperatorFunction<DataFrame[]>;\nexport type CustomTransformerDefinition =\n | { operator: CustomTransformOperator; topic: DataTopic }\n | CustomTransformOperator;\nexport type SceneStateChangedHandler<TState> = (newState: TState, prevState: TState) => void;\n\nexport type DeepPartial<T> = {\n [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K];\n};\n\nexport interface SceneDataProviderResult {\n data: PanelData;\n origin: SceneDataProvider;\n}\n\nexport interface SceneDataProvider<T extends SceneObjectState = SceneDataState> extends SceneObject<T> {\n setContainerWidth?: (width: number) => void;\n isDataReadyToDisplay?: () => boolean;\n cancelQuery?: () => void;\n getResultsStream(): Observable<SceneDataProviderResult>;\n}\n\nexport interface SceneDataLayerProviderState extends SceneDataState {\n name: string;\n description?: string;\n isEnabled?: boolean;\n isHidden?: boolean;\n}\n\nexport interface SceneDataLayerProvider extends SceneDataProvider<SceneDataLayerProviderState> {\n isDataLayer: true;\n}\n\nexport function isDataLayer(obj: SceneObject): obj is SceneDataLayerProvider {\n return 'isDataLayer' in obj;\n}\n\nexport interface DataLayerFilter {\n panelId: number;\n}\n\nexport interface SceneStatelessBehavior<T extends SceneObject = any> {\n (sceneObject: T): CancelActivationHandler | void;\n}\n\nexport type ControlsLayout = 'horizontal' | 'vertical';\n\nexport interface UseStateHookOptions {\n /**\n * For some edge cases other scene objects want to subscribe to scene object state for objects\n * that are not active, or whose main React Component can be un-mounted. Set this to true\n * to keep the scene object active even if the React component is unmounted.\n *\n * Normally you would not need this but this can be useful in some edge cases.\n *\n * @experimental\n */\n shouldActivateOrKeepAlive?: boolean;\n}\n\nexport interface SceneDataQuery extends DataQuery {\n [key: string]: any;\n\n // Opt this query out of time window comparison\n timeRangeCompare?: boolean;\n}\n"],"names":[],"mappings":"AA8KO,SAAS,cAAc,GAA8B,EAAA;AAC1D,EAAA,OAAO,IAAI,QAAa,KAAA,KAAA,CAAA,CAAA;AAC1B,CAAA;AAyBO,SAAS,sBAAsB,GAAsC,EAAA;AAC1E,EAAA,OAAO,mBAAuB,IAAA,GAAA,CAAA;AAChC,CAAA;AAEO,SAAS,yBAAyB,GAAyC,EAAA;AAChF,EAAA,OAAO,sBAA0B,IAAA,GAAA,CAAA;AACnC,CAAA;AAsCO,SAAS,YAAY,GAAiD,EAAA;AAC3E,EAAA,OAAO,aAAiB,IAAA,GAAA,CAAA;AAC1B;;;;"}
|
1
|
+
{"version":3,"file":"types.js","sources":["../../../src/core/types.ts"],"sourcesContent":["import React from 'react';\nimport { MonoTypeOperatorFunction, Observable, Unsubscribable } from 'rxjs';\n\nimport {\n BusEvent,\n BusEventHandler,\n BusEventType,\n DataFrame,\n DataQueryRequest,\n DataSourceGetTagKeysOptions,\n DataSourceGetTagValuesOptions,\n DataTransformContext,\n PanelData,\n TimeRange,\n} from '@grafana/data';\nimport { DataQuery, DataTopic, TimeZone } from '@grafana/schema';\n\nimport { SceneVariableDependencyConfigLike, SceneVariables } from '../variables/types';\nimport { SceneObjectRef } from './SceneObjectRef';\n\nexport interface SceneObjectState {\n key?: string;\n $timeRange?: SceneTimeRangeLike;\n $data?: SceneDataProvider;\n $variables?: SceneVariables;\n /**\n * @experimental\n * Can be used to add extra behaviors to a scene object.\n * These are activated when the their parent scene object is activated.\n */\n $behaviors?: Array<SceneObject | SceneStatelessBehavior>;\n}\n\nexport interface SceneLayoutChildOptions {\n width?: number | string;\n height?: number | string;\n xSizing?: 'fill' | 'content';\n ySizing?: 'fill' | 'content';\n x?: number;\n y?: number;\n minWidth?: number | string;\n minHeight?: number | string;\n isDraggable?: boolean;\n isResizable?: boolean;\n}\n\nexport interface SceneComponentProps<T> {\n model: T;\n}\n\nexport type SceneComponent<TModel> = (props: SceneComponentProps<TModel>) => React.ReactElement | null;\n\nexport interface SceneDataState extends SceneObjectState {\n data?: PanelData;\n}\n\nexport interface SceneObject<TState extends SceneObjectState = SceneObjectState> {\n /** The current state */\n readonly state: TState;\n\n /** True when there is a React component mounted for this Object */\n readonly isActive: boolean;\n\n /** SceneObject parent */\n readonly parent?: SceneObject;\n\n /** This abtractions declares what variables the scene object depends on and how to handle when they change value. **/\n readonly variableDependency?: SceneVariableDependencyConfigLike;\n\n /** This abstraction declares URL sync dependencies of a scene object. **/\n readonly urlSync?: SceneObjectUrlSyncHandler;\n\n /** Subscribe to state changes */\n subscribeToState(handler: SceneStateChangedHandler<TState>): Unsubscribable;\n\n /** Subscribe to a scene event */\n subscribeToEvent<T extends BusEvent>(typeFilter: BusEventType<T>, handler: BusEventHandler<T>): Unsubscribable;\n\n /** Publish an event and optionally bubble it up the scene */\n publishEvent(event: BusEvent, bubble?: boolean): void;\n\n /** Utility hook that wraps useObservable. Used by React components to subscribes to state changes */\n useState(): TState;\n\n /** How to modify state */\n setState(state: Partial<TState>): void;\n\n /**\n * Called when the Component is mounted. This will also activate any $data, $variables or $timeRange scene object on this level.\n * Don't override this in your custom SceneObjects, instead use addActivationHandler from the constructor.\n **/\n activate(): CancelActivationHandler;\n\n /** Get the scene root */\n getRoot(): SceneObject;\n\n /** Returns a deep clone this object and all its children */\n clone(state?: Partial<TState>): this;\n\n /** A React component to use for rendering the object */\n Component(props: SceneComponentProps<SceneObject<TState>>): React.ReactElement | null;\n\n /** Force a re-render, should only be needed when variable values change */\n forceRender(): void;\n\n /** Returns a SceneObjectRef that will resolve to this object */\n getRef(): SceneObjectRef<this>;\n\n /**\n * Allows external code to register code that is executed on activate and deactivate. This allow you\n * to wire up scene objects that need to respond to state changes in other objects from the outside.\n **/\n addActivationHandler(handler: SceneActivationHandler): void;\n\n /**\n * Loop through state and call callback for each direct child scene object.\n * Checks 1 level deep properties and arrays. So a scene object hidden in a nested plain object will not be detected.\n */\n forEachChild(callback: (child: SceneObject) => void): void;\n}\n\nexport type SceneActivationHandler = () => SceneDeactivationHandler | void;\nexport type SceneDeactivationHandler = () => void;\n\n/**\n * Function returned by activate() that when called will deactivate the object if it's the last activator\n **/\nexport type CancelActivationHandler = () => void;\n\nexport interface SceneLayoutState extends SceneObjectState {\n children: SceneObject[];\n}\n\nexport interface SceneLayout<T extends SceneLayoutState = SceneLayoutState> extends SceneObject<T> {\n isDraggable(): boolean;\n getDragClass?(): string;\n getDragClassCancel?(): string;\n}\n\nexport interface SceneTimeRangeState extends SceneObjectState {\n from: string;\n to: string;\n fiscalYearStartMonth?: number;\n value: TimeRange;\n timeZone?: TimeZone;\n /** weekStart will change the global date locale so having multiple different weekStart values is not supported */\n weekStart?: string;\n /**\n * @internal\n * To enable feature parity with the old time range picker, not sure if it will be kept.\n * Override the now time by entering a time delay. Use this option to accommodate known delays in data aggregation to avoid null values.\n * */\n UNSAFE_nowDelay?: string;\n\n refreshOnActivate?: {\n /**\n * When set, the time range will invalidate relative ranges after the specified interval has elapsed\n */\n afterMs?: number;\n /**\n * When set, the time range will invalidate relative ranges after the specified percentage of the current interval has elapsed.\n * If both invalidate values are set, the smaller value will be used for the given interval.\n */\n percent?: number;\n };\n}\n\nexport interface SceneTimeRangeLike extends SceneObject<SceneTimeRangeState> {\n onTimeZoneChange(timeZone: TimeZone): void;\n onTimeRangeChange(timeRange: TimeRange): void;\n onRefresh(): void;\n getTimeZone(): TimeZone;\n}\n\nexport function isSceneObject(obj: any): obj is SceneObject {\n return obj.useState !== undefined;\n}\n\nexport interface SceneObjectWithUrlSync extends SceneObject {\n getUrlState(): SceneObjectUrlValues;\n updateFromUrl(values: SceneObjectUrlValues): void;\n shouldCreateHistoryStep?(values: SceneObjectUrlValues): boolean;\n}\n\nexport interface SceneObjectUrlSyncHandler {\n getKeys(): string[];\n getUrlState(): SceneObjectUrlValues;\n updateFromUrl(values: SceneObjectUrlValues): void;\n shouldCreateHistoryStep?(values: SceneObjectUrlValues): boolean;\n}\n\nexport interface DataRequestEnricher {\n // Return partial data query request that will be merged with the original request provided by SceneQueryRunner\n enrichDataRequest(source: SceneObject): Partial<DataQueryRequest> | null;\n}\n\nexport interface FiltersRequestEnricher {\n // Return partial getTagKeys or getTagValues query request that will be merged with the original request provided by ad hoc or group by variable\n enrichFiltersRequest(\n source: SceneObject\n ): Partial<DataSourceGetTagKeysOptions | DataSourceGetTagValuesOptions> | null;\n}\n\nexport function isDataRequestEnricher(obj: any): obj is DataRequestEnricher {\n return 'enrichDataRequest' in obj;\n}\n\nexport function isFiltersRequestEnricher(obj: any): obj is FiltersRequestEnricher {\n return 'enrichFiltersRequest' in obj;\n}\n\nexport type SceneObjectUrlValue = string | string[] | undefined | null;\nexport type SceneObjectUrlValues = Record<string, SceneObjectUrlValue>;\n\nexport type CustomTransformOperator = (context: DataTransformContext) => MonoTypeOperatorFunction<DataFrame[]>;\nexport type CustomTransformerDefinition =\n | { operator: CustomTransformOperator; topic: DataTopic }\n | CustomTransformOperator;\nexport type SceneStateChangedHandler<TState> = (newState: TState, prevState: TState) => void;\n\nexport type DeepPartial<T> = {\n [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K];\n};\n\nexport interface SceneDataProviderResult {\n data: PanelData;\n origin: SceneDataProvider;\n}\n\nexport interface SceneDataProvider<T extends SceneObjectState = SceneDataState> extends SceneObject<T> {\n setContainerWidth?: (width: number) => void;\n isDataReadyToDisplay?: () => boolean;\n cancelQuery?: () => void;\n getResultsStream(): Observable<SceneDataProviderResult>;\n}\n\nexport interface SceneDataLayerProviderState extends SceneDataState {\n name: string;\n description?: string;\n isEnabled?: boolean;\n isHidden?: boolean;\n}\n\nexport interface SceneDataLayerProvider extends SceneDataProvider<SceneDataLayerProviderState> {\n isDataLayer: true;\n}\n\nexport function isDataLayer(obj: SceneObject): obj is SceneDataLayerProvider {\n return 'isDataLayer' in obj;\n}\n\nexport interface DataLayerFilter {\n panelId: number;\n}\n\nexport interface SceneStatelessBehavior<T extends SceneObject = any> {\n (sceneObject: T): CancelActivationHandler | void;\n}\n\nexport type ControlsLayout = 'horizontal' | 'vertical';\n\nexport interface UseStateHookOptions {\n /**\n * For some edge cases other scene objects want to subscribe to scene object state for objects\n * that are not active, or whose main React Component can be un-mounted. Set this to true\n * to keep the scene object active even if the React component is unmounted.\n *\n * Normally you would not need this but this can be useful in some edge cases.\n *\n * @experimental\n */\n shouldActivateOrKeepAlive?: boolean;\n}\n\nexport interface SceneDataQuery extends DataQuery {\n [key: string]: any;\n\n // Opt this query out of time window comparison\n timeRangeCompare?: boolean;\n}\n\nexport interface SceneUrlSyncOptions {\n /**\n * This will update the url to contain all scene url state\n * when the scene is initialized. Important for browser history \"back\" actions.\n */\n updateUrlOnInit?: boolean;\n /**\n * This is only supported by some objects if they implement\n * shouldCreateHistoryStep where they can control what changes\n * url changes should add a new browser history entry.\n */\n createBrowserHistorySteps?: boolean;\n}\n"],"names":[],"mappings":"AA8KO,SAAS,cAAc,GAA8B,EAAA;AAC1D,EAAA,OAAO,IAAI,QAAa,KAAA,KAAA,CAAA,CAAA;AAC1B,CAAA;AA2BO,SAAS,sBAAsB,GAAsC,EAAA;AAC1E,EAAA,OAAO,mBAAuB,IAAA,GAAA,CAAA;AAChC,CAAA;AAEO,SAAS,yBAAyB,GAAyC,EAAA;AAChF,EAAA,OAAO,sBAA0B,IAAA,GAAA,CAAA;AACnC,CAAA;AAsCO,SAAS,YAAY,GAAiD,EAAA;AAC3E,EAAA,OAAO,aAAiB,IAAA,GAAA,CAAA;AAC1B;;;;"}
|
package/dist/esm/index.js
CHANGED
@@ -41,7 +41,7 @@ export { LocalValueVariable } from './variables/variants/LocalValueVariable.js';
|
|
41
41
|
export { IntervalVariable } from './variables/variants/IntervalVariable.js';
|
42
42
|
export { AdHocFiltersVariable } from './variables/adhoc/AdHocFiltersVariable.js';
|
43
43
|
export { GroupByVariable } from './variables/groupby/GroupByVariable.js';
|
44
|
-
export {
|
44
|
+
export { NewSceneObjectAddedEvent, UrlSyncManager } from './services/UrlSyncManager.js';
|
45
45
|
export { useUrlSync } from './services/useUrlSync.js';
|
46
46
|
export { UrlSyncContextProvider } from './services/UrlSyncContextProvider.js';
|
47
47
|
export { SceneObjectUrlSyncConfig } from './services/SceneObjectUrlSyncConfig.js';
|
package/dist/esm/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["import { getUrlWithAppState } from './components/SceneApp/utils';\nimport { registerRuntimePanelPlugin } from './components/VizPanel/registerRuntimePanelPlugin';\nimport { cloneSceneObjectState } from './core/sceneGraph/utils';\nimport { registerRuntimeDataSource } from './querying/RuntimeDataSource';\nimport { getUrlState, syncStateFromSearchParams } from './services/utils';\n\nimport { registerVariableMacro } from './variables/macros';\nimport { renderPrometheusLabelFilters } from './variables/utils';\nimport {\n isAdHocVariable,\n isQueryVariable,\n isTextBoxVariable,\n isCustomVariable,\n isDataSourceVariable,\n isConstantVariable,\n isIntervalVariable,\n isGroupByVariable,\n} from './variables/variants/guards';\n\nexport * from './core/types';\nexport * from './core/events';\nexport { sceneGraph } from './core/sceneGraph';\nexport * as behaviors from './behaviors';\nexport * as dataLayers from './querying/layers';\n\nexport { SceneObjectBase, useSceneObjectState } from './core/SceneObjectBase';\nexport { SceneDataNode } from './core/SceneDataNode';\nexport { SceneTimeRange } from './core/SceneTimeRange';\nexport { SceneTimeZoneOverride } from './core/SceneTimeZoneOverride';\n\nexport { SceneQueryRunner, type QueryRunnerState } from './querying/SceneQueryRunner';\nexport {\n type ExtraQueryDescriptor,\n type ExtraQueryProvider,\n type ExtraQueryDataProcessor,\n} from './querying/ExtraQueryProvider';\nexport { SceneDataLayerSet, SceneDataLayerSetBase } from './querying/SceneDataLayerSet';\nexport { SceneDataLayerBase } from './querying/layers/SceneDataLayerBase';\nexport { SceneDataLayerControls } from './querying/layers/SceneDataLayerControls';\nexport { SceneDataTransformer } from './querying/SceneDataTransformer';\nexport { registerQueryWithController } from './querying/registerQueryWithController';\nexport { registerRuntimeDataSource, RuntimeDataSource } from './querying/RuntimeDataSource';\nexport type {\n SceneQueryControllerLike,\n SceneQueryControllerEntryType,\n SceneQueryControllerEntry,\n} from './behaviors/SceneQueryController';\n\nexport * from './variables/types';\nexport { VariableDependencyConfig } from './variables/VariableDependencyConfig';\nexport { formatRegistry, type FormatVariable } from './variables/interpolation/formatRegistry';\nexport { VariableValueSelectors } from './variables/components/VariableValueSelectors';\nexport { VariableValueControl } from './variables/components/VariableValueControl';\nexport { SceneVariableSet } from './variables/sets/SceneVariableSet';\nexport { ConstantVariable } from './variables/variants/ConstantVariable';\nexport { CustomVariable } from './variables/variants/CustomVariable';\nexport { DataSourceVariable } from './variables/variants/DataSourceVariable';\nexport { QueryVariable } from './variables/variants/query/QueryVariable';\nexport { TestVariable } from './variables/variants/TestVariable';\nexport { TextBoxVariable } from './variables/variants/TextBoxVariable';\nexport {\n MultiValueVariable,\n type MultiValueVariableState,\n type VariableGetOptionsArgs,\n} from './variables/variants/MultiValueVariable';\nexport { LocalValueVariable } from './variables/variants/LocalValueVariable';\nexport { IntervalVariable } from './variables/variants/IntervalVariable';\nexport { AdHocFiltersVariable } from './variables/adhoc/AdHocFiltersVariable';\nexport { GroupByVariable } from './variables/groupby/GroupByVariable';\nexport { type MacroVariableConstructor } from './variables/macros/types';\n\nexport { type UrlSyncManagerLike, UrlSyncManager,
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["import { getUrlWithAppState } from './components/SceneApp/utils';\nimport { registerRuntimePanelPlugin } from './components/VizPanel/registerRuntimePanelPlugin';\nimport { cloneSceneObjectState } from './core/sceneGraph/utils';\nimport { registerRuntimeDataSource } from './querying/RuntimeDataSource';\nimport { getUrlState, syncStateFromSearchParams } from './services/utils';\n\nimport { registerVariableMacro } from './variables/macros';\nimport { renderPrometheusLabelFilters } from './variables/utils';\nimport {\n isAdHocVariable,\n isQueryVariable,\n isTextBoxVariable,\n isCustomVariable,\n isDataSourceVariable,\n isConstantVariable,\n isIntervalVariable,\n isGroupByVariable,\n} from './variables/variants/guards';\n\nexport * from './core/types';\nexport * from './core/events';\nexport { sceneGraph } from './core/sceneGraph';\nexport * as behaviors from './behaviors';\nexport * as dataLayers from './querying/layers';\n\nexport { SceneObjectBase, useSceneObjectState } from './core/SceneObjectBase';\nexport { SceneDataNode } from './core/SceneDataNode';\nexport { SceneTimeRange } from './core/SceneTimeRange';\nexport { SceneTimeZoneOverride } from './core/SceneTimeZoneOverride';\n\nexport { SceneQueryRunner, type QueryRunnerState } from './querying/SceneQueryRunner';\nexport {\n type ExtraQueryDescriptor,\n type ExtraQueryProvider,\n type ExtraQueryDataProcessor,\n} from './querying/ExtraQueryProvider';\nexport { SceneDataLayerSet, SceneDataLayerSetBase } from './querying/SceneDataLayerSet';\nexport { SceneDataLayerBase } from './querying/layers/SceneDataLayerBase';\nexport { SceneDataLayerControls } from './querying/layers/SceneDataLayerControls';\nexport { SceneDataTransformer, type SceneDataTransformerState } from './querying/SceneDataTransformer';\nexport { registerQueryWithController } from './querying/registerQueryWithController';\nexport { registerRuntimeDataSource, RuntimeDataSource } from './querying/RuntimeDataSource';\nexport type {\n SceneQueryControllerLike,\n SceneQueryControllerEntryType,\n SceneQueryControllerEntry,\n} from './behaviors/SceneQueryController';\n\nexport * from './variables/types';\nexport { VariableDependencyConfig } from './variables/VariableDependencyConfig';\nexport { formatRegistry, type FormatVariable } from './variables/interpolation/formatRegistry';\nexport { VariableValueSelectors } from './variables/components/VariableValueSelectors';\nexport { VariableValueControl } from './variables/components/VariableValueControl';\nexport { SceneVariableSet } from './variables/sets/SceneVariableSet';\nexport { ConstantVariable } from './variables/variants/ConstantVariable';\nexport { CustomVariable } from './variables/variants/CustomVariable';\nexport { DataSourceVariable } from './variables/variants/DataSourceVariable';\nexport { QueryVariable } from './variables/variants/query/QueryVariable';\nexport { TestVariable } from './variables/variants/TestVariable';\nexport { TextBoxVariable } from './variables/variants/TextBoxVariable';\nexport {\n MultiValueVariable,\n type MultiValueVariableState,\n type VariableGetOptionsArgs,\n} from './variables/variants/MultiValueVariable';\nexport { LocalValueVariable } from './variables/variants/LocalValueVariable';\nexport { IntervalVariable } from './variables/variants/IntervalVariable';\nexport { AdHocFiltersVariable } from './variables/adhoc/AdHocFiltersVariable';\nexport { GroupByVariable } from './variables/groupby/GroupByVariable';\nexport { type MacroVariableConstructor } from './variables/macros/types';\n\nexport { type UrlSyncManagerLike, UrlSyncManager, NewSceneObjectAddedEvent } from './services/UrlSyncManager';\nexport { useUrlSync } from './services/useUrlSync';\nexport { UrlSyncContextProvider } from './services/UrlSyncContextProvider';\nexport { SceneObjectUrlSyncConfig } from './services/SceneObjectUrlSyncConfig';\n\nexport { EmbeddedScene, type EmbeddedSceneState } from './components/EmbeddedScene';\nexport { VizPanel, type VizPanelState } from './components/VizPanel/VizPanel';\nexport { VizPanelMenu } from './components/VizPanel/VizPanelMenu';\nexport { NestedScene } from './components/NestedScene';\nexport { SceneCanvasText } from './components/SceneCanvasText';\nexport { SceneToolbarButton, SceneToolbarInput } from './components/SceneToolbarButton';\nexport { SceneTimePicker } from './components/SceneTimePicker';\nexport { SceneRefreshPicker, type SceneRefreshPickerState } from './components/SceneRefreshPicker';\nexport { SceneTimeRangeTransformerBase } from './core/SceneTimeRangeTransformerBase';\nexport { SceneTimeRangeCompare } from './components/SceneTimeRangeCompare';\nexport { SceneByFrameRepeater } from './components/SceneByFrameRepeater';\nexport { SceneByVariableRepeater } from './components/SceneByVariableRepeater';\nexport { SceneControlsSpacer } from './components/SceneControlsSpacer';\nexport {\n SceneFlexLayout,\n SceneFlexItem,\n type SceneFlexItemState,\n type SceneFlexItemLike,\n} from './components/layout/SceneFlexLayout';\nexport { SceneCSSGridLayout, SceneCSSGridItem } from './components/layout/CSSGrid/SceneCSSGridLayout';\nexport { SceneGridLayout } from './components/layout/grid/SceneGridLayout';\nexport { SceneGridItem } from './components/layout/grid/SceneGridItem';\nexport { SceneGridRow } from './components/layout/grid/SceneGridRow';\nexport { type SceneGridItemStateLike, type SceneGridItemLike } from './components/layout/grid/types';\nexport { SplitLayout } from './components/layout/split/SplitLayout';\nexport {\n type SceneAppPageLike,\n type SceneRouteMatch,\n type SceneAppPageState,\n type SceneAppDrilldownView,\n type SceneAppRoute,\n} from './components/SceneApp/types';\nexport { SceneApp, useSceneApp } from './components/SceneApp/SceneApp';\nexport { SceneAppPage } from './components/SceneApp/SceneAppPage';\nexport { SceneReactObject } from './components/SceneReactObject';\nexport { SceneObjectRef } from './core/SceneObjectRef';\nexport {\n PanelBuilders,\n PanelOptionsBuilders,\n FieldConfigBuilders,\n FieldConfigOverridesBuilder,\n} from './core/PanelBuilders';\nexport { FieldConfigBuilder } from './core/PanelBuilders/FieldConfigBuilder';\nexport { VizPanelBuilder } from './core/PanelBuilders/VizPanelBuilder';\nexport { SceneDebugger } from './components/SceneDebugger/SceneDebugger';\nexport { VariableValueSelectWrapper } from './variables/components/VariableValueSelectors';\nexport { renderSelectForVariable } from './variables/components/VariableValueSelect';\nexport { VizConfigBuilder } from './core/PanelBuilders/VizConfigBuilder';\nexport { VizConfigBuilders } from './core/PanelBuilders/VizConfigBuilders';\nexport { type VizConfig } from './core/PanelBuilders/types';\n\nexport const sceneUtils = {\n getUrlWithAppState,\n registerRuntimePanelPlugin,\n registerRuntimeDataSource,\n registerVariableMacro,\n cloneSceneObjectState,\n syncStateFromSearchParams,\n getUrlState,\n renderPrometheusLabelFilters,\n\n // Variable guards\n isAdHocVariable,\n isConstantVariable,\n isCustomVariable,\n isDataSourceVariable,\n isIntervalVariable,\n isQueryVariable,\n isTextBoxVariable,\n isGroupByVariable,\n};\n\nexport { SafeSerializableSceneObject } from './utils/SafeSerializableSceneObject';\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+HO,MAAM,UAAa,GAAA;AAAA,EACxB,kBAAA;AAAA,EACA,0BAAA;AAAA,EACA,yBAAA;AAAA,EACA,qBAAA;AAAA,EACA,qBAAA;AAAA,EACA,yBAAA;AAAA,EACA,WAAA;AAAA,EACA,4BAAA;AAAA,EAGA,eAAA;AAAA,EACA,kBAAA;AAAA,EACA,gBAAA;AAAA,EACA,oBAAA;AAAA,EACA,kBAAA;AAAA,EACA,eAAA;AAAA,EACA,iBAAA;AAAA,EACA,iBAAA;AACF;;;;"}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
class SceneObjectUrlSyncConfig {
|
2
2
|
constructor(_sceneObject, _options) {
|
3
3
|
this._sceneObject = _sceneObject;
|
4
|
+
this._nextChangeShouldAddHistoryStep = false;
|
4
5
|
this._keys = _options.keys;
|
5
6
|
}
|
6
7
|
getKeys() {
|
@@ -15,6 +16,14 @@ class SceneObjectUrlSyncConfig {
|
|
15
16
|
updateFromUrl(values) {
|
16
17
|
this._sceneObject.updateFromUrl(values);
|
17
18
|
}
|
19
|
+
performBrowserHistoryAction(callback) {
|
20
|
+
this._nextChangeShouldAddHistoryStep = true;
|
21
|
+
callback();
|
22
|
+
this._nextChangeShouldAddHistoryStep = false;
|
23
|
+
}
|
24
|
+
shouldCreateHistoryStep(values) {
|
25
|
+
return this._nextChangeShouldAddHistoryStep;
|
26
|
+
}
|
18
27
|
}
|
19
28
|
|
20
29
|
export { SceneObjectUrlSyncConfig };
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"SceneObjectUrlSyncConfig.js","sources":["../../../src/services/SceneObjectUrlSyncConfig.ts"],"sourcesContent":["import { SceneObjectUrlSyncHandler, SceneObjectWithUrlSync, SceneObjectUrlValues } from '../core/types';\n\ninterface SceneObjectUrlSyncConfigOptions {\n keys: string[] | (() => string[]);\n}\n\nexport class SceneObjectUrlSyncConfig implements SceneObjectUrlSyncHandler {\n private _keys: string[] | (() => string[]);\n\n public constructor(private _sceneObject: SceneObjectWithUrlSync, _options: SceneObjectUrlSyncConfigOptions) {\n this._keys = _options.keys;\n }\n\n public getKeys(): string[] {\n if (typeof this._keys === 'function') {\n return this._keys();\n }\n\n return this._keys;\n }\n\n public getUrlState(): SceneObjectUrlValues {\n return this._sceneObject.getUrlState();\n }\n\n public updateFromUrl(values: SceneObjectUrlValues): void {\n this._sceneObject.updateFromUrl(values);\n }\n}\n"],"names":[],"mappings":"AAMO,MAAM,wBAA8D,CAAA;AAAA,
|
1
|
+
{"version":3,"file":"SceneObjectUrlSyncConfig.js","sources":["../../../src/services/SceneObjectUrlSyncConfig.ts"],"sourcesContent":["import { SceneObjectUrlSyncHandler, SceneObjectWithUrlSync, SceneObjectUrlValues } from '../core/types';\n\ninterface SceneObjectUrlSyncConfigOptions {\n keys: string[] | (() => string[]);\n}\n\nexport class SceneObjectUrlSyncConfig implements SceneObjectUrlSyncHandler {\n private _keys: string[] | (() => string[]);\n private _nextChangeShouldAddHistoryStep = false;\n\n public constructor(private _sceneObject: SceneObjectWithUrlSync, _options: SceneObjectUrlSyncConfigOptions) {\n this._keys = _options.keys;\n }\n\n public getKeys(): string[] {\n if (typeof this._keys === 'function') {\n return this._keys();\n }\n\n return this._keys;\n }\n\n public getUrlState(): SceneObjectUrlValues {\n return this._sceneObject.getUrlState();\n }\n\n public updateFromUrl(values: SceneObjectUrlValues): void {\n this._sceneObject.updateFromUrl(values);\n }\n\n public performBrowserHistoryAction(callback: () => void) {\n this._nextChangeShouldAddHistoryStep = true;\n callback();\n this._nextChangeShouldAddHistoryStep = false;\n }\n\n public shouldCreateHistoryStep(values: SceneObjectUrlValues): boolean {\n return this._nextChangeShouldAddHistoryStep;\n }\n}\n"],"names":[],"mappings":"AAMO,MAAM,wBAA8D,CAAA;AAAA,EAIlE,WAAA,CAAoB,cAAsC,QAA2C,EAAA;AAAjF,IAAA,IAAA,CAAA,YAAA,GAAA,YAAA,CAAA;AAF3B,IAAA,IAAA,CAAQ,+BAAkC,GAAA,KAAA,CAAA;AAGxC,IAAA,IAAA,CAAK,QAAQ,QAAS,CAAA,IAAA,CAAA;AAAA,GACxB;AAAA,EAEO,OAAoB,GAAA;AACzB,IAAI,IAAA,OAAO,IAAK,CAAA,KAAA,KAAU,UAAY,EAAA;AACpC,MAAA,OAAO,KAAK,KAAM,EAAA,CAAA;AAAA,KACpB;AAEA,IAAA,OAAO,IAAK,CAAA,KAAA,CAAA;AAAA,GACd;AAAA,EAEO,WAAoC,GAAA;AACzC,IAAO,OAAA,IAAA,CAAK,aAAa,WAAY,EAAA,CAAA;AAAA,GACvC;AAAA,EAEO,cAAc,MAAoC,EAAA;AACvD,IAAK,IAAA,CAAA,YAAA,CAAa,cAAc,MAAM,CAAA,CAAA;AAAA,GACxC;AAAA,EAEO,4BAA4B,QAAsB,EAAA;AACvD,IAAA,IAAA,CAAK,+BAAkC,GAAA,IAAA,CAAA;AACvC,IAAS,QAAA,EAAA,CAAA;AACT,IAAA,IAAA,CAAK,+BAAkC,GAAA,KAAA,CAAA;AAAA,GACzC;AAAA,EAEO,wBAAwB,MAAuC,EAAA;AACpE,IAAA,OAAO,IAAK,CAAA,+BAAA,CAAA;AAAA,GACd;AACF;;;;"}
|
@@ -1,7 +1,12 @@
|
|
1
1
|
import { useUrlSync } from './useUrlSync.js';
|
2
2
|
|
3
|
-
function UrlSyncContextProvider({
|
4
|
-
|
3
|
+
function UrlSyncContextProvider({
|
4
|
+
children,
|
5
|
+
scene,
|
6
|
+
updateUrlOnInit,
|
7
|
+
createBrowserHistorySteps
|
8
|
+
}) {
|
9
|
+
const isInitialized = useUrlSync(scene, { updateUrlOnInit, createBrowserHistorySteps });
|
5
10
|
if (!isInitialized) {
|
6
11
|
return null;
|
7
12
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"UrlSyncContextProvider.js","sources":["../../../src/services/UrlSyncContextProvider.ts"],"sourcesContent":["import { SceneObject } from '../core/types';\nimport { useUrlSync } from './useUrlSync';\n\nexport interface UrlSyncContextProviderProps {\n scene: SceneObject;\n children: React.ReactNode;\n}\n\n/**\n * Right now this is actually not defining a context, but think it might in the future (with UrlSyncManager as the context value)\n */\n\nexport function UrlSyncContextProvider({
|
1
|
+
{"version":3,"file":"UrlSyncContextProvider.js","sources":["../../../src/services/UrlSyncContextProvider.ts"],"sourcesContent":["import { SceneObject, SceneUrlSyncOptions } from '../core/types';\nimport { useUrlSync } from './useUrlSync';\n\nexport interface UrlSyncContextProviderProps extends SceneUrlSyncOptions {\n scene: SceneObject;\n children: React.ReactNode;\n}\n\n/**\n * Right now this is actually not defining a context, but think it might in the future (with UrlSyncManager as the context value)\n */\n\nexport function UrlSyncContextProvider({\n children,\n scene,\n updateUrlOnInit,\n createBrowserHistorySteps,\n}: UrlSyncContextProviderProps) {\n const isInitialized = useUrlSync(scene, { updateUrlOnInit, createBrowserHistorySteps });\n\n if (!isInitialized) {\n return null;\n }\n\n return children;\n}\n"],"names":[],"mappings":";;AAYO,SAAS,sBAAuB,CAAA;AAAA,EACrC,QAAA;AAAA,EACA,KAAA;AAAA,EACA,eAAA;AAAA,EACA,yBAAA;AACF,CAAgC,EAAA;AAC9B,EAAA,MAAM,gBAAgB,UAAW,CAAA,KAAA,EAAO,EAAE,eAAA,EAAiB,2BAA2B,CAAA,CAAA;AAEtF,EAAA,IAAI,CAAC,aAAe,EAAA;AAClB,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AAEA,EAAO,OAAA,QAAA,CAAA;AACT;;;;"}
|