DashboardScene: Fix layout issues with repeated panels when repeatDirection is missing (#97149)

fix
This commit is contained in:
Victor Marin
2024-11-28 14:26:36 +02:00
committed by GitHub
parent f6124344ba
commit 0bf9d68070
2 changed files with 21 additions and 1 deletions
@@ -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: '',
@@ -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',
}
: {};