@grafana/scenes 4.29.0 → 4.29.1--canary.765.9462062093.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/esm/components/EmbeddedScene.js +0 -5
- package/dist/esm/components/EmbeddedScene.js.map +1 -1
- package/dist/esm/components/SceneApp/SceneAppPage.js +0 -5
- package/dist/esm/components/SceneApp/SceneAppPage.js.map +1 -1
- package/dist/esm/components/SceneApp/SceneAppPageView.js +3 -1
- package/dist/esm/components/SceneApp/SceneAppPageView.js.map +1 -1
- package/dist/esm/core/sceneGraph/sceneGraph.js +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/services/UniqueUrlKeyMapper.js +24 -16
- package/dist/esm/services/UniqueUrlKeyMapper.js.map +1 -1
- package/dist/esm/services/UrlSyncContextProvider.js +12 -0
- package/dist/esm/services/UrlSyncContextProvider.js.map +1 -0
- package/dist/esm/services/UrlSyncManager.js +83 -48
- package/dist/esm/services/UrlSyncManager.js.map +1 -1
- package/dist/esm/services/useUrlSync.js +27 -0
- package/dist/esm/services/useUrlSync.js.map +1 -0
- package/dist/esm/services/utils.js +10 -4
- package/dist/esm/services/utils.js.map +1 -1
- package/dist/index.d.ts +18 -17
- package/dist/index.js +833 -763
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
@@ -2,7 +2,6 @@ import { css } from '@emotion/css';
|
|
2
2
|
import { useStyles2 } from '@grafana/ui';
|
3
3
|
import React from 'react';
|
4
4
|
import { SceneObjectBase } from '../core/SceneObjectBase.js';
|
5
|
-
import { getUrlSyncManager } from '../services/UrlSyncManager.js';
|
6
5
|
import { setWindowGrafanaSceneContext } from '../utils/compatibility/setWindowGrafanaSceneContext.js';
|
7
6
|
|
8
7
|
class EmbeddedScene extends SceneObjectBase {
|
@@ -12,13 +11,9 @@ class EmbeddedScene extends SceneObjectBase {
|
|
12
11
|
const unsetGlobalScene = setWindowGrafanaSceneContext(this);
|
13
12
|
return () => {
|
14
13
|
unsetGlobalScene();
|
15
|
-
getUrlSyncManager().cleanUp(this);
|
16
14
|
};
|
17
15
|
});
|
18
16
|
}
|
19
|
-
initUrlSync() {
|
20
|
-
getUrlSyncManager().initSync(this);
|
21
|
-
}
|
22
17
|
}
|
23
18
|
EmbeddedScene.Component = EmbeddedSceneRenderer;
|
24
19
|
function EmbeddedSceneRenderer({ model }) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"EmbeddedScene.js","sources":["../../../src/components/EmbeddedScene.tsx"],"sourcesContent":["import { css } from '@emotion/css';\nimport { GrafanaTheme2 } from '@grafana/data';\nimport { useStyles2 } from '@grafana/ui';\nimport React from 'react';\n\nimport { SceneObjectBase } from '../core/SceneObjectBase';\nimport { SceneComponentProps, SceneObjectState, SceneObject } from '../core/types';\nimport {
|
1
|
+
{"version":3,"file":"EmbeddedScene.js","sources":["../../../src/components/EmbeddedScene.tsx"],"sourcesContent":["import { css } from '@emotion/css';\nimport { GrafanaTheme2 } from '@grafana/data';\nimport { useStyles2 } from '@grafana/ui';\nimport React from 'react';\n\nimport { SceneObjectBase } from '../core/SceneObjectBase';\nimport { SceneComponentProps, SceneObjectState, SceneObject } from '../core/types';\nimport { setWindowGrafanaSceneContext } from '../utils/compatibility/setWindowGrafanaSceneContext';\n\nexport interface EmbeddedSceneState extends SceneObjectState {\n /**\n * The main content of the scene (usually a SceneFlexLayout)\n */\n body: SceneObject;\n /**\n * Top row of variable selectors, filters, time pickers and custom actions.\n */\n controls?: SceneObject[];\n}\n\nexport class EmbeddedScene extends SceneObjectBase<EmbeddedSceneState> {\n public static Component = EmbeddedSceneRenderer;\n\n public constructor(state: EmbeddedSceneState) {\n super(state);\n\n this.addActivationHandler(() => {\n // This function is setting window.__grafanaSceneContext which is used from Grafana core in the old services TimeSrv and TemplateSrv.\n // This works as a backward compatability method to support accessing scene time range and variables from those old services.\n const unsetGlobalScene = setWindowGrafanaSceneContext(this);\n return () => {\n unsetGlobalScene();\n };\n });\n }\n}\n\nfunction EmbeddedSceneRenderer({ model }: SceneComponentProps<EmbeddedScene>) {\n const { body, controls } = model.useState();\n const styles = useStyles2(getStyles);\n\n return (\n <div className={styles.container}>\n {controls && (\n <div className={styles.controls}>\n {controls.map((control) => (\n <control.Component key={control.state.key} model={control} />\n ))}\n </div>\n )}\n <div className={styles.body}>\n <body.Component model={body} />\n </div>\n </div>\n );\n}\n\nconst getStyles = (theme: GrafanaTheme2) => {\n return {\n container: css({\n flexGrow: 1,\n display: 'flex',\n gap: theme.spacing(2),\n minHeight: '100%',\n flexDirection: 'column',\n }),\n body: css({\n flexGrow: 1,\n display: 'flex',\n gap: theme.spacing(1),\n }),\n controls: css({\n display: 'flex',\n gap: theme.spacing(2),\n alignItems: 'flex-end',\n flexWrap: 'wrap',\n }),\n };\n};\n"],"names":[],"mappings":";;;;;;AAoBO,MAAM,sBAAsB,eAAoC,CAAA;AAAA,EAG9D,YAAY,KAA2B,EAAA;AAC5C,IAAA,KAAA,CAAM,KAAK,CAAA,CAAA;AAEX,IAAA,IAAA,CAAK,qBAAqB,MAAM;AAG9B,MAAM,MAAA,gBAAA,GAAmB,6BAA6B,IAAI,CAAA,CAAA;AAC1D,MAAA,OAAO,MAAM;AACX,QAAiB,gBAAA,EAAA,CAAA;AAAA,OACnB,CAAA;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAA;AAfa,aAAA,CACG,SAAY,GAAA,qBAAA,CAAA;AAgB5B,SAAS,qBAAA,CAAsB,EAAE,KAAA,EAA6C,EAAA;AAC5E,EAAA,MAAM,EAAE,IAAA,EAAM,QAAS,EAAA,GAAI,MAAM,QAAS,EAAA,CAAA;AAC1C,EAAM,MAAA,MAAA,GAAS,WAAW,SAAS,CAAA,CAAA;AAEnC,EAAA,uBACG,KAAA,CAAA,aAAA,CAAA,KAAA,EAAA;AAAA,IAAI,WAAW,MAAO,CAAA,SAAA;AAAA,GAAA,EACpB,4BACE,KAAA,CAAA,aAAA,CAAA,KAAA,EAAA;AAAA,IAAI,WAAW,MAAO,CAAA,QAAA;AAAA,GAAA,EACpB,SAAS,GAAI,CAAA,CAAC,OACb,qBAAA,KAAA,CAAA,aAAA,CAAC,QAAQ,SAAR,EAAA;AAAA,IAAkB,GAAA,EAAK,QAAQ,KAAM,CAAA,GAAA;AAAA,IAAK,KAAO,EAAA,OAAA;AAAA,GAAS,CAC5D,CACH,CAAA,kBAED,KAAA,CAAA,aAAA,CAAA,KAAA,EAAA;AAAA,IAAI,WAAW,MAAO,CAAA,IAAA;AAAA,GACrB,kBAAA,KAAA,CAAA,aAAA,CAAC,KAAK,SAAL,EAAA;AAAA,IAAe,KAAO,EAAA,IAAA;AAAA,GAAM,CAC/B,CACF,CAAA,CAAA;AAEJ,CAAA;AAEA,MAAM,SAAA,GAAY,CAAC,KAAyB,KAAA;AAC1C,EAAO,OAAA;AAAA,IACL,WAAW,GAAI,CAAA;AAAA,MACb,QAAU,EAAA,CAAA;AAAA,MACV,OAAS,EAAA,MAAA;AAAA,MACT,GAAA,EAAK,KAAM,CAAA,OAAA,CAAQ,CAAC,CAAA;AAAA,MACpB,SAAW,EAAA,MAAA;AAAA,MACX,aAAe,EAAA,QAAA;AAAA,KAChB,CAAA;AAAA,IACD,MAAM,GAAI,CAAA;AAAA,MACR,QAAU,EAAA,CAAA;AAAA,MACV,OAAS,EAAA,MAAA;AAAA,MACT,GAAA,EAAK,KAAM,CAAA,OAAA,CAAQ,CAAC,CAAA;AAAA,KACrB,CAAA;AAAA,IACD,UAAU,GAAI,CAAA;AAAA,MACZ,OAAS,EAAA,MAAA;AAAA,MACT,GAAA,EAAK,KAAM,CAAA,OAAA,CAAQ,CAAC,CAAA;AAAA,MACpB,UAAY,EAAA,UAAA;AAAA,MACZ,QAAU,EAAA,MAAA;AAAA,KACX,CAAA;AAAA,GACH,CAAA;AACF,CAAA;;;;"}
|
@@ -2,7 +2,6 @@ import React from 'react';
|
|
2
2
|
import { Route, Switch } from 'react-router-dom';
|
3
3
|
import { SceneObjectBase } from '../../core/SceneObjectBase.js';
|
4
4
|
import { isDataRequestEnricher } from '../../core/types.js';
|
5
|
-
import { getUrlSyncManager } from '../../services/UrlSyncManager.js';
|
6
5
|
import { EmbeddedScene } from '../EmbeddedScene.js';
|
7
6
|
import { SceneFlexLayout, SceneFlexItem } from '../layout/SceneFlexLayout.js';
|
8
7
|
import { SceneReactObject } from '../SceneReactObject.js';
|
@@ -14,13 +13,9 @@ class SceneAppPage extends SceneObjectBase {
|
|
14
13
|
super(state);
|
15
14
|
this._sceneCache = /* @__PURE__ */ new Map();
|
16
15
|
this._drilldownCache = /* @__PURE__ */ new Map();
|
17
|
-
this.addActivationHandler(() => {
|
18
|
-
return () => getUrlSyncManager().cleanUp(this);
|
19
|
-
});
|
20
16
|
}
|
21
17
|
initializeScene(scene) {
|
22
18
|
this.setState({ initializedScene: scene });
|
23
|
-
getUrlSyncManager().initSync(this);
|
24
19
|
}
|
25
20
|
getScene(routeMatch) {
|
26
21
|
let scene = this._sceneCache.get(routeMatch.url);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"SceneAppPage.js","sources":["../../../../src/components/SceneApp/SceneAppPage.tsx"],"sourcesContent":["import React from 'react';\nimport { Route, RouteComponentProps, Switch } from 'react-router-dom';\nimport { SceneObjectBase } from '../../core/SceneObjectBase';\nimport { SceneComponentProps, SceneObject, isDataRequestEnricher } from '../../core/types';\nimport { getUrlSyncManager } from '../../services/UrlSyncManager';\nimport { EmbeddedScene } from '../EmbeddedScene';\nimport { SceneFlexItem, SceneFlexLayout } from '../layout/SceneFlexLayout';\nimport { SceneReactObject } from '../SceneReactObject';\nimport { SceneAppDrilldownViewRender, SceneAppPageView } from './SceneAppPageView';\nimport { SceneAppDrilldownView, SceneAppPageLike, SceneAppPageState, SceneRouteMatch } from './types';\nimport { renderSceneComponentWithRouteProps } from './utils';\n\n/**\n * Responsible for page's drilldown & tabs routing\n */\nexport class SceneAppPage extends SceneObjectBase<SceneAppPageState> implements SceneAppPageLike {\n public static Component = SceneAppPageRenderer;\n private _sceneCache = new Map<string, EmbeddedScene>();\n private _drilldownCache = new Map<string, SceneAppPageLike>();\n\n public constructor(state: SceneAppPageState) {\n super(state);\n\n this.addActivationHandler(() => {\n return () => getUrlSyncManager().cleanUp(this);\n });\n }\n\n public initializeScene(scene: EmbeddedScene) {\n this.setState({ initializedScene: scene });\n getUrlSyncManager().initSync(this);\n }\n\n public getScene(routeMatch: SceneRouteMatch): EmbeddedScene {\n let scene = this._sceneCache.get(routeMatch.url);\n\n if (scene) {\n return scene;\n }\n\n if (!this.state.getScene) {\n throw new Error('Missing getScene on SceneAppPage ' + this.state.title);\n }\n\n scene = this.state.getScene(routeMatch);\n this._sceneCache.set(routeMatch.url, scene);\n\n return scene;\n }\n\n public getDrilldownPage(drilldown: SceneAppDrilldownView, routeMatch: SceneRouteMatch<{}>): SceneAppPageLike {\n let page = this._drilldownCache.get(routeMatch!.url);\n if (page) {\n return page;\n }\n\n page = drilldown.getPage(routeMatch, this);\n this._drilldownCache.set(routeMatch!.url, page);\n\n return page;\n }\n\n public enrichDataRequest(source: SceneObject) {\n if (this.state.getParentPage) {\n return this.state.getParentPage().enrichDataRequest(source);\n }\n\n if (!this.parent) {\n return null;\n }\n\n const root = this.getRoot();\n\n if (isDataRequestEnricher(root)) {\n return root.enrichDataRequest(source);\n }\n\n return null;\n }\n}\n\nexport interface SceneAppPageRendererProps extends SceneComponentProps<SceneAppPage> {\n routeProps: RouteComponentProps;\n}\n\nfunction SceneAppPageRenderer({ model, routeProps }: SceneAppPageRendererProps) {\n const { tabs, drilldowns } = model.useState();\n const routes: React.ReactNode[] = [];\n\n if (tabs && tabs.length > 0) {\n for (let tabIndex = 0; tabIndex < tabs.length; tabIndex++) {\n const tab = tabs[tabIndex];\n\n // Add first tab as a default route, this makes it possible for the first tab to render with the url of the parent page\n if (tabIndex === 0) {\n routes.push(\n <Route\n exact={true}\n key={model.state.url}\n path={model.state.routePath ?? model.state.url}\n render={(props) => renderSceneComponentWithRouteProps(tab, props)}\n ></Route>\n );\n }\n\n routes.push(\n <Route\n exact={true}\n key={tab.state.url}\n path={tab.state.routePath ?? tab.state.url}\n render={(props) => renderSceneComponentWithRouteProps(tab, props)}\n ></Route>\n );\n\n if (tab.state.drilldowns) {\n for (const drilldown of tab.state.drilldowns) {\n routes.push(\n <Route\n exact={false}\n key={drilldown.routePath}\n path={drilldown.routePath}\n render={(props) => <SceneAppDrilldownViewRender drilldown={drilldown} parent={tab} routeProps={props} />}\n ></Route>\n );\n }\n }\n }\n }\n\n if (drilldowns) {\n for (const drilldown of drilldowns) {\n routes.push(\n <Route\n key={drilldown.routePath}\n exact={false}\n path={drilldown.routePath}\n render={(props) => <SceneAppDrilldownViewRender drilldown={drilldown} parent={model} routeProps={props} />}\n ></Route>\n );\n }\n }\n\n if (!tabs && isCurrentPageRouteMatch(model, routeProps.match)) {\n return <SceneAppPageView page={model} routeProps={routeProps} />;\n }\n\n routes.push(getFallbackRoute(model, routeProps));\n\n return <Switch>{routes}</Switch>;\n}\n\nfunction getFallbackRoute(page: SceneAppPage, routeProps: RouteComponentProps) {\n return (\n <Route\n key={'fallback route'}\n render={(props) => {\n const fallbackPage = page.state.getFallbackPage?.() ?? getDefaultFallbackPage();\n return <SceneAppPageView page={fallbackPage} routeProps={routeProps} />;\n }}\n ></Route>\n );\n}\n\nfunction isCurrentPageRouteMatch(page: SceneAppPage, match: SceneRouteMatch) {\n if (!match.isExact) {\n return false;\n }\n\n // current page matches the route url\n if (match.url === page.state.url) {\n return true;\n }\n\n // check if we are a tab and the first tab, then we should also render on the parent url\n if (\n page.parent instanceof SceneAppPage &&\n page.parent.state.tabs![0] === page &&\n page.parent.state.url === match.url\n ) {\n return true;\n }\n\n return false;\n}\n\nfunction getDefaultFallbackPage() {\n return new SceneAppPage({\n url: '',\n title: 'Not found',\n subTitle: 'The url did not match any page',\n getScene: () => {\n return new EmbeddedScene({\n body: new SceneFlexLayout({\n direction: 'column',\n children: [\n new SceneFlexItem({\n body: new SceneReactObject({\n component: () => {\n return (\n <div data-testid=\"default-fallback-content\">\n If you found your way here using a link then there might be a bug in this application.\n </div>\n );\n },\n }),\n }),\n ],\n }),\n });\n },\n });\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAeO,MAAM,qBAAqB,eAA+D,CAAA;AAAA,EAKxF,YAAY,KAA0B,EAAA;AAC3C,IAAA,KAAA,CAAM,KAAK,CAAA,CAAA;AAJb,IAAQ,IAAA,CAAA,WAAA,uBAAkB,GAA2B,EAAA,CAAA;AACrD,IAAQ,IAAA,CAAA,eAAA,uBAAsB,GAA8B,EAAA,CAAA;AAK1D,IAAA,IAAA,CAAK,qBAAqB,MAAM;AAC9B,MAAA,OAAO,MAAM,iBAAA,EAAoB,CAAA,OAAA,CAAQ,IAAI,CAAA,CAAA;AAAA,KAC9C,CAAA,CAAA;AAAA,GACH;AAAA,EAEO,gBAAgB,KAAsB,EAAA;AAC3C,IAAA,IAAA,CAAK,QAAS,CAAA,EAAE,gBAAkB,EAAA,KAAA,EAAO,CAAA,CAAA;AACzC,IAAkB,iBAAA,EAAA,CAAE,SAAS,IAAI,CAAA,CAAA;AAAA,GACnC;AAAA,EAEO,SAAS,UAA4C,EAAA;AAC1D,IAAA,IAAI,KAAQ,GAAA,IAAA,CAAK,WAAY,CAAA,GAAA,CAAI,WAAW,GAAG,CAAA,CAAA;AAE/C,IAAA,IAAI,KAAO,EAAA;AACT,MAAO,OAAA,KAAA,CAAA;AAAA,KACT;AAEA,IAAI,IAAA,CAAC,IAAK,CAAA,KAAA,CAAM,QAAU,EAAA;AACxB,MAAA,MAAM,IAAI,KAAA,CAAM,mCAAsC,GAAA,IAAA,CAAK,MAAM,KAAK,CAAA,CAAA;AAAA,KACxE;AAEA,IAAQ,KAAA,GAAA,IAAA,CAAK,KAAM,CAAA,QAAA,CAAS,UAAU,CAAA,CAAA;AACtC,IAAA,IAAA,CAAK,WAAY,CAAA,GAAA,CAAI,UAAW,CAAA,GAAA,EAAK,KAAK,CAAA,CAAA;AAE1C,IAAO,OAAA,KAAA,CAA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,gCAAA;AAAA,IACV,UAAU,MAAM;AACd,MAAA,OAAO,IAAI,aAAc,CAAA;AAAA,QACvB,IAAA,EAAM,IAAI,eAAgB,CAAA;AAAA,UACxB,SAAW,EAAA,QAAA;AAAA,UACX,QAAU,EAAA;AAAA,YACR,IAAI,aAAc,CAAA;AAAA,cAChB,IAAA,EAAM,IAAI,gBAAiB,CAAA;AAAA,gBACzB,WAAW,MAAM;AACf,kBAAA,uBACG,KAAA,CAAA,aAAA,CAAA,KAAA,EAAA;AAAA,oBAAI,aAAY,EAAA,0BAAA;AAAA,mBAAA,EAA2B,wFAE5C,CAAA,CAAA;AAAA,iBAEJ;AAAA,eACD,CAAA;AAAA,aACF,CAAA;AAAA,WACH;AAAA,SACD,CAAA;AAAA,OACF,CAAA,CAAA;AAAA,KACH;AAAA,GACD,CAAA,CAAA;AACH;;;;"}
|
1
|
+
{"version":3,"file":"SceneAppPage.js","sources":["../../../../src/components/SceneApp/SceneAppPage.tsx"],"sourcesContent":["import React from 'react';\nimport { Route, RouteComponentProps, Switch } from 'react-router-dom';\nimport { SceneObjectBase } from '../../core/SceneObjectBase';\nimport { SceneComponentProps, SceneObject, isDataRequestEnricher } from '../../core/types';\nimport { EmbeddedScene } from '../EmbeddedScene';\nimport { SceneFlexItem, SceneFlexLayout } from '../layout/SceneFlexLayout';\nimport { SceneReactObject } from '../SceneReactObject';\nimport { SceneAppDrilldownViewRender, SceneAppPageView } from './SceneAppPageView';\nimport { SceneAppDrilldownView, SceneAppPageLike, SceneAppPageState, SceneRouteMatch } from './types';\nimport { renderSceneComponentWithRouteProps } from './utils';\n\n/**\n * Responsible for page's drilldown & tabs routing\n */\nexport class SceneAppPage extends SceneObjectBase<SceneAppPageState> implements SceneAppPageLike {\n public static Component = SceneAppPageRenderer;\n private _sceneCache = new Map<string, EmbeddedScene>();\n private _drilldownCache = new Map<string, SceneAppPageLike>();\n\n public constructor(state: SceneAppPageState) {\n super(state);\n }\n\n public initializeScene(scene: EmbeddedScene) {\n this.setState({ initializedScene: scene });\n }\n\n public getScene(routeMatch: SceneRouteMatch): EmbeddedScene {\n let scene = this._sceneCache.get(routeMatch.url);\n\n if (scene) {\n return scene;\n }\n\n if (!this.state.getScene) {\n throw new Error('Missing getScene on SceneAppPage ' + this.state.title);\n }\n\n scene = this.state.getScene(routeMatch);\n this._sceneCache.set(routeMatch.url, scene);\n\n return scene;\n }\n\n public getDrilldownPage(drilldown: SceneAppDrilldownView, routeMatch: SceneRouteMatch<{}>): SceneAppPageLike {\n let page = this._drilldownCache.get(routeMatch!.url);\n if (page) {\n return page;\n }\n\n page = drilldown.getPage(routeMatch, this);\n this._drilldownCache.set(routeMatch!.url, page);\n\n return page;\n }\n\n public enrichDataRequest(source: SceneObject) {\n if (this.state.getParentPage) {\n return this.state.getParentPage().enrichDataRequest(source);\n }\n\n if (!this.parent) {\n return null;\n }\n\n const root = this.getRoot();\n\n if (isDataRequestEnricher(root)) {\n return root.enrichDataRequest(source);\n }\n\n return null;\n }\n}\n\nexport interface SceneAppPageRendererProps extends SceneComponentProps<SceneAppPage> {\n routeProps: RouteComponentProps;\n}\n\nfunction SceneAppPageRenderer({ model, routeProps }: SceneAppPageRendererProps) {\n const { tabs, drilldowns } = model.useState();\n const routes: React.ReactNode[] = [];\n\n if (tabs && tabs.length > 0) {\n for (let tabIndex = 0; tabIndex < tabs.length; tabIndex++) {\n const tab = tabs[tabIndex];\n\n // Add first tab as a default route, this makes it possible for the first tab to render with the url of the parent page\n if (tabIndex === 0) {\n routes.push(\n <Route\n exact={true}\n key={model.state.url}\n path={model.state.routePath ?? model.state.url}\n render={(props) => renderSceneComponentWithRouteProps(tab, props)}\n ></Route>\n );\n }\n\n routes.push(\n <Route\n exact={true}\n key={tab.state.url}\n path={tab.state.routePath ?? tab.state.url}\n render={(props) => renderSceneComponentWithRouteProps(tab, props)}\n ></Route>\n );\n\n if (tab.state.drilldowns) {\n for (const drilldown of tab.state.drilldowns) {\n routes.push(\n <Route\n exact={false}\n key={drilldown.routePath}\n path={drilldown.routePath}\n render={(props) => <SceneAppDrilldownViewRender drilldown={drilldown} parent={tab} routeProps={props} />}\n ></Route>\n );\n }\n }\n }\n }\n\n if (drilldowns) {\n for (const drilldown of drilldowns) {\n routes.push(\n <Route\n key={drilldown.routePath}\n exact={false}\n path={drilldown.routePath}\n render={(props) => <SceneAppDrilldownViewRender drilldown={drilldown} parent={model} routeProps={props} />}\n ></Route>\n );\n }\n }\n\n if (!tabs && isCurrentPageRouteMatch(model, routeProps.match)) {\n return <SceneAppPageView page={model} routeProps={routeProps} />;\n }\n\n routes.push(getFallbackRoute(model, routeProps));\n\n return <Switch>{routes}</Switch>;\n}\n\nfunction getFallbackRoute(page: SceneAppPage, routeProps: RouteComponentProps) {\n return (\n <Route\n key={'fallback route'}\n render={(props) => {\n const fallbackPage = page.state.getFallbackPage?.() ?? getDefaultFallbackPage();\n return <SceneAppPageView page={fallbackPage} routeProps={routeProps} />;\n }}\n ></Route>\n );\n}\n\nfunction isCurrentPageRouteMatch(page: SceneAppPage, match: SceneRouteMatch) {\n if (!match.isExact) {\n return false;\n }\n\n // current page matches the route url\n if (match.url === page.state.url) {\n return true;\n }\n\n // check if we are a tab and the first tab, then we should also render on the parent url\n if (\n page.parent instanceof SceneAppPage &&\n page.parent.state.tabs![0] === page &&\n page.parent.state.url === match.url\n ) {\n return true;\n }\n\n return false;\n}\n\nfunction getDefaultFallbackPage() {\n return new SceneAppPage({\n url: '',\n title: 'Not found',\n subTitle: 'The url did not match any page',\n getScene: () => {\n return new EmbeddedScene({\n body: new SceneFlexLayout({\n direction: 'column',\n children: [\n new SceneFlexItem({\n body: new SceneReactObject({\n component: () => {\n return (\n <div data-testid=\"default-fallback-content\">\n If you found your way here using a link then there might be a bug in this application.\n </div>\n );\n },\n }),\n }),\n ],\n }),\n });\n },\n });\n}\n"],"names":[],"mappings":";;;;;;;;;;AAcO,MAAM,qBAAqB,eAA+D,CAAA;AAAA,EAKxF,YAAY,KAA0B,EAAA;AAC3C,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AAA;AAAA,iBAEJ;AAAA,eACD,CAAA;AAAA,aACF,CAAA;AAAA,WACH;AAAA,SACD,CAAA;AAAA,OACF,CAAA,CAAA;AAAA,KACH;AAAA,GACD,CAAA,CAAA;AACH;;;;"}
|
@@ -3,6 +3,7 @@ import React, { 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
|
+
import { useUrlSync } from '../../services/useUrlSync.js';
|
6
7
|
|
7
8
|
function SceneAppPageView({ page, routeProps }) {
|
8
9
|
const containerPage = getParentPageIfTab(page);
|
@@ -18,7 +19,8 @@ function SceneAppPageView({ page, routeProps }) {
|
|
18
19
|
useEffect(() => {
|
19
20
|
return () => containerPage.setState({ initializedScene: void 0 });
|
20
21
|
}, [containerPage]);
|
21
|
-
|
22
|
+
const urlSyncInitialized = useUrlSync(containerPage);
|
23
|
+
if (!isInitialized && !urlSyncInitialized) {
|
22
24
|
return null;
|
23
25
|
}
|
24
26
|
const pageNav = {
|
@@ -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';\n\nexport interface Props {\n page: SceneAppPageLike;\n // activeTab?: SceneAppPageLike;\n routeProps: RouteComponentProps;\n}\n\nexport function SceneAppPageView({ page, routeProps }: Props) {\n const containerPage = getParentPageIfTab(page);\n const containerState = containerPage.useState();\n const params = useAppQueryParams();\n const scene = page.getScene(routeProps.match);\n const isInitialized = containerState.initializedScene === scene;\n\n useLayoutEffect(() => {\n // Before rendering scene components, we are making sure the URL sync is enabled for.\n if (!isInitialized) {\n containerPage.initializeScene(scene);\n }\n }, [scene, containerPage, isInitialized]);\n\n // Clear initializedScene when unmounting\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, { useEffect, useLayoutEffect } from 'react';\n\nimport { RouteComponentProps } from 'react-router-dom';\nimport { SceneObject } from '../../core/types';\nimport { SceneDebugger } from '../SceneDebugger/SceneDebugger';\nimport { SceneAppPage } from './SceneAppPage';\nimport { SceneAppDrilldownView, SceneAppPageLike } from './types';\nimport { getUrlWithAppState, renderSceneComponentWithRouteProps, useAppQueryParams } from './utils';\nimport { useUrlSync } from '../../services/useUrlSync';\n\nexport interface Props {\n page: SceneAppPageLike;\n // activeTab?: SceneAppPageLike;\n routeProps: RouteComponentProps;\n}\n\nexport function SceneAppPageView({ page, routeProps }: Props) {\n const containerPage = getParentPageIfTab(page);\n const containerState = containerPage.useState();\n const params = useAppQueryParams();\n const scene = page.getScene(routeProps.match);\n const isInitialized = containerState.initializedScene === scene;\n\n useLayoutEffect(() => {\n // Before rendering scene components, we are making sure the URL sync is enabled for.\n if (!isInitialized) {\n containerPage.initializeScene(scene);\n }\n }, [scene, containerPage, isInitialized]);\n\n useEffect(() => {\n // Clear initializedScene when unmounting\n return () => containerPage.setState({ initializedScene: undefined });\n }, [containerPage]);\n\n const urlSyncInitialized = useUrlSync(containerPage);\n\n if (!isInitialized && !urlSyncInitialized) {\n return null;\n }\n\n const pageNav: NavModelItem = {\n text: containerState.title,\n img: containerState.titleImg,\n icon: containerState.titleIcon,\n url: getUrlWithAppState(containerState.url, containerState.preserveUrlKeys),\n hideFromBreadcrumbs: containerState.hideFromBreadcrumbs,\n parentItem: getParentBreadcrumbs(\n containerState.getParentPage ? containerState.getParentPage() : containerPage.parent,\n params\n ),\n };\n\n if (containerState.tabs) {\n pageNav.children = containerState.tabs.map((tab) => {\n return {\n text: tab.state.title,\n icon: tab.state.titleIcon,\n tabSuffix: tab.state.tabSuffix,\n active: page === tab,\n url: getUrlWithAppState(tab.state.url, tab.state.preserveUrlKeys),\n parentItem: pageNav,\n };\n });\n }\n\n let pageActions: React.ReactNode[] = [];\n if (containerState.controls) {\n pageActions = containerState.controls.map((control) => (\n <control.Component model={control} key={control.state.key} />\n ));\n }\n\n if (params['scene-debugger']) {\n pageActions.push(<SceneDebugger scene={containerPage} key={'scene-debugger'} />);\n }\n\n return (\n <PluginPage\n pageNav={pageNav}\n actions={pageActions}\n renderTitle={containerState.renderTitle}\n subTitle={containerState.subTitle}\n >\n <scene.Component model={scene} />\n </PluginPage>\n );\n}\n\n/**\n * For pages that are \"tabs\" this will return the parent page\n */\nfunction getParentPageIfTab(page: SceneAppPageLike) {\n if (page.parent instanceof SceneAppPage) {\n return page.parent;\n }\n\n return page;\n}\n\nfunction getParentBreadcrumbs(parent: SceneObject | undefined, params: UrlQueryMap): NavModelItem | undefined {\n if (parent instanceof SceneAppPage) {\n return {\n text: parent.state.title,\n url: getUrlWithAppState(parent.state.url, parent.state.preserveUrlKeys),\n hideFromBreadcrumbs: parent.state.hideFromBreadcrumbs,\n parentItem: getParentBreadcrumbs(\n parent.state.getParentPage ? parent.state.getParentPage() : parent.parent,\n params\n ),\n };\n }\n\n return undefined;\n}\n\nexport interface SceneAppDrilldownViewRenderProps {\n drilldown: SceneAppDrilldownView;\n parent: SceneAppPageLike;\n routeProps: RouteComponentProps;\n}\n\nexport function SceneAppDrilldownViewRender({ drilldown, parent, routeProps }: SceneAppDrilldownViewRenderProps) {\n return renderSceneComponentWithRouteProps(parent.getDrilldownPage(drilldown,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AA,WAAA;AAAA,IACT,aAAa,cAAe,CAAA,WAAA;AAAA,IAC5B,UAAU,cAAe,CAAA,QAAA;AAAA,GAEzB,kBAAA,KAAA,CAAA,aAAA,CAAC,MAAM,SAAN,EAAA;AAAA,IAAgB,KAAO,EAAA,KAAA;AAAA,GAAO,CACjC,CAAA,CAAA;AAEJ,CAAA;AAKA,SAAS,mBAAmB,IAAwB,EAAA;AAClD,EAAI,IAAA,IAAA,CAAK,kBAAkB,YAAc,EAAA;AACvC,IAAA,OAAO,IAAK,CAAA,MAAA,CAAA;AAAA,GACd;AAEA,EAAO,OAAA,IAAA,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;;;;"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { EmptyDataNode, EmptyVariableSet } from '../../variables/interpolation/defaults.js';
|
2
2
|
import { sceneInterpolator } from '../../variables/interpolation/sceneInterpolator.js';
|
3
3
|
import { isDataLayer } from '../types.js';
|
4
4
|
import { lookupVariable } from '../../variables/lookupVariable.js';
|
package/dist/esm/index.js
CHANGED
@@ -42,6 +42,8 @@ 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
44
|
export { UrlSyncManager, getUrlSyncManager } from './services/UrlSyncManager.js';
|
45
|
+
export { useUrlSync } from './services/useUrlSync.js';
|
46
|
+
export { UrlSyncContextProvider } from './services/UrlSyncContextProvider.js';
|
45
47
|
export { SceneObjectUrlSyncConfig } from './services/SceneObjectUrlSyncConfig.js';
|
46
48
|
export { EmbeddedScene } from './components/EmbeddedScene.js';
|
47
49
|
export { VizPanel } from './components/VizPanel/VizPanel.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';\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 { type ExtraQueryDescriptor, type ExtraQueryProvider, type ExtraQueryDataProcessor } 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 { MultiValueVariable } 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, getUrlSyncManager } from './services/UrlSyncManager';\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 { 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"],"names":[],"mappings":"
|
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';\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 { type ExtraQueryDescriptor, type ExtraQueryProvider, type ExtraQueryDataProcessor } 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 { MultiValueVariable } 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, getUrlSyncManager } 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 { 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"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqHO,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,3 +1,5 @@
|
|
1
|
+
import { sceneGraph } from '../core/sceneGraph/index.js';
|
2
|
+
|
1
3
|
class UniqueUrlKeyMapper {
|
2
4
|
constructor() {
|
3
5
|
this.index = /* @__PURE__ */ new Map();
|
@@ -5,33 +7,39 @@ class UniqueUrlKeyMapper {
|
|
5
7
|
getUniqueKey(key, obj) {
|
6
8
|
const objectsWithKey = this.index.get(key);
|
7
9
|
if (!objectsWithKey) {
|
8
|
-
|
10
|
+
this.index.set(key, [obj]);
|
11
|
+
return key;
|
12
|
+
}
|
13
|
+
let address = objectsWithKey.findIndex((o) => o === obj);
|
14
|
+
if (address === -1) {
|
15
|
+
filterOutOrphanedObjects(objectsWithKey);
|
16
|
+
objectsWithKey.push(obj);
|
17
|
+
address = objectsWithKey.length - 1;
|
9
18
|
}
|
10
|
-
const address = objectsWithKey.findIndex((o) => o.sceneObject === obj);
|
11
19
|
if (address > 0) {
|
12
20
|
return `${key}-${address + 1}`;
|
13
21
|
}
|
14
22
|
return key;
|
15
23
|
}
|
16
|
-
|
24
|
+
clear() {
|
17
25
|
this.index.clear();
|
18
|
-
this.buildIndex(root, 0);
|
19
26
|
}
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
hit.sort((a, b) => a.depth - b.depth);
|
27
|
-
} else {
|
28
|
-
this.index.set(key, [{ sceneObject, depth }]);
|
29
|
-
}
|
30
|
-
}
|
27
|
+
}
|
28
|
+
function filterOutOrphanedObjects(sceneObjects) {
|
29
|
+
for (const obj of sceneObjects) {
|
30
|
+
if (isOrphanOrInActive(obj)) {
|
31
|
+
const index = sceneObjects.indexOf(obj);
|
32
|
+
sceneObjects.splice(index, 1);
|
31
33
|
}
|
32
|
-
sceneObject.forEachChild((child) => this.buildIndex(child, depth + 1));
|
33
34
|
}
|
34
35
|
}
|
36
|
+
function isOrphanOrInActive(obj) {
|
37
|
+
const root = obj.getRoot();
|
38
|
+
if (!sceneGraph.findObject(root, (child) => child === obj)) {
|
39
|
+
return true;
|
40
|
+
}
|
41
|
+
return false;
|
42
|
+
}
|
35
43
|
|
36
44
|
export { UniqueUrlKeyMapper };
|
37
45
|
//# sourceMappingURL=UniqueUrlKeyMapper.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"UniqueUrlKeyMapper.js","sources":["../../../src/services/UniqueUrlKeyMapper.ts"],"sourcesContent":["import { SceneObject } from '../core/types';\n\nexport interface SceneObjectWithDepth {\n sceneObject: SceneObject;\n depth: number;\n}\n\nexport class UniqueUrlKeyMapper {\n private index = new Map<string,
|
1
|
+
{"version":3,"file":"UniqueUrlKeyMapper.js","sources":["../../../src/services/UniqueUrlKeyMapper.ts"],"sourcesContent":["import { sceneGraph } from '../core/sceneGraph';\nimport { SceneObject } from '../core/types';\n\nexport interface SceneObjectWithDepth {\n sceneObject: SceneObject;\n depth: number;\n}\n\nexport class UniqueUrlKeyMapper {\n private index = new Map<string, SceneObject[]>();\n\n public getUniqueKey(key: string, obj: SceneObject) {\n const objectsWithKey = this.index.get(key);\n\n if (!objectsWithKey) {\n this.index.set(key, [obj]);\n return key;\n }\n\n let address = objectsWithKey.findIndex((o) => o === obj);\n if (address === -1) {\n filterOutOrphanedObjects(objectsWithKey);\n objectsWithKey.push(obj);\n\n address = objectsWithKey.length - 1;\n }\n\n if (address > 0) {\n return `${key}-${address + 1}`;\n }\n\n return key;\n }\n\n public clear() {\n this.index.clear();\n }\n}\n\nfunction filterOutOrphanedObjects(sceneObjects: SceneObject[]) {\n for (const obj of sceneObjects) {\n if (isOrphanOrInActive(obj)) {\n const index = sceneObjects.indexOf(obj);\n sceneObjects.splice(index, 1);\n }\n }\n}\n\nfunction isOrphanOrInActive(obj: SceneObject) {\n const root = obj.getRoot();\n\n // If we cannot find it from the root it's an orphan\n if (!sceneGraph.findObject(root, (child) => child === obj)) {\n return true;\n }\n\n return false;\n}\n"],"names":[],"mappings":";;AAQO,MAAM,kBAAmB,CAAA;AAAA,EAAzB,WAAA,GAAA;AACL,IAAQ,IAAA,CAAA,KAAA,uBAAY,GAA2B,EAAA,CAAA;AAAA,GAAA;AAAA,EAExC,YAAA,CAAa,KAAa,GAAkB,EAAA;AACjD,IAAA,MAAM,cAAiB,GAAA,IAAA,CAAK,K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U,GAAG,CAAG,EAAA;AAC1D,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AAEA,EAAO,OAAA,KAAA,CAAA;AACT;;;;"}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { useUrlSync } from './useUrlSync.js';
|
2
|
+
|
3
|
+
function UrlSyncContextProvider({ children, scene }) {
|
4
|
+
const isInitialized = useUrlSync(scene);
|
5
|
+
if (!isInitialized) {
|
6
|
+
return null;
|
7
|
+
}
|
8
|
+
return children;
|
9
|
+
}
|
10
|
+
|
11
|
+
export { UrlSyncContextProvider };
|
12
|
+
//# sourceMappingURL=UrlSyncContextProvider.js.map
|
@@ -0,0 +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({ children, scene }: UrlSyncContextProviderProps) {\n const isInitialized = useUrlSync(scene);\n\n if (!isInitialized) {\n return null;\n }\n\n return children;\n}\n"],"names":[],"mappings":";;AAYO,SAAS,sBAAuB,CAAA,EAAE,QAAU,EAAA,KAAA,EAAsC,EAAA;AACvF,EAAM,MAAA,aAAA,GAAgB,WAAW,KAAK,CAAA,CAAA;AAEtC,EAAA,IAAI,CAAC,aAAe,EAAA;AAClB,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AAEA,EAAO,OAAA,QAAA,CAAA;AACT;;;;"}
|
@@ -2,92 +2,127 @@ import { locationService } from '@grafana/runtime';
|
|
2
2
|
import { SceneObjectStateChangedEvent } from '../core/events.js';
|
3
3
|
import { writeSceneLog } from '../utils/writeSceneLog.js';
|
4
4
|
import { UniqueUrlKeyMapper } from './UniqueUrlKeyMapper.js';
|
5
|
-
import { syncStateFromUrl,
|
5
|
+
import { syncStateFromUrl, getUrlState, isUrlValueEqual } from './utils.js';
|
6
6
|
|
7
|
+
var __accessCheck = (obj, member, msg) => {
|
8
|
+
if (!member.has(obj))
|
9
|
+
throw TypeError("Cannot " + msg);
|
10
|
+
};
|
11
|
+
var __privateGet = (obj, member, getter) => {
|
12
|
+
__accessCheck(obj, member, "read from private field");
|
13
|
+
return getter ? getter.call(obj) : member.get(obj);
|
14
|
+
};
|
15
|
+
var __privateAdd = (obj, member, value) => {
|
16
|
+
if (member.has(obj))
|
17
|
+
throw TypeError("Cannot add the same private member more than once");
|
18
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
19
|
+
};
|
20
|
+
var __privateSet = (obj, member, value, setter) => {
|
21
|
+
__accessCheck(obj, member, "write to private field");
|
22
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
23
|
+
return value;
|
24
|
+
};
|
25
|
+
var _urlKeyMapper, _sceneRoot, _stateSub, _lastLocation, _paramsCache, _onStateChanged, _cache, _location;
|
7
26
|
class UrlSyncManager {
|
8
27
|
constructor() {
|
9
|
-
this
|
10
|
-
this
|
11
|
-
this
|
12
|
-
this
|
13
|
-
this
|
14
|
-
|
15
|
-
this._ignoreNextLocationUpdate = false;
|
16
|
-
return;
|
17
|
-
}
|
18
|
-
if (this._lastPath !== location.pathname) {
|
19
|
-
return;
|
20
|
-
}
|
21
|
-
const urlParams = new URLSearchParams(location.search);
|
22
|
-
this._urlKeyMapper.rebuildIndex(this._sceneRoot);
|
23
|
-
syncStateFromUrl(this._sceneRoot, urlParams, this._urlKeyMapper);
|
24
|
-
this._lastPath = location.pathname;
|
25
|
-
};
|
26
|
-
this._onStateChanged = ({ payload }) => {
|
28
|
+
__privateAdd(this, _urlKeyMapper, new UniqueUrlKeyMapper());
|
29
|
+
__privateAdd(this, _sceneRoot, void 0);
|
30
|
+
__privateAdd(this, _stateSub, null);
|
31
|
+
__privateAdd(this, _lastLocation, void 0);
|
32
|
+
__privateAdd(this, _paramsCache, new UrlParamsCache());
|
33
|
+
__privateAdd(this, _onStateChanged, ({ payload }) => {
|
27
34
|
const changedObject = payload.changedObject;
|
28
35
|
if (changedObject.urlSync) {
|
29
36
|
const newUrlState = changedObject.urlSync.getUrlState();
|
30
37
|
const searchParams = locationService.getSearch();
|
31
38
|
const mappedUpdated = {};
|
32
|
-
this._urlKeyMapper.rebuildIndex(this._sceneRoot);
|
33
39
|
for (const [key, newUrlValue] of Object.entries(newUrlState)) {
|
34
|
-
const uniqueKey = this
|
40
|
+
const uniqueKey = __privateGet(this, _urlKeyMapper).getUniqueKey(key, changedObject);
|
35
41
|
const currentUrlValue = searchParams.getAll(uniqueKey);
|
36
42
|
if (!isUrlValueEqual(currentUrlValue, newUrlValue)) {
|
37
43
|
mappedUpdated[uniqueKey] = newUrlValue;
|
38
44
|
}
|
39
45
|
}
|
40
46
|
if (Object.keys(mappedUpdated).length > 0) {
|
41
|
-
|
47
|
+
writeSceneLog("UrlSyncManager", "onStateChange updating URL");
|
42
48
|
locationService.partial(mappedUpdated, true);
|
49
|
+
__privateSet(this, _lastLocation, locationService.getLocation());
|
43
50
|
}
|
44
51
|
}
|
45
|
-
};
|
52
|
+
});
|
46
53
|
}
|
47
54
|
initSync(root) {
|
48
|
-
|
49
|
-
|
50
|
-
|
55
|
+
var _a;
|
56
|
+
if (__privateGet(this, _stateSub)) {
|
57
|
+
writeSceneLog("UrlSyncManager", "Unregister previous scene state subscription", (_a = __privateGet(this, _sceneRoot)) == null ? void 0 : _a.state.key);
|
58
|
+
__privateGet(this, _stateSub).unsubscribe();
|
51
59
|
}
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
this
|
57
|
-
this.
|
58
|
-
this._stateSub = root.subscribeToEvent(SceneObjectStateChangedEvent, this._onStateChanged);
|
59
|
-
this.syncFrom(this._sceneRoot);
|
60
|
+
writeSceneLog("UrlSyncManager", "init", root.state.key);
|
61
|
+
__privateSet(this, _sceneRoot, root);
|
62
|
+
__privateSet(this, _stateSub, root.subscribeToEvent(SceneObjectStateChangedEvent, __privateGet(this, _onStateChanged)));
|
63
|
+
__privateGet(this, _urlKeyMapper).clear();
|
64
|
+
__privateSet(this, _lastLocation, locationService.getLocation());
|
65
|
+
this.handleNewObject(__privateGet(this, _sceneRoot));
|
60
66
|
}
|
61
67
|
cleanUp(root) {
|
62
|
-
if (this
|
68
|
+
if (__privateGet(this, _sceneRoot) !== root) {
|
63
69
|
return;
|
64
70
|
}
|
65
71
|
writeSceneLog("UrlSyncManager", "Clean up");
|
66
|
-
if (this
|
67
|
-
this.
|
68
|
-
|
69
|
-
this._locationSub = null;
|
70
|
-
}
|
71
|
-
if (this._stateSub) {
|
72
|
-
this._stateSub.unsubscribe();
|
73
|
-
this._stateSub = null;
|
72
|
+
if (__privateGet(this, _stateSub)) {
|
73
|
+
__privateGet(this, _stateSub).unsubscribe();
|
74
|
+
__privateSet(this, _stateSub, null);
|
74
75
|
writeSceneLog(
|
75
76
|
"UrlSyncManager",
|
76
77
|
"Root deactived, unsub to state",
|
77
78
|
"same key",
|
78
|
-
this
|
79
|
+
__privateGet(this, _sceneRoot).state.key === root.state.key
|
79
80
|
);
|
80
81
|
}
|
82
|
+
__privateSet(this, _sceneRoot, void 0);
|
83
|
+
__privateSet(this, _lastLocation, void 0);
|
84
|
+
}
|
85
|
+
handleNewLocation(location) {
|
86
|
+
if (!__privateGet(this, _sceneRoot) || __privateGet(this, _lastLocation) === location) {
|
87
|
+
return;
|
88
|
+
}
|
89
|
+
writeSceneLog("UrlSyncManager", "handleNewLocation");
|
90
|
+
__privateSet(this, _lastLocation, location);
|
91
|
+
syncStateFromUrl(__privateGet(this, _sceneRoot), __privateGet(this, _paramsCache).getParams(), __privateGet(this, _urlKeyMapper));
|
81
92
|
}
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
93
|
+
handleNewObject(sceneObj) {
|
94
|
+
if (!__privateGet(this, _sceneRoot)) {
|
95
|
+
return;
|
96
|
+
}
|
97
|
+
syncStateFromUrl(sceneObj, __privateGet(this, _paramsCache).getParams(), __privateGet(this, _urlKeyMapper));
|
86
98
|
}
|
87
99
|
getUrlState(root) {
|
88
100
|
return getUrlState(root);
|
89
101
|
}
|
90
102
|
}
|
103
|
+
_urlKeyMapper = new WeakMap();
|
104
|
+
_sceneRoot = new WeakMap();
|
105
|
+
_stateSub = new WeakMap();
|
106
|
+
_lastLocation = new WeakMap();
|
107
|
+
_paramsCache = new WeakMap();
|
108
|
+
_onStateChanged = new WeakMap();
|
109
|
+
class UrlParamsCache {
|
110
|
+
constructor() {
|
111
|
+
__privateAdd(this, _cache, void 0);
|
112
|
+
__privateAdd(this, _location, void 0);
|
113
|
+
}
|
114
|
+
getParams() {
|
115
|
+
const location = locationService.getLocation();
|
116
|
+
if (__privateGet(this, _location) === location) {
|
117
|
+
return __privateGet(this, _cache);
|
118
|
+
}
|
119
|
+
__privateSet(this, _location, location);
|
120
|
+
__privateSet(this, _cache, new URLSearchParams(location.search));
|
121
|
+
return __privateGet(this, _cache);
|
122
|
+
}
|
123
|
+
}
|
124
|
+
_cache = new WeakMap();
|
125
|
+
_location = new WeakMap();
|
91
126
|
let urlSyncManager;
|
92
127
|
function getUrlSyncManager() {
|
93
128
|
if (!urlSyncManager) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"UrlSyncManager.js","sources":["../../../src/services/UrlSyncManager.ts"],"sourcesContent":["import { Location
|
1
|
+
{"version":3,"file":"UrlSyncManager.js","sources":["../../../src/services/UrlSyncManager.ts"],"sourcesContent":["import { Location } from 'history';\n\nimport { locationService } from '@grafana/runtime';\n\nimport { SceneObjectStateChangedEvent } from '../core/events';\nimport { SceneObject, SceneObjectUrlValues } from '../core/types';\nimport { writeSceneLog } from '../utils/writeSceneLog';\nimport { Unsubscribable } from 'rxjs';\nimport { UniqueUrlKeyMapper } from './UniqueUrlKeyMapper';\nimport { getUrlState, isUrlValueEqual, syncStateFromUrl } from './utils';\n\nexport interface UrlSyncManagerLike {\n initSync(root: SceneObject): void;\n cleanUp(root: SceneObject): void;\n getUrlState(root: SceneObject): SceneObjectUrlValues;\n handleNewLocation(location: Location): void;\n handleNewObject(sceneObj: SceneObject): void;\n}\n\nexport class UrlSyncManager implements UrlSyncManagerLike {\n #urlKeyMapper = new UniqueUrlKeyMapper();\n #sceneRoot?: SceneObject;\n #stateSub: Unsubscribable | null = null;\n #lastLocation: Location | undefined;\n #paramsCache = new UrlParamsCache();\n\n /**\n * Updates the current scene state to match URL state.\n */\n public initSync(root: SceneObject) {\n if (this.#stateSub) {\n writeSceneLog('UrlSyncManager', 'Unregister previous scene state subscription', this.#sceneRoot?.state.key);\n this.#stateSub.unsubscribe();\n }\n\n writeSceneLog('UrlSyncManager', 'init', root.state.key);\n\n this.#sceneRoot = root;\n this.#stateSub = root.subscribeToEvent(SceneObjectStateChangedEvent, this.#onStateChanged);\n\n this.#urlKeyMapper.clear();\n this.#lastLocation = locationService.getLocation();\n\n this.handleNewObject(this.#sceneRoot);\n }\n\n public cleanUp(root: SceneObject) {\n // Ignore this if we have a new or different root\n if (this.#sceneRoot !== root) {\n return;\n }\n\n writeSceneLog('UrlSyncManager', 'Clean up');\n\n if (this.#stateSub) {\n this.#stateSub.unsubscribe();\n this.#stateSub = null;\n writeSceneLog(\n 'UrlSyncManager',\n 'Root deactived, unsub to state',\n 'same key',\n this.#sceneRoot.state.key === root.state.key\n );\n }\n\n this.#sceneRoot = undefined;\n this.#lastLocation = undefined;\n }\n\n public handleNewLocation(location: Location) {\n if (!this.#sceneRoot || this.#lastLocation === location) {\n return;\n }\n\n writeSceneLog('UrlSyncManager', 'handleNewLocation');\n\n this.#lastLocation = location;\n\n // Sync scene state tree from url\n syncStateFromUrl(this.#sceneRoot!, this.#paramsCache.getParams(), this.#urlKeyMapper);\n }\n\n public handleNewObject(sceneObj: SceneObject) {\n if (!this.#sceneRoot) {\n return;\n }\n\n syncStateFromUrl(sceneObj, this.#paramsCache.getParams(), this.#urlKeyMapper);\n }\n\n #onStateChanged = ({ payload }: SceneObjectStateChangedEvent) => {\n const changedObject = payload.changedObject;\n\n if (changedObject.urlSync) {\n const newUrlState = changedObject.urlSync.getUrlState();\n\n const searchParams = locationService.getSearch();\n const mappedUpdated: SceneObjectUrlValues = {};\n\n for (const [key, newUrlValue] of Object.entries(newUrlState)) {\n const uniqueKey = this.#urlKeyMapper.getUniqueKey(key, changedObject);\n const currentUrlValue = searchParams.getAll(uniqueKey);\n\n if (!isUrlValueEqual(currentUrlValue, newUrlValue)) {\n mappedUpdated[uniqueKey] = newUrlValue;\n }\n }\n\n if (Object.keys(mappedUpdated).length > 0) {\n writeSceneLog('UrlSyncManager', 'onStateChange updating URL');\n locationService.partial(mappedUpdated, true);\n\n /// Mark the location already handled\n this.#lastLocation = locationService.getLocation();\n }\n }\n };\n\n public getUrlState(root: SceneObject): SceneObjectUrlValues {\n return getUrlState(root);\n }\n}\n\nclass UrlParamsCache {\n #cache: URLSearchParams | undefined;\n #location: Location | undefined;\n\n public getParams(): URLSearchParams {\n const location = locationService.getLocation();\n\n if (this.#location === location) {\n return this.#cache!;\n }\n\n this.#location = location;\n this.#cache = new URLSearchParams(location.search);\n\n return this.#cache;\n }\n}\n\nlet urlSyncManager: UrlSyncManagerLike | undefined;\n\nexport function getUrlSyncManager(): UrlSyncManagerLike {\n if (!urlSyncManager) {\n urlSyncManager = new UrlSyncManager();\n }\n\n return urlSyncManager;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAA,aAAA,EAAA,UAAA,EAAA,SAAA,EAAA,aAAA,EAAA,YAAA,EAAA,eAAA,EAAA,MAAA,EAAA,SAAA,CAAA;AAmBO,MAAM,cAA6C,CAAA;AAAA,EAAnD,WAAA,GAAA;AACL,IAAA,YAAA,CAAA,IAAA,EAAA,aAAA,EAAgB,IAAI,kBAAmB,EAAA,CAAA,CAAA;AACvC,IAAA,YAAA,CAAA,IAAA,EAAA,UAAA,EAAA,KAAA,CAAA,CAAA,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{ useState, useEffect } from 'react';
|
2
|
+
import { useLocation } from 'react-router-dom';
|
3
|
+
import { getUrlSyncManager } from './UrlSyncManager.js';
|
4
|
+
import { locationService } from '@grafana/runtime';
|
5
|
+
|
6
|
+
function useUrlSync(sceneRoot) {
|
7
|
+
const urlSyncManager = getUrlSyncManager();
|
8
|
+
const location = useLocation();
|
9
|
+
const [isInitialized, setIsInitialized] = useState(false);
|
10
|
+
useEffect(() => {
|
11
|
+
urlSyncManager.initSync(sceneRoot);
|
12
|
+
setIsInitialized(true);
|
13
|
+
return () => urlSyncManager.cleanUp(sceneRoot);
|
14
|
+
}, [sceneRoot, urlSyncManager]);
|
15
|
+
useEffect(() => {
|
16
|
+
const latestLocation = locationService.getLocation();
|
17
|
+
const locationToHandle = latestLocation !== location ? latestLocation : location;
|
18
|
+
if (latestLocation !== location) {
|
19
|
+
console.log("latestLocation different from location");
|
20
|
+
}
|
21
|
+
urlSyncManager.handleNewLocation(locationToHandle);
|
22
|
+
}, [sceneRoot, urlSyncManager, location]);
|
23
|
+
return isInitialized;
|
24
|
+
}
|
25
|
+
|
26
|
+
export { useUrlSync };
|
27
|
+
//# sourceMappingURL=useUrlSync.js.map
|