2022-07-07 01:53:02 -05:00
|
|
|
// Libraries
|
2023-01-17 11:02:46 -06:00
|
|
|
import React, { useEffect, useState } from 'react';
|
2022-07-07 01:53:02 -05:00
|
|
|
|
2023-04-26 00:03:44 -05:00
|
|
|
import { getUrlSyncManager } from '@grafana/scenes';
|
2022-07-07 01:53:02 -05:00
|
|
|
import { GrafanaRouteComponentProps } from 'app/core/navigation/types';
|
|
|
|
|
|
|
|
import { getSceneByTitle } from './scenes';
|
|
|
|
|
|
|
|
export interface Props extends GrafanaRouteComponentProps<{ name: string }> {}
|
|
|
|
|
2023-01-05 11:55:55 -06:00
|
|
|
export const ScenePage = (props: Props) => {
|
2023-01-17 11:02:46 -06:00
|
|
|
const scene = getSceneByTitle(props.match.params.name);
|
|
|
|
const [isInitialized, setInitialized] = useState(false);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (scene && !isInitialized) {
|
2023-04-26 00:03:44 -05:00
|
|
|
getUrlSyncManager().initSync(scene);
|
2023-01-17 11:02:46 -06:00
|
|
|
setInitialized(true);
|
|
|
|
}
|
|
|
|
}, [isInitialized, scene]);
|
2022-07-07 01:53:02 -05:00
|
|
|
|
|
|
|
if (!scene) {
|
|
|
|
return <h2>Scene not found</h2>;
|
|
|
|
}
|
|
|
|
|
2023-01-17 11:02:46 -06:00
|
|
|
if (!isInitialized) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-07-14 13:52:03 -05:00
|
|
|
return <scene.Component model={scene} />;
|
2022-07-07 01:53:02 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
export default ScenePage;
|