DashboardScene: prevent panel hovel header crop with scenes (#85869)

* add behaviour that adjusts hoverHeaderOffset

* clean up behaviour logic

* optimise and extract behaviour to separate file

* fix hoverHeaderOffsetBehavior unsubscribe

* update to latest scenes version

* Fix PanelOptionsTest

* fix: test value for adhoc filter url param

* Fix transformation tab tests

* bump scenes version

* Revert "Fix transformation tab tests"

This reverts commit 3ec9f5b226.

---------

Co-authored-by: Dominik Prokop <dominik.prokop@grafana.com>
Co-authored-by: Darren Janeczek <darren.janeczek@grafana.com>
Co-authored-by: oscarkilhed <oscar.kilhed@grafana.com>
This commit is contained in:
Sergej-Vlasov
2024-04-10 20:39:43 +03:00
committed by GitHub
parent 212acb9bc5
commit 79631bdd15
6 changed files with 35 additions and 7 deletions

View File

@@ -22,6 +22,13 @@ jest.mock('react-router-dom', () => ({
}),
}));
jest.mock('@grafana/runtime', () => ({
...jest.requireActual('@grafana/runtime'),
getPluginImportUtils: () => ({
getPanelPluginFromCache: jest.fn(),
}),
}));
// Needed when the panel is not part of an DashboardScene
jest.spyOn(utils, 'getDashboardSceneFor').mockReturnValue(new DashboardScene({}));

View File

@@ -0,0 +1,18 @@
import { VizPanel } from '@grafana/scenes';
import { DashboardGridItem } from './DashboardGridItem';
export const hoverHeaderOffsetBehavior = (grid: DashboardGridItem) => {
const sub = grid.subscribeToState((newState, prevState) => {
if ([newState.y, prevState.y].includes(0) && newState.y !== prevState.y) {
grid.forEachChild((child) => {
if (child instanceof VizPanel && child.state.hoverHeader) {
child.setState({ hoverHeaderOffset: grid.state.y === 0 ? 0 : undefined });
}
});
}
});
return () => {
sub.unsubscribe();
};
};

View File

@@ -47,6 +47,7 @@ import { panelLinksBehavior, panelMenuBehavior } from '../scene/PanelMenuBehavio
import { PanelNotices } from '../scene/PanelNotices';
import { PanelTimeRange } from '../scene/PanelTimeRange';
import { RowRepeaterBehavior } from '../scene/RowRepeaterBehavior';
import { hoverHeaderOffsetBehavior } from '../scene/hoverHeaderOffsetBehavior';
import { RowActions } from '../scene/row-actions/RowActions';
import { setDashboardPanelContext } from '../scene/setDashboardPanelContext';
import { createPanelDataProvider } from '../utils/createPanelDataProvider';
@@ -506,6 +507,7 @@ export function buildGridItemForPanel(panel: PanelModel): DashboardGridItem {
displayMode: panel.transparent ? 'transparent' : undefined,
// To be replaced with it's own option persited option instead derived
hoverHeader: !panel.title && !panel.timeFrom && !panel.timeShift,
hoverHeaderOffset: (panel.gridPos?.y ?? 0) === 0 ? 0 : undefined,
$data: createPanelDataProvider(panel),
titleItems,
@@ -539,6 +541,7 @@ export function buildGridItemForPanel(panel: PanelModel): DashboardGridItem {
body,
maxPerRow: panel.maxPerRow,
...repeatOptions,
$behaviors: [hoverHeaderOffsetBehavior],
});
}

View File

@@ -136,7 +136,7 @@ describe('TrailStore', () => {
['to', 'now-30m'],
['var-ds', '1234'],
['var-groupby', 'job'],
['var-filters', 'test'],
['var-filters', 'cluster|=|dev-eu-west-2'],
])(`new recent trails with a different '%p' value should insert new entry`, (key, differentValue) => {
const store = getTrailStore();
// We expect the initialized trail to be there