mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Dashboards: Fix issue where filtered panels would not react to variable changes (#98718)
* Make sure we activate the parent and tree even if current panel is active * force activate full scene object tree --------- Co-authored-by: Sergej-Vlasov <sergej.s.vlasov@gmail.com>
This commit is contained in:
parent
9e8c1acd00
commit
56be39ed4f
@ -7,7 +7,7 @@ import { SceneGridRow, VizPanel, sceneGraph } from '@grafana/scenes';
|
||||
import { useStyles2 } from '@grafana/ui';
|
||||
import { Trans } from 'app/core/internationalization';
|
||||
|
||||
import { activateSceneObjectAndParentTree } from '../utils/utils';
|
||||
import { forceActivateFullSceneObjectTree } from '../utils/utils';
|
||||
|
||||
import { DashboardScene } from './DashboardScene';
|
||||
import { DashboardGridItem } from './layout-default/DashboardGridItem';
|
||||
@ -65,7 +65,13 @@ export function PanelSearchLayout({ dashboard, panelSearch = '', panelsPerRow }:
|
||||
}
|
||||
|
||||
function PanelSearchHit({ panel }: { panel: VizPanel }) {
|
||||
useEffect(() => activateSceneObjectAndParentTree(panel), [panel]);
|
||||
useEffect(() => {
|
||||
const deactivate = forceActivateFullSceneObjectTree(panel);
|
||||
|
||||
return () => {
|
||||
deactivate?.();
|
||||
};
|
||||
}, [panel]);
|
||||
|
||||
return <panel.Component model={panel} />;
|
||||
}
|
||||
|
@ -275,6 +275,34 @@ export function activateSceneObjectAndParentTree(so: SceneObject): CancelActivat
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Adaptation of activateSceneObjectAndParentTree specific for PanelSearchLayout use case with
|
||||
* with panelSearch and panelsPerRow custom panel filtering logic.
|
||||
*
|
||||
* Activating the whole tree because dashboard does not react to variable updates such as panel repeats
|
||||
*/
|
||||
export function forceActivateFullSceneObjectTree(so: SceneObject): CancelActivationHandler | undefined {
|
||||
let cancel: CancelActivationHandler | undefined;
|
||||
let parentCancel: CancelActivationHandler | undefined;
|
||||
|
||||
if (so.parent) {
|
||||
parentCancel = forceActivateFullSceneObjectTree(so.parent);
|
||||
}
|
||||
|
||||
if (!so.isActive) {
|
||||
cancel = so.activate();
|
||||
return () => {
|
||||
parentCancel?.();
|
||||
cancel?.();
|
||||
};
|
||||
}
|
||||
|
||||
return () => {
|
||||
parentCancel?.();
|
||||
cancel?.();
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use activateSceneObjectAndParentTree instead.
|
||||
* Activates any inactive ancestors of the scene object.
|
||||
|
Loading…
Reference in New Issue
Block a user