diff --git a/public/app/features/dashboard-scene/scene/LibraryVizPanel.tsx b/public/app/features/dashboard-scene/scene/LibraryVizPanel.tsx index 379a5ba1b4a..b5ab559f343 100644 --- a/public/app/features/dashboard-scene/scene/LibraryVizPanel.tsx +++ b/public/app/features/dashboard-scene/scene/LibraryVizPanel.tsx @@ -84,15 +84,16 @@ export class LibraryVizPanel extends SceneObjectBase { const panel = new VizPanel(vizPanelState); const gridItem = this.parent; + if (libPanelModel.repeat && gridItem instanceof SceneGridItem && gridItem.parent instanceof SceneGridLayout) { this._parent = undefined; const repeater = new PanelRepeaterGridItem({ key: gridItem.state.key, - x: libPanelModel.gridPos.x, - y: libPanelModel.gridPos.y, - width: libPanelModel.repeatDirection === 'h' ? 24 : libPanelModel.gridPos.w, - height: libPanelModel.gridPos.h, - itemHeight: libPanelModel.gridPos.h, + x: gridItem.state.x, + y: gridItem.state.y, + width: libPanelModel.repeatDirection === 'h' ? 24 : gridItem.state.width, + height: gridItem.state.height, + itemHeight: gridItem.state.height, source: this, variableName: libPanelModel.repeat, repeatedPanels: [], diff --git a/public/app/features/dashboard-scene/scene/PanelRepeaterGridItem.test.tsx b/public/app/features/dashboard-scene/scene/PanelRepeaterGridItem.test.tsx index ae74628a711..ea1a3647908 100644 --- a/public/app/features/dashboard-scene/scene/PanelRepeaterGridItem.test.tsx +++ b/public/app/features/dashboard-scene/scene/PanelRepeaterGridItem.test.tsx @@ -98,7 +98,7 @@ describe('PanelRepeaterGridItem', () => { expect(repeater.state.itemHeight).toBe(5); }); - it('When updating variable should update repeats', async () => { + it('Should update repeats when updating variable', async () => { const { scene, repeater, variable } = buildPanelRepeaterScene({ variableQueryTime: 0 }); activateFullSceneTree(scene); @@ -107,4 +107,13 @@ describe('PanelRepeaterGridItem', () => { expect(repeater.state.repeatedPanels?.length).toBe(2); }); + + it('Should fall back to default variable if specified variable cannot be found', () => { + const { scene, repeater } = buildPanelRepeaterScene({ variableQueryTime: 0 }); + scene.setState({ $variables: undefined }); + activateFullSceneTree(scene); + expect(repeater.state.repeatedPanels?.[0].state.$variables?.state.variables[0].state.name).toBe( + '_____default_sys_repeat_var_____' + ); + }); }); diff --git a/public/app/features/dashboard-scene/scene/PanelRepeaterGridItem.tsx b/public/app/features/dashboard-scene/scene/PanelRepeaterGridItem.tsx index 631ecda727d..48745d21ad7 100644 --- a/public/app/features/dashboard-scene/scene/PanelRepeaterGridItem.tsx +++ b/public/app/features/dashboard-scene/scene/PanelRepeaterGridItem.tsx @@ -14,6 +14,7 @@ import { sceneGraph, MultiValueVariable, LocalValueVariable, + CustomVariable, } from '@grafana/scenes'; import { GRID_CELL_HEIGHT, GRID_CELL_VMARGIN } from 'app/core/constants'; @@ -84,11 +85,15 @@ export class PanelRepeaterGridItem extends SceneObjectBase