Skip to content

Commit

Permalink
Dashboards: Fix issue where filtered panels would not react to variab…
Browse files Browse the repository at this point in the history
…le changes (grafana#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 <[email protected]>
  • Loading branch information
oscarkilhed and Sergej-Vlasov authored Jan 9, 2025
1 parent 9e8c1ac commit 56be39e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
10 changes: 8 additions & 2 deletions public/app/features/dashboard-scene/scene/PanelSearchLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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} />;
}
Expand Down
28 changes: 28 additions & 0 deletions public/app/features/dashboard-scene/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 56be39e

Please sign in to comment.