diff --git a/public/app/features/scenes/SceneEmbeddedPage.tsx b/public/app/features/scenes/SceneEmbeddedPage.tsx index 5728ffa7c0c..7b7b2c06500 100644 --- a/public/app/features/scenes/SceneEmbeddedPage.tsx +++ b/public/app/features/scenes/SceneEmbeddedPage.tsx @@ -10,15 +10,16 @@ import { getSceneByTitle } from './scenes'; export interface Props extends GrafanaRouteComponentProps<{ name: string }> {} export const SceneEmbeddedPage = (props: Props) => { - const scene = getSceneByTitle(props.match.params.name, false); + const scene = getSceneByTitle(props.match.params.name); if (!scene) { return

Scene not found

; } const pageNav: NavModelItem = { - text: scene.state.title, + text: 'Embedded Scene', }; + return ( diff --git a/public/app/features/scenes/SceneListPage.tsx b/public/app/features/scenes/SceneListPage.tsx index 6518394f78d..33078f91313 100644 --- a/public/app/features/scenes/SceneListPage.tsx +++ b/public/app/features/scenes/SceneListPage.tsx @@ -3,7 +3,7 @@ import React from 'react'; import { useAsync } from 'react-use'; import { Stack } from '@grafana/experimental'; -import { Card, LinkButton } from '@grafana/ui'; +import { Card } from '@grafana/ui'; import { Page } from 'app/core/components/Page/Page'; // Types @@ -26,16 +26,8 @@ export const SceneListPage = ({}: Props) => {
Test scenes
{scenes.map((scene) => ( - + {scene.title} - - - Open as standalone scene - - - Open as embedded scene - - ))} diff --git a/public/app/features/scenes/ScenePage.tsx b/public/app/features/scenes/ScenePage.tsx index 92587896aee..b755d11491b 100644 --- a/public/app/features/scenes/ScenePage.tsx +++ b/public/app/features/scenes/ScenePage.tsx @@ -1,5 +1,5 @@ // Libraries -import React from 'react'; +import React, { useEffect, useState } from 'react'; import { GrafanaRouteComponentProps } from 'app/core/navigation/types'; @@ -8,12 +8,24 @@ import { getSceneByTitle } from './scenes'; export interface Props extends GrafanaRouteComponentProps<{ name: string }> {} export const ScenePage = (props: Props) => { - const scene = getSceneByTitle(props.match.params.name, true); + const scene = getSceneByTitle(props.match.params.name); + const [isInitialized, setInitialized] = useState(false); + + useEffect(() => { + if (scene && !isInitialized) { + scene.initUrlSync(); + setInitialized(true); + } + }, [isInitialized, scene]); if (!scene) { return

Scene not found

; } + if (!isInitialized) { + return null; + } + return ; }; diff --git a/public/app/features/scenes/components/Scene.test.tsx b/public/app/features/scenes/components/Scene.test.tsx deleted file mode 100644 index b6138fca279..00000000000 --- a/public/app/features/scenes/components/Scene.test.tsx +++ /dev/null @@ -1,16 +0,0 @@ -import { SceneFlexLayout } from '@grafana/scenes'; - -import { Scene } from './Scene'; - -describe('Scene', () => { - it('Simple scene', () => { - const scene = new Scene({ - title: 'Hello', - body: new SceneFlexLayout({ - children: [], - }), - }); - - expect(scene.state.title).toBe('Hello'); - }); -}); diff --git a/public/app/features/scenes/components/Scene.tsx b/public/app/features/scenes/components/Scene.tsx deleted file mode 100644 index 18857af0438..00000000000 --- a/public/app/features/scenes/components/Scene.tsx +++ /dev/null @@ -1,59 +0,0 @@ -import React from 'react'; - -import { PageLayoutType } from '@grafana/data'; -import { config } from '@grafana/runtime'; -import { SceneObjectBase, SceneComponentProps, SceneState, UrlSyncManager } from '@grafana/scenes'; -import { PageToolbar, ToolbarButton } from '@grafana/ui'; -import { AppChromeUpdate } from 'app/core/components/AppChrome/AppChromeUpdate'; -import { Page } from 'app/core/components/Page/Page'; - -export class Scene extends SceneObjectBase { - public static Component = SceneRenderer; - private urlSyncManager?: UrlSyncManager; - - public activate() { - super.activate(); - this.urlSyncManager = new UrlSyncManager(this); - this.urlSyncManager.initSync(); - } - - public deactivate() { - super.deactivate(); - this.urlSyncManager!.cleanUp(); - } -} - -function SceneRenderer({ model }: SceneComponentProps) { - const { title, body, actions = [], isEditing, $editor, subMenu } = model.useState(); - - const toolbarActions = (actions ?? []).map((action) => ); - - if ($editor) { - toolbarActions.push( - model.setState({ isEditing: !model.state.isEditing })} - /> - ); - } - - const pageToolbar = config.featureToggles.topnav ? ( - - ) : ( - {toolbarActions} - ); - - return ( - -
- {subMenu && } -
- - {$editor && <$editor.Component model={$editor} isEditing={isEditing} />} -
-
-
- ); -} diff --git a/public/app/features/scenes/dashboard/DashboardScene.tsx b/public/app/features/scenes/dashboard/DashboardScene.tsx index dc88bf95a05..5990086af42 100644 --- a/public/app/features/scenes/dashboard/DashboardScene.tsx +++ b/public/app/features/scenes/dashboard/DashboardScene.tsx @@ -1,25 +1,25 @@ +import { css } from '@emotion/css'; import React from 'react'; -import { PageLayoutType } from '@grafana/data'; +import { GrafanaTheme2, PageLayoutType } from '@grafana/data'; import { config, locationService } from '@grafana/runtime'; import { UrlSyncManager, SceneObjectBase, SceneComponentProps, - SceneLayout, SceneObject, SceneObjectStatePlain, } from '@grafana/scenes'; -import { PageToolbar, ToolbarButton } from '@grafana/ui'; +import { PageToolbar, ToolbarButton, useStyles2 } from '@grafana/ui'; import { AppChromeUpdate } from 'app/core/components/AppChrome/AppChromeUpdate'; import { Page } from 'app/core/components/Page/Page'; interface DashboardSceneState extends SceneObjectStatePlain { title: string; - uid: string; - body: SceneLayout; + uid?: string; + body: SceneObject; actions?: SceneObject[]; - subMenu?: SceneObject; + controls?: SceneObject[]; } export class DashboardScene extends SceneObjectBase { @@ -48,7 +48,8 @@ export class DashboardScene extends SceneObjectBase { } function DashboardSceneRenderer({ model }: SceneComponentProps) { - const { title, body, actions = [], uid, subMenu } = model.useState(); + const { title, body, actions = [], uid, controls } = model.useState(); + const styles = useStyles2(getStyles); const toolbarActions = (actions ?? []).map((action) => ); @@ -63,10 +64,31 @@ function DashboardSceneRenderer({ model }: SceneComponentProps) return ( - {subMenu && } -
+ {controls && ( +
+ {controls.map((control) => ( + + ))} +
+ )} +
); } + +function getStyles(theme: GrafanaTheme2) { + return { + body: css({ + flexGrow: 1, + display: 'flex', + gap: '8px', + }), + controls: css({ + display: 'flex', + gap: theme.spacing(1), + alignItems: 'center', + }), + }; +} diff --git a/public/app/features/scenes/dashboard/DashboardsLoader.test.ts b/public/app/features/scenes/dashboard/DashboardsLoader.test.ts index 63e672ace35..8684e5d2b3a 100644 --- a/public/app/features/scenes/dashboard/DashboardsLoader.test.ts +++ b/public/app/features/scenes/dashboard/DashboardsLoader.test.ts @@ -135,7 +135,7 @@ describe('DashboardLoader', () => { expect(scene.state.uid).toBe('test-uid'); expect(scene.state?.$timeRange?.state.value.raw).toEqual(dash.time); expect(scene.state?.$variables?.state.variables).toHaveLength(1); - expect(scene.state.subMenu).toBeDefined(); + expect(scene.state.controls).toBeDefined(); }); }); @@ -162,9 +162,10 @@ describe('DashboardLoader', () => { const oldModel = new DashboardModel(dashboard); const scene = createDashboardSceneFromDashboardModel(oldModel); + const body = scene.state.body as SceneGridLayout; - expect(scene.state.body.state.children).toHaveLength(1); - const rowScene = scene.state.body.state.children[0] as SceneGridRow; + expect(body.state.children).toHaveLength(1); + const rowScene = body.state.children[0] as SceneGridRow; expect(rowScene).toBeInstanceOf(SceneGridRow); expect(rowScene.state.title).toEqual(row.title); expect(rowScene.state.placement?.y).toEqual(row.gridPos!.y); @@ -226,16 +227,17 @@ describe('DashboardLoader', () => { const oldModel = new DashboardModel(dashboard); const scene = createDashboardSceneFromDashboardModel(oldModel); + const body = scene.state.body as SceneGridLayout; - expect(scene.state.body.state.children).toHaveLength(3); - expect(scene.state.body).toBeInstanceOf(SceneGridLayout); + expect(body.state.children).toHaveLength(3); + expect(body).toBeInstanceOf(SceneGridLayout); // Panel out of row - expect(scene.state.body.state.children[0]).toBeInstanceOf(VizPanel); - const panelOutOfRowVizPanel = scene.state.body.state.children[0] as VizPanel; + expect(body.state.children[0]).toBeInstanceOf(VizPanel); + const panelOutOfRowVizPanel = body.state.children[0] as VizPanel; expect(panelOutOfRowVizPanel.state.title).toBe(panelOutOfRow.title); // Row with panel - expect(scene.state.body.state.children[1]).toBeInstanceOf(SceneGridRow); - const rowWithPanelsScene = scene.state.body.state.children[1] as SceneGridRow; + expect(body.state.children[1]).toBeInstanceOf(SceneGridRow); + const rowWithPanelsScene = body.state.children[1] as SceneGridRow; expect(rowWithPanelsScene.state.title).toBe(rowWithPanel.title); expect(rowWithPanelsScene.state.children).toHaveLength(1); // Panel within row @@ -243,8 +245,8 @@ describe('DashboardLoader', () => { const panelInRowVizPanel = rowWithPanelsScene.state.children[0] as VizPanel; expect(panelInRowVizPanel.state.title).toBe(panelInRow.title); // Empty row - expect(scene.state.body.state.children[2]).toBeInstanceOf(SceneGridRow); - const emptyRowScene = scene.state.body.state.children[2] as SceneGridRow; + expect(body.state.children[2]).toBeInstanceOf(SceneGridRow); + const emptyRowScene = body.state.children[2] as SceneGridRow; expect(emptyRowScene.state.title).toBe(emptyRow.title); expect(emptyRowScene.state.children).toHaveLength(0); }); diff --git a/public/app/features/scenes/dashboard/DashboardsLoader.ts b/public/app/features/scenes/dashboard/DashboardsLoader.ts index d2bcd4de2a7..bd19241d56e 100644 --- a/public/app/features/scenes/dashboard/DashboardsLoader.ts +++ b/public/app/features/scenes/dashboard/DashboardsLoader.ts @@ -13,7 +13,6 @@ import { SceneTimeRange, SceneObject, SceneQueryRunner, - SceneSubMenu, SceneVariableSet, VariableValueSelectors, SceneVariable, @@ -150,7 +149,6 @@ export function createSceneObjectsForPanels(oldPanels: PanelModel[]): SceneObjec } export function createDashboardSceneFromDashboardModel(oldModel: DashboardModel) { - let subMenu: SceneSubMenu | undefined = undefined; let variables: SceneVariableSet | undefined = undefined; if (oldModel.templating.list.length) { @@ -166,9 +164,7 @@ export function createDashboardSceneFromDashboardModel(oldModel: DashboardModel) // TODO: Remove filter // Added temporarily to allow skipping non-compatible variables .filter((v): v is SceneVariable => Boolean(v)); - subMenu = new SceneSubMenu({ - children: [new VariableValueSelectors({})], - }); + variables = new SceneVariableSet({ variables: variableObjects, }); @@ -183,7 +179,9 @@ export function createDashboardSceneFromDashboardModel(oldModel: DashboardModel) $timeRange: new SceneTimeRange(oldModel.time), actions: [new SceneTimePicker({})], $variables: variables, - subMenu, + ...(variables && { + controls: [new VariableValueSelectors({})], + }), }); } diff --git a/public/app/features/scenes/scenes/demo.tsx b/public/app/features/scenes/scenes/demo.tsx index bf63f63c019..489e3088a23 100644 --- a/public/app/features/scenes/scenes/demo.tsx +++ b/public/app/features/scenes/scenes/demo.tsx @@ -6,18 +6,17 @@ import { VizPanel, SceneCanvasText, SceneToolbarInput, - EmbeddedScene, SceneDataNode, } from '@grafana/scenes'; import { panelBuilders } from '../builders/panelBuilders'; -import { Scene } from '../components/Scene'; +import { DashboardScene } from '../dashboard/DashboardScene'; import { SceneEditManager } from '../editor/SceneEditManager'; import { getQueryRunnerWithRandomWalkQuery } from './queries'; -export function getFlexLayoutTest(standalone: boolean): Scene | EmbeddedScene { - const state = { +export function getFlexLayoutTest(): DashboardScene { + return new DashboardScene({ title: 'Flex layout test', body: new SceneFlexLayout({ direction: 'row', @@ -63,19 +62,17 @@ export function getFlexLayoutTest(standalone: boolean): Scene | EmbeddedScene { $timeRange: new SceneTimeRange(), $data: getQueryRunnerWithRandomWalkQuery(), actions: [new SceneTimePicker({})], - }; - - return standalone ? new Scene(state) : new EmbeddedScene(state); + }); } -export function getScenePanelRepeaterTest(standalone: boolean): Scene | EmbeddedScene { +export function getScenePanelRepeaterTest(): DashboardScene { const queryRunner = getQueryRunnerWithRandomWalkQuery({ seriesCount: 2, alias: '__server_names', scenarioId: 'random_walk', }); - const state = { + return new DashboardScene({ title: 'Panel repeater test', body: new SceneByFrameRepeater({ body: new SceneFlexLayout({ @@ -133,7 +130,5 @@ export function getScenePanelRepeaterTest(standalone: boolean): Scene | Embedded }), new SceneTimePicker({}), ], - }; - - return standalone ? new Scene(state) : new EmbeddedScene(state); + }); } diff --git a/public/app/features/scenes/scenes/grid.tsx b/public/app/features/scenes/scenes/grid.tsx index 6cbfce18580..4b7e85e9aa3 100644 --- a/public/app/features/scenes/scenes/grid.tsx +++ b/public/app/features/scenes/scenes/grid.tsx @@ -1,19 +1,12 @@ -import { - VizPanel, - SceneTimePicker, - SceneFlexLayout, - SceneGridLayout, - SceneTimeRange, - EmbeddedScene, -} from '@grafana/scenes'; +import { VizPanel, SceneTimePicker, SceneFlexLayout, SceneGridLayout, SceneTimeRange } from '@grafana/scenes'; -import { Scene } from '../components/Scene'; +import { DashboardScene } from '../dashboard/DashboardScene'; import { SceneEditManager } from '../editor/SceneEditManager'; import { getQueryRunnerWithRandomWalkQuery } from './queries'; -export function getGridLayoutTest(standalone: boolean): Scene | EmbeddedScene { - const state = { +export function getGridLayoutTest(): DashboardScene { + return new DashboardScene({ title: 'Grid layout test', body: new SceneGridLayout({ children: [ @@ -58,7 +51,5 @@ export function getGridLayoutTest(standalone: boolean): Scene | EmbeddedScene { $timeRange: new SceneTimeRange(), $data: getQueryRunnerWithRandomWalkQuery(), actions: [new SceneTimePicker({})], - }; - - return standalone ? new Scene(state) : new EmbeddedScene(state); + }); } diff --git a/public/app/features/scenes/scenes/gridMultiTimeRange.tsx b/public/app/features/scenes/scenes/gridMultiTimeRange.tsx index dc856427bb2..052f5ee9903 100644 --- a/public/app/features/scenes/scenes/gridMultiTimeRange.tsx +++ b/public/app/features/scenes/scenes/gridMultiTimeRange.tsx @@ -1,25 +1,18 @@ -import { - VizPanel, - SceneGridRow, - SceneTimePicker, - SceneGridLayout, - SceneTimeRange, - EmbeddedScene, -} from '@grafana/scenes'; +import { VizPanel, SceneGridRow, SceneTimePicker, SceneGridLayout, SceneTimeRange } from '@grafana/scenes'; -import { Scene } from '../components/Scene'; +import { DashboardScene } from '../dashboard/DashboardScene'; import { SceneEditManager } from '../editor/SceneEditManager'; import { getQueryRunnerWithRandomWalkQuery } from './queries'; -export function getGridWithMultipleTimeRanges(standalone: boolean): Scene | EmbeddedScene { +export function getGridWithMultipleTimeRanges(): DashboardScene { const globalTimeRange = new SceneTimeRange(); const row1TimeRange = new SceneTimeRange({ from: 'now-1y', to: 'now', }); - const state = { + return new DashboardScene({ title: 'Grid with rows and different queries and time ranges', body: new SceneGridLayout({ children: [ @@ -66,7 +59,5 @@ export function getGridWithMultipleTimeRanges(standalone: boolean): Scene | Embe $timeRange: globalTimeRange, $data: getQueryRunnerWithRandomWalkQuery(), actions: [new SceneTimePicker({})], - }; - - return standalone ? new Scene(state) : new EmbeddedScene(state); + }); } diff --git a/public/app/features/scenes/scenes/gridMultiple.tsx b/public/app/features/scenes/scenes/gridMultiple.tsx index bfd49bc6e00..76cb257b203 100644 --- a/public/app/features/scenes/scenes/gridMultiple.tsx +++ b/public/app/features/scenes/scenes/gridMultiple.tsx @@ -1,19 +1,12 @@ -import { - VizPanel, - SceneTimePicker, - SceneFlexLayout, - SceneGridLayout, - SceneTimeRange, - EmbeddedScene, -} from '@grafana/scenes'; +import { VizPanel, SceneTimePicker, SceneFlexLayout, SceneGridLayout, SceneTimeRange } from '@grafana/scenes'; -import { Scene } from '../components/Scene'; +import { DashboardScene } from '../dashboard/DashboardScene'; import { SceneEditManager } from '../editor/SceneEditManager'; import { getQueryRunnerWithRandomWalkQuery } from './queries'; -export function getMultipleGridLayoutTest(standalone: boolean): Scene | EmbeddedScene { - const state = { +export function getMultipleGridLayoutTest(): DashboardScene { + return new DashboardScene({ title: 'Multiple grid layouts test', body: new SceneFlexLayout({ children: [ @@ -98,7 +91,5 @@ export function getMultipleGridLayoutTest(standalone: boolean): Scene | Embedded $timeRange: new SceneTimeRange(), $data: getQueryRunnerWithRandomWalkQuery(), actions: [new SceneTimePicker({})], - }; - - return standalone ? new Scene(state) : new EmbeddedScene(state); + }); } diff --git a/public/app/features/scenes/scenes/gridWithMultipleData.tsx b/public/app/features/scenes/scenes/gridWithMultipleData.tsx index 683d118932b..051c539c61a 100644 --- a/public/app/features/scenes/scenes/gridWithMultipleData.tsx +++ b/public/app/features/scenes/scenes/gridWithMultipleData.tsx @@ -1,19 +1,12 @@ -import { - VizPanel, - SceneGridRow, - SceneTimePicker, - SceneGridLayout, - SceneTimeRange, - EmbeddedScene, -} from '@grafana/scenes'; +import { VizPanel, SceneGridRow, SceneTimePicker, SceneGridLayout, SceneTimeRange } from '@grafana/scenes'; -import { Scene } from '../components/Scene'; +import { DashboardScene } from '../dashboard/DashboardScene'; import { SceneEditManager } from '../editor/SceneEditManager'; import { getQueryRunnerWithRandomWalkQuery } from './queries'; -export function getGridWithMultipleData(standalone: boolean): Scene | EmbeddedScene { - const state = { +export function getGridWithMultipleData(): DashboardScene { + return new DashboardScene({ title: 'Grid with rows and different queries', body: new SceneGridLayout({ children: [ @@ -93,7 +86,5 @@ export function getGridWithMultipleData(standalone: boolean): Scene | EmbeddedSc $timeRange: new SceneTimeRange(), $data: getQueryRunnerWithRandomWalkQuery(), actions: [new SceneTimePicker({})], - }; - - return standalone ? new Scene(state) : new EmbeddedScene(state); + }); } diff --git a/public/app/features/scenes/scenes/gridWithRow.tsx b/public/app/features/scenes/scenes/gridWithRow.tsx index d3739040722..8f3c7f09500 100644 --- a/public/app/features/scenes/scenes/gridWithRow.tsx +++ b/public/app/features/scenes/scenes/gridWithRow.tsx @@ -1,19 +1,12 @@ -import { - VizPanel, - SceneGridLayout, - SceneGridRow, - SceneTimePicker, - SceneTimeRange, - EmbeddedScene, -} from '@grafana/scenes'; +import { VizPanel, SceneGridLayout, SceneGridRow, SceneTimePicker, SceneTimeRange } from '@grafana/scenes'; -import { Scene } from '../components/Scene'; +import { DashboardScene } from '../dashboard/DashboardScene'; import { SceneEditManager } from '../editor/SceneEditManager'; import { getQueryRunnerWithRandomWalkQuery } from './queries'; -export function getGridWithRowLayoutTest(standalone: boolean): Scene | EmbeddedScene { - const state = { +export function getGridWithRowLayoutTest(): DashboardScene { + return new DashboardScene({ title: 'Grid with row layout test', body: new SceneGridLayout({ children: [ @@ -76,7 +69,5 @@ export function getGridWithRowLayoutTest(standalone: boolean): Scene | EmbeddedS $timeRange: new SceneTimeRange(), $data: getQueryRunnerWithRandomWalkQuery(), actions: [new SceneTimePicker({})], - }; - - return standalone ? new Scene(state) : new EmbeddedScene(state); + }); } diff --git a/public/app/features/scenes/scenes/gridWithRows.tsx b/public/app/features/scenes/scenes/gridWithRows.tsx index c3bde62bb1f..ad1c871d35d 100644 --- a/public/app/features/scenes/scenes/gridWithRows.tsx +++ b/public/app/features/scenes/scenes/gridWithRows.tsx @@ -7,12 +7,11 @@ import { SceneTimeRange, } from '@grafana/scenes'; -import { Scene } from '../components/Scene'; -import { SceneEditManager } from '../editor/SceneEditManager'; +import { DashboardScene } from '../dashboard/DashboardScene'; import { getQueryRunnerWithRandomWalkQuery } from './queries'; -export function getGridWithRowsTest(): Scene { +export function getGridWithRowsTest(): DashboardScene { const panel = new VizPanel({ pluginId: 'timeseries', title: 'Fill height', @@ -77,12 +76,12 @@ export function getGridWithRowsTest(): Scene { }), ], }); - const scene = new Scene({ + + const scene = new DashboardScene({ title: 'Grid rows test', body: new SceneGridLayout({ children: [cell1, cell2, row1, row2], }), - $editor: new SceneEditManager({}), $timeRange: new SceneTimeRange(), $data: getQueryRunnerWithRandomWalkQuery(), actions: [new SceneTimePicker({})], diff --git a/public/app/features/scenes/scenes/index.tsx b/public/app/features/scenes/scenes/index.tsx index bdb94daebe4..f398ff1a2ae 100644 --- a/public/app/features/scenes/scenes/index.tsx +++ b/public/app/features/scenes/scenes/index.tsx @@ -1,6 +1,4 @@ -import { EmbeddedScene, SceneObjectBase, SceneState } from '@grafana/scenes'; - -import { Scene } from '../components/Scene'; +import { DashboardScene } from '../dashboard/DashboardScene'; import { getFlexLayoutTest, getScenePanelRepeaterTest } from './demo'; import { getGridLayoutTest } from './grid'; @@ -16,7 +14,7 @@ import { getVariablesDemo, getVariablesDemoWithAll } from './variablesDemo'; interface SceneDef { title: string; - getScene: (standalone: boolean) => Scene | EmbeddedScene; + getScene: () => DashboardScene; } export function getScenes(): SceneDef[] { return [ @@ -36,20 +34,18 @@ export function getScenes(): SceneDef[] { ]; } -const cache: Record }> = {}; +const cache: Record = {}; -export function getSceneByTitle(title: string, standalone = true) { +export function getSceneByTitle(title: string) { if (cache[title]) { - if (cache[title].standalone === standalone) { - return cache[title].scene; - } + return cache[title]; } const scene = getScenes().find((x) => x.title === title); if (scene) { - cache[title] = { scene: scene.getScene(standalone), standalone }; + cache[title] = scene.getScene(); } - return cache[title].scene; + return cache[title]; } diff --git a/public/app/features/scenes/scenes/nested.tsx b/public/app/features/scenes/scenes/nested.tsx index 9243a1c1abc..7ac0056e3e8 100644 --- a/public/app/features/scenes/scenes/nested.tsx +++ b/public/app/features/scenes/scenes/nested.tsx @@ -1,18 +1,11 @@ -import { - VizPanel, - NestedScene, - SceneTimePicker, - SceneFlexLayout, - SceneTimeRange, - EmbeddedScene, -} from '@grafana/scenes'; +import { VizPanel, NestedScene, SceneTimePicker, SceneFlexLayout, SceneTimeRange } from '@grafana/scenes'; -import { Scene } from '../components/Scene'; +import { DashboardScene } from '../dashboard/DashboardScene'; import { getQueryRunnerWithRandomWalkQuery } from './queries'; -export function getNestedScene(standalone: boolean): Scene | EmbeddedScene { - const state = { +export function getNestedScene(): DashboardScene { + return new DashboardScene({ title: 'Nested Scene demo', body: new SceneFlexLayout({ direction: 'column', @@ -28,9 +21,7 @@ export function getNestedScene(standalone: boolean): Scene | EmbeddedScene { $timeRange: new SceneTimeRange(), $data: getQueryRunnerWithRandomWalkQuery(), actions: [new SceneTimePicker({})], - }; - - return standalone ? new Scene(state) : new EmbeddedScene(state); + }); } export function getInnerScene(title: string) { diff --git a/public/app/features/scenes/scenes/queryVariableDemo.tsx b/public/app/features/scenes/scenes/queryVariableDemo.tsx index 4eb211d8d59..69fd91ded75 100644 --- a/public/app/features/scenes/scenes/queryVariableDemo.tsx +++ b/public/app/features/scenes/scenes/queryVariableDemo.tsx @@ -1,7 +1,6 @@ import { VariableRefresh } from '@grafana/data'; import { SceneCanvasText, - SceneSubMenu, SceneTimePicker, SceneFlexLayout, SceneTimeRange, @@ -10,13 +9,12 @@ import { CustomVariable, DataSourceVariable, QueryVariable, - EmbeddedScene, } from '@grafana/scenes'; -import { Scene } from '../components/Scene'; +import { DashboardScene } from '../dashboard/DashboardScene'; -export function getQueryVariableDemo(standalone: boolean): Scene | EmbeddedScene { - const state = { +export function getQueryVariableDemo(): DashboardScene { + return new DashboardScene({ title: 'Query variable', $variables: new SceneVariableSet({ variables: [ @@ -65,10 +63,6 @@ export function getQueryVariableDemo(standalone: boolean): Scene | EmbeddedScene }), $timeRange: new SceneTimeRange(), actions: [new SceneTimePicker({})], - subMenu: new SceneSubMenu({ - children: [new VariableValueSelectors({})], - }), - }; - - return standalone ? new Scene(state) : new EmbeddedScene(state); + controls: [new VariableValueSelectors({})], + }); } diff --git a/public/app/features/scenes/scenes/sceneWithRows.tsx b/public/app/features/scenes/scenes/sceneWithRows.tsx index c7d5d7f4f1f..51e4352129b 100644 --- a/public/app/features/scenes/scenes/sceneWithRows.tsx +++ b/public/app/features/scenes/scenes/sceneWithRows.tsx @@ -1,19 +1,12 @@ -import { - VizPanel, - NestedScene, - SceneTimePicker, - SceneFlexLayout, - SceneTimeRange, - EmbeddedScene, -} from '@grafana/scenes'; +import { VizPanel, NestedScene, SceneTimePicker, SceneFlexLayout, SceneTimeRange } from '@grafana/scenes'; -import { Scene } from '../components/Scene'; +import { DashboardScene } from '../dashboard/DashboardScene'; import { SceneEditManager } from '../editor/SceneEditManager'; import { getQueryRunnerWithRandomWalkQuery } from './queries'; -export function getSceneWithRows(standalone: boolean): Scene | EmbeddedScene { - const state = { +export function getSceneWithRows(): DashboardScene { + return new DashboardScene({ title: 'Scene with rows', body: new SceneFlexLayout({ direction: 'column', @@ -60,7 +53,5 @@ export function getSceneWithRows(standalone: boolean): Scene | EmbeddedScene { $timeRange: new SceneTimeRange(), $data: getQueryRunnerWithRandomWalkQuery(), actions: [new SceneTimePicker({})], - }; - - return standalone ? new Scene(state) : new EmbeddedScene(state); + }); } diff --git a/public/app/features/scenes/scenes/transformations.tsx b/public/app/features/scenes/scenes/transformations.tsx index 739f88c820f..d8c5a08f335 100644 --- a/public/app/features/scenes/scenes/transformations.tsx +++ b/public/app/features/scenes/scenes/transformations.tsx @@ -1,19 +1,11 @@ -import { - SceneTimePicker, - SceneFlexLayout, - VizPanel, - SceneDataTransformer, - SceneTimeRange, - EmbeddedScene, -} from '@grafana/scenes'; +import { SceneTimePicker, SceneFlexLayout, VizPanel, SceneDataTransformer, SceneTimeRange } from '@grafana/scenes'; -import { Scene } from '../components/Scene'; -import { SceneEditManager } from '../editor/SceneEditManager'; +import { DashboardScene } from '../dashboard/DashboardScene'; import { getQueryRunnerWithRandomWalkQuery } from './queries'; -export function getTransformationsDemo(standalone: boolean): Scene | EmbeddedScene { - const state = { +export function getTransformationsDemo(): DashboardScene { + return new DashboardScene({ title: 'Transformations demo', body: new SceneFlexLayout({ direction: 'row', @@ -63,11 +55,8 @@ export function getTransformationsDemo(standalone: boolean): Scene | EmbeddedSce }), ], }), - $editor: new SceneEditManager({}), $timeRange: new SceneTimeRange(), $data: getQueryRunnerWithRandomWalkQuery(), actions: [new SceneTimePicker({})], - }; - - return standalone ? new Scene(state) : new EmbeddedScene(state); + }); } diff --git a/public/app/features/scenes/scenes/variablesDemo.tsx b/public/app/features/scenes/scenes/variablesDemo.tsx index 14547e4302d..aae86008f13 100644 --- a/public/app/features/scenes/scenes/variablesDemo.tsx +++ b/public/app/features/scenes/scenes/variablesDemo.tsx @@ -1,7 +1,6 @@ import { VizPanel, SceneCanvasText, - SceneSubMenu, SceneTimePicker, SceneFlexLayout, SceneTimeRange, @@ -10,15 +9,14 @@ import { CustomVariable, DataSourceVariable, TestVariable, - EmbeddedScene, } from '@grafana/scenes'; -import { Scene } from '../components/Scene'; +import { DashboardScene } from '../dashboard/DashboardScene'; import { getQueryRunnerWithRandomWalkQuery } from './queries'; -export function getVariablesDemo(standalone: boolean): Scene | EmbeddedScene { - const state = { +export function getVariablesDemo(): DashboardScene { + return new DashboardScene({ title: 'Variables', $variables: new SceneVariableSet({ variables: [ @@ -82,16 +80,12 @@ export function getVariablesDemo(standalone: boolean): Scene | EmbeddedScene { }), $timeRange: new SceneTimeRange(), actions: [new SceneTimePicker({})], - subMenu: new SceneSubMenu({ - children: [new VariableValueSelectors({})], - }), - }; - - return standalone ? new Scene(state) : new EmbeddedScene(state); + controls: [new VariableValueSelectors({})], + }); } -export function getVariablesDemoWithAll(): Scene { - const scene = new Scene({ +export function getVariablesDemoWithAll(): DashboardScene { + return new DashboardScene({ title: 'Variables with All values', $variables: new SceneVariableSet({ variables: [ @@ -153,10 +147,6 @@ export function getVariablesDemoWithAll(): Scene { }), $timeRange: new SceneTimeRange(), actions: [new SceneTimePicker({})], - subMenu: new SceneSubMenu({ - children: [new VariableValueSelectors({})], - }), + controls: [new VariableValueSelectors({})], }); - - return scene; } diff --git a/yarn.lock b/yarn.lock index 0fcfb12c7a8..cc831b0a19d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5121,8 +5121,8 @@ __metadata: linkType: soft "@grafana/scenes@npm:latest": - version: 0.0.5 - resolution: "@grafana/scenes@npm:0.0.5" + version: 0.0.8 + resolution: "@grafana/scenes@npm:0.0.8" dependencies: "@grafana/e2e-selectors": canary "@grafana/experimental": 1.0.1 @@ -5130,7 +5130,7 @@ __metadata: react-use: 17.4.0 react-virtualized-auto-sizer: 1.0.7 uuid: ^9.0.0 - checksum: 7388aaccb0788801f94734126d1abab71df3f81131eec41c967b0c462223a13fcfbc5a65ce7a45bf6761032d8efd1330cb85ac8e86136cba9e4dd244f41b1054 + checksum: 4c76ca9850906b98fc9131b48ea6a664f84a0f8ac5f7d87543d73f8ca8214c33483fc4454447e46d67096826f7cb32f3db70461323e65aefc241c4169c88fd98 languageName: node linkType: hard