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>
pull/98729/head
Oscar Kilhed 4 months ago committed by GitHub
parent 9e8c1acd00
commit 56be39ed4f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 10
      public/app/features/dashboard-scene/scene/PanelSearchLayout.tsx
  2. 28
      public/app/features/dashboard-scene/utils/utils.ts

@ -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…
Cancel
Save