[v11.4.x] Dashboards: Fix issue where filtered panels would not react to variable changes (#98734)
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>
(cherry picked from commit 56be39ed4f)
This commit is contained in:
@@ -7,7 +7,7 @@ import { SceneGridRow, VizPanel, sceneGraph } from '@grafana/scenes';
|
||||
import { useStyles2 } from '@grafana/ui';
|
||||
import { Trans } from 'app/core/internationalization';
|
||||
|
||||
import { activateInActiveParents } from '../utils/utils';
|
||||
import { forceActivateFullSceneObjectTree } from '../utils/utils';
|
||||
|
||||
import { DashboardGridItem } from './DashboardGridItem';
|
||||
import { DashboardScene } from './DashboardScene';
|
||||
@@ -65,7 +65,13 @@ export function PanelSearchLayout({ dashboard, panelSearch = '', panelsPerRow }:
|
||||
}
|
||||
|
||||
function PanelSearchHit({ panel }: { panel: VizPanel }) {
|
||||
useEffect(() => activateInActiveParents(panel), [panel]);
|
||||
useEffect(() => {
|
||||
const deactivate = forceActivateFullSceneObjectTree(panel);
|
||||
|
||||
return () => {
|
||||
deactivate?.();
|
||||
};
|
||||
}, [panel]);
|
||||
|
||||
return <panel.Component model={panel} />;
|
||||
}
|
||||
|
||||
@@ -277,3 +277,31 @@ export function activateInActiveParents(so: SceneObject): CancelActivationHandle
|
||||
cancel();
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 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?.();
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user