optimise and extract behaviour to separate file

This commit is contained in:
Sergej-Vlasov committed 2024-04-09 13:34:21 +03:00
1 parent 6b7c4413b1
commit 7774685afe
2 files changed
+20 -10

No files matched your search

@@ -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();
};
});
};
@@ -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