[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)
pull/98747/head
Oscar Kilhed 6 months ago committed by GitHub
parent ed927a143c
commit 49ea20d027
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 { useStyles2 } from '@grafana/ui';
import { Trans } from 'app/core/internationalization'; import { Trans } from 'app/core/internationalization';
import { activateInActiveParents } from '../utils/utils'; import { forceActivateFullSceneObjectTree } from '../utils/utils';
import { DashboardGridItem } from './DashboardGridItem'; import { DashboardGridItem } from './DashboardGridItem';
import { DashboardScene } from './DashboardScene'; import { DashboardScene } from './DashboardScene';
@ -65,7 +65,13 @@ export function PanelSearchLayout({ dashboard, panelSearch = '', panelsPerRow }:
} }
function PanelSearchHit({ panel }: { panel: VizPanel }) { function PanelSearchHit({ panel }: { panel: VizPanel }) {
useEffect(() => activateInActiveParents(panel), [panel]); useEffect(() => {
const deactivate = forceActivateFullSceneObjectTree(panel);
return () => {
deactivate?.();
};
}, [panel]);
return <panel.Component model={panel} />; return <panel.Component model={panel} />;
} }

@ -277,3 +277,31 @@ export function activateInActiveParents(so: SceneObject): CancelActivationHandle
cancel(); 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?.();
};
}

Loading…
Cancel
Save