mirror of https://github.com/grafana/grafana
Dashboard: Fixes rendering of repeating panels (#39991)
* Dashboard: Fixes rendering of repeating panels * Chore: update after PR commentspull/40260/head
parent
7706483654
commit
d8e97fc024
@ -0,0 +1,35 @@ |
||||
import { PanelModel } from './PanelModel'; |
||||
import { isOnTheSameGridRow } from './utils'; |
||||
import { REPEAT_DIR_HORIZONTAL } from '../../../core/constants'; |
||||
|
||||
describe('isOnTheSameGridRow', () => { |
||||
describe('when source panel is next to a panel', () => { |
||||
it('then it should return true', () => { |
||||
const sourcePanel: PanelModel = ({ gridPos: { x: 0, y: 1, w: 4, h: 4 } } as unknown) as PanelModel; |
||||
const otherPanel: PanelModel = ({ gridPos: { x: 4, y: 1, w: 4, h: 4 } } as unknown) as PanelModel; |
||||
|
||||
expect(isOnTheSameGridRow(sourcePanel, otherPanel)).toBe(true); |
||||
}); |
||||
}); |
||||
|
||||
describe('when source panel is not next to a panel', () => { |
||||
it('then it should return false', () => { |
||||
const sourcePanel: PanelModel = ({ gridPos: { x: 0, y: 1, w: 4, h: 4 } } as unknown) as PanelModel; |
||||
const otherPanel: PanelModel = ({ gridPos: { x: 4, y: 5, w: 4, h: 4 } } as unknown) as PanelModel; |
||||
|
||||
expect(isOnTheSameGridRow(sourcePanel, otherPanel)).toBe(false); |
||||
}); |
||||
}); |
||||
|
||||
describe('when source panel is repeated horizontally', () => { |
||||
it('then it should return false', () => { |
||||
const sourcePanel: PanelModel = ({ |
||||
gridPos: { x: 0, y: 1, w: 4, h: 4 }, |
||||
repeatDirection: REPEAT_DIR_HORIZONTAL, |
||||
} as unknown) as PanelModel; |
||||
const otherPanel: PanelModel = ({ gridPos: { x: 4, y: 1, w: 4, h: 4 } } as unknown) as PanelModel; |
||||
|
||||
expect(isOnTheSameGridRow(sourcePanel, otherPanel)).toBe(false); |
||||
}); |
||||
}); |
||||
}); |
||||
@ -0,0 +1,17 @@ |
||||
import { PanelModel } from './PanelModel'; |
||||
import { REPEAT_DIR_HORIZONTAL } from '../../../core/constants'; |
||||
|
||||
export function isOnTheSameGridRow(sourcePanel: PanelModel, otherPanel: PanelModel): boolean { |
||||
if (sourcePanel.repeatDirection === REPEAT_DIR_HORIZONTAL) { |
||||
return false; |
||||
} |
||||
|
||||
if ( |
||||
otherPanel.gridPos.x >= sourcePanel.gridPos.x + sourcePanel.gridPos.w && |
||||
otherPanel.gridPos.y === sourcePanel.gridPos.y |
||||
) { |
||||
return true; |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
Loading…
Reference in new issue