grafana / scenes

Build Grafana dashboards directly in your Grafana app plugins.
https://grafana.com/developers/scenes
Apache License 2.0
141 stars 21 forks source link

ScenesReact: Use new react components and hooks from inside existing EmbeddedScenes #777

Closed torkelo closed 5 months ago

torkelo commented 5 months ago

Use case

Example:

export function getInteropDemo(defaults: SceneAppPageState) {
  return new SceneAppPage({
    ...defaults,
    subTitle: 'Testing using the hooks and plain react components from normal scene',
    getScene: () => {
      return new EmbeddedSceneWithContext({
        ...getEmbeddedSceneDefaults(),
        key: 'Flex layout embedded scene',
        body: new SceneFlexLayout({
          direction: 'column',
          children: [
            new SceneFlexItem({
              body: new VizPanel({
                title: 'Graph',
                pluginId: 'timeseries',
                $data: getQueryRunnerWithRandomWalkQuery({}),
              }),
            }),
            new SceneFlexItem({
              body: new CustomSceneObject({}),
            }),
          ],
        }),
      });
    },
  });
}

class CustomSceneObject extends SceneObjectBase<SceneObjectState> {
  static Component = ({ model }: SceneComponentProps<CustomSceneObject>) => {
    const [timeRange, _] = useTimeRange();

    return (
      <Stack direction="column">
        <div>Time hook: {timeRange.from.toString()}</div>
        <DemoVizLayout>
          <PlainGraphWithRandomWalk title="Visualization using React VizPanel with data from useQueryRunner" />
        </DemoVizLayout>
      </Stack>
    );
  };
}
grafanabot commented 5 months ago

:rocket: PR was released in v5.1.0 :rocket: