Scenes: Repeat horizontally set the width to 24 even if repeat variable is not set (#89658)

This commit is contained in:
Ivan Ortega Alba 2024-06-25 14:10:00 +02:00 committed by GitHub
parent df4b280134
commit 6773f7f4ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 44 additions and 4 deletions

View File

@ -504,6 +504,47 @@ describe('transformSaveModelToScene', () => {
expect(repeater.state.maxPerRow).toBe(8);
});
it('When horizontal repeat is set should modify the width to 24', () => {
const panel = {
title: '',
type: 'text-plugin-34',
gridPos: { x: 0, y: 0, w: 8, h: 8 },
repeat: 'server',
repeatDirection: 'h',
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 horizontal repeat is NOT fully configured should not modify the width', () => {
const panel = {
title: '',
type: 'text-plugin-34',
gridPos: { x: 0, y: 0, w: 8, h: 8 },
repeatDirection: 'h',
maxPerRow: 8,
};
const gridItem = buildGridItemForPanel(new PanelModel(panel));
const repeater = gridItem as DashboardGridItem;
expect(repeater.state.maxPerRow).toBe(8);
expect(repeater.state.variableName).toBe(undefined);
expect(repeater.state.width).toBe(8);
expect(repeater.state.height).toBe(8);
expect(repeater.state.repeatDirection).toBe(undefined);
expect(repeater.state.maxPerRow).toBe(8);
});
it('should apply query caching options to SceneQueryRunner', () => {
const panel = {
title: '',

View File

@ -443,11 +443,10 @@ export function buildGridItemForLibPanel(panel: PanelModel) {
}
export function buildGridItemForPanel(panel: PanelModel): DashboardGridItem {
const repeatDirection: RepeatDirection = panel.repeatDirection === 'h' ? 'h' : 'v';
const repeatOptions = panel.repeat
const repeatOptions: Partial<{ variableName: string; repeatDirection: RepeatDirection }> = panel.repeat
? {
variableName: panel.repeat,
repeatDirection,
repeatDirection: panel.repeatDirection === 'h' ? 'h' : 'v',
}
: {};
@ -501,7 +500,7 @@ export function buildGridItemForPanel(panel: PanelModel): DashboardGridItem {
key: `grid-item-${panel.id}`,
x: panel.gridPos.x,
y: panel.gridPos.y,
width: repeatDirection === 'h' ? 24 : panel.gridPos.w,
width: repeatOptions.repeatDirection === 'h' ? 24 : panel.gridPos.w,
height: panel.gridPos.h,
itemHeight: panel.gridPos.h,
body,