From 0bf9d68070ff5d1b267328563afba1568a422d6b Mon Sep 17 00:00:00 2001 From: Victor Marin <36818606+mdvictor@users.noreply.github.com> Date: Thu, 28 Nov 2024 14:26:36 +0200 Subject: [PATCH] DashboardScene: Fix layout issues with repeated panels when `repeatDirection` is missing (#97149) fix --- .../transformSaveModelToScene.test.ts | 20 +++++++++++++++++++ .../transformSaveModelToScene.ts | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/public/app/features/dashboard-scene/serialization/transformSaveModelToScene.test.ts b/public/app/features/dashboard-scene/serialization/transformSaveModelToScene.test.ts index 39f84f3480b..ad063c17fb1 100644 --- a/public/app/features/dashboard-scene/serialization/transformSaveModelToScene.test.ts +++ b/public/app/features/dashboard-scene/serialization/transformSaveModelToScene.test.ts @@ -660,6 +660,26 @@ describe('transformSaveModelToScene', () => { expect(vizPanel.state.$data).toBeUndefined(); }); + it('When repeat is set but repeatDirection is not it should default to horizontal repeat', () => { + const panel = { + title: '', + type: 'text-plugin-34', + gridPos: { x: 0, y: 0, w: 8, h: 8 }, + repeat: 'server', + maxPerRow: 8, + }; + + const gridItem = buildGridItemForPanel(new PanelModel(panel)); + const repeater = gridItem as DashboardGridItem; + + expect(repeater.state.maxPerRow).toBe(8); + expect(repeater.state.variableName).toBe('server'); + expect(repeater.state.width).toBe(24); + expect(repeater.state.height).toBe(8); + expect(repeater.state.repeatDirection).toBe('h'); + expect(repeater.state.maxPerRow).toBe(8); + }); + it('When repeat is set should build PanelRepeaterGridItem', () => { const panel = { title: '', diff --git a/public/app/features/dashboard-scene/serialization/transformSaveModelToScene.ts b/public/app/features/dashboard-scene/serialization/transformSaveModelToScene.ts index a63312a9f81..ba05dff82c9 100644 --- a/public/app/features/dashboard-scene/serialization/transformSaveModelToScene.ts +++ b/public/app/features/dashboard-scene/serialization/transformSaveModelToScene.ts @@ -283,7 +283,7 @@ export function buildGridItemForPanel(panel: PanelModel): DashboardGridItem { const repeatOptions: Partial<{ variableName: string; repeatDirection: RepeatDirection }> = panel.repeat ? { variableName: panel.repeat, - repeatDirection: panel.repeatDirection === 'h' ? 'h' : 'v', + repeatDirection: panel.repeatDirection === 'v' ? 'v' : 'h', } : {};