diff --git a/public/app/features/dashboard-scene/scene/hoverHeaderOffsetBehavior.ts b/public/app/features/dashboard-scene/scene/hoverHeaderOffsetBehavior.ts new file mode 100644 index 00000000000..b7b06f4e060 --- /dev/null +++ b/public/app/features/dashboard-scene/scene/hoverHeaderOffsetBehavior.ts @@ -0,0 +1,19 @@ +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(); + }; + }); +}; diff --git a/public/app/features/dashboard-scene/serialization/transformSaveModelToScene.ts b/public/app/features/dashboard-scene/serialization/transformSaveModelToScene.ts index e1258ae363d..68286638784 100644 --- a/public/app/features/dashboard-scene/serialization/transformSaveModelToScene.ts +++ b/public/app/features/dashboard-scene/serialization/transformSaveModelToScene.ts @@ -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'; @@ -475,16 +476,6 @@ export function buildGridItemForLibPanel(panel: PanelModel) { }); } -const hoverHeaderOffsetBehavior = (grid: DashboardGridItem) => { - grid.subscribeToState(() => { - grid.forEachChild((child) => { - if (child instanceof VizPanel && child.state.hoverHeader) { - child.setState({ hoverHeaderOffset: grid.state.y === 0 ? 0 : undefined }); - } - }); - }); -}; - export function buildGridItemForPanel(panel: PanelModel): DashboardGridItem { const repeatDirection: RepeatDirection = panel.repeatDirection === 'h' ? 'h' : 'v'; const repeatOptions = panel.repeat