Chore: Rename activateInActiveParents -> activateSceneObjectAndParentTree (#95534)

* Activate parents of query runner when using dashboard ds

* Set plugin loading util to fix test because activating the ancestors of the query runner needs to be able to load the plugin for the panel

* Rename activateInActiveParents -> activateSceneObjectAndParentTree

* Add back but deprecate activeInActiveParents
This commit is contained in:
Oscar Kilhed 2024-10-30 09:55:16 +01:00 committed by GitHub
parent a20c9db6b7
commit 5673fafbfb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 18 additions and 11 deletions

View File

@ -24,7 +24,7 @@ import { getPanelChanges } from '../saving/getDashboardChanges';
import { DashboardGridItem, DashboardGridItemState } from '../scene/DashboardGridItem'; import { DashboardGridItem, DashboardGridItemState } from '../scene/DashboardGridItem';
import { vizPanelToPanel } from '../serialization/transformSceneToSaveModel'; import { vizPanelToPanel } from '../serialization/transformSceneToSaveModel';
import { import {
activateInActiveParents, activateSceneObjectAndParentTree,
getDashboardSceneFor, getDashboardSceneFor,
getLibraryPanelBehavior, getLibraryPanelBehavior,
getPanelIdForVizPanel, getPanelIdForVizPanel,
@ -68,7 +68,7 @@ export class PanelEditor extends SceneObjectBase<PanelEditorState> {
private _activationHandler() { private _activationHandler() {
const panel = this.state.panelRef.resolve(); const panel = this.state.panelRef.resolve();
const deactivateParents = activateInActiveParents(panel); const deactivateParents = activateSceneObjectAndParentTree(panel);
const layoutElement = panel.parent; const layoutElement = panel.parent;
this.waitForPlugin(); this.waitForPlugin();

View File

@ -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 { activateSceneObjectAndParentTree } from '../utils/utils';
import { DashboardGridItem } from './DashboardGridItem'; import { DashboardGridItem } from './DashboardGridItem';
import { DashboardScene } from './DashboardScene'; import { DashboardScene } from './DashboardScene';
@ -65,7 +65,7 @@ export function PanelSearchLayout({ dashboard, panelSearch = '', panelsPerRow }:
} }
function PanelSearchHit({ panel }: { panel: VizPanel }) { function PanelSearchHit({ panel }: { panel: VizPanel }) {
useEffect(() => activateInActiveParents(panel), [panel]); useEffect(() => activateSceneObjectAndParentTree(panel), [panel]);
return <panel.Component model={panel} />; return <panel.Component model={panel} />;
} }

View File

@ -1,6 +1,6 @@
import { SceneComponentProps, SceneObjectBase, SceneObjectRef, SceneObjectState, VizPanel } from '@grafana/scenes'; import { SceneComponentProps, SceneObjectBase, SceneObjectRef, SceneObjectState, VizPanel } from '@grafana/scenes';
import { activateInActiveParents } from '../utils/utils'; import { activateSceneObjectAndParentTree } from '../utils/utils';
interface ViewPanelSceneState extends SceneObjectState { interface ViewPanelSceneState extends SceneObjectState {
panelRef: SceneObjectRef<VizPanel>; panelRef: SceneObjectRef<VizPanel>;
@ -15,7 +15,7 @@ export class ViewPanelScene extends SceneObjectBase<ViewPanelSceneState> {
public _activationHandler() { public _activationHandler() {
const panel = this.state.panelRef.resolve(); const panel = this.state.panelRef.resolve();
return activateInActiveParents(panel); return activateSceneObjectAndParentTree(panel);
} }
public getUrlKey() { public getUrlKey() {

View File

@ -249,11 +249,11 @@ export function getLibraryPanelBehavior(vizPanel: VizPanel): LibraryPanelBehavio
} }
/** /**
* Activates any inactive parents of the scene object. * Activates any inactive ancestors of the scene object.
* Useful when rendering a scene object out of context of it's parent * Useful when rendering a scene object out of context of it's parent
* @returns * @returns
*/ */
export function activateInActiveParents(so: SceneObject): CancelActivationHandler | undefined { export function activateSceneObjectAndParentTree(so: SceneObject): CancelActivationHandler | undefined {
let cancel: CancelActivationHandler | undefined; let cancel: CancelActivationHandler | undefined;
let parentCancel: CancelActivationHandler | undefined; let parentCancel: CancelActivationHandler | undefined;
@ -262,7 +262,7 @@ export function activateInActiveParents(so: SceneObject): CancelActivationHandle
} }
if (so.parent) { if (so.parent) {
parentCancel = activateInActiveParents(so.parent); parentCancel = activateSceneObjectAndParentTree(so.parent);
} }
cancel = so.activate(); cancel = so.activate();
@ -272,3 +272,10 @@ export function activateInActiveParents(so: SceneObject): CancelActivationHandle
cancel(); cancel();
}; };
} }
/**
* @deprecated use activateSceneObjectAndParentTree instead.
* Activates any inactive ancestors of the scene object.
* Useful when rendering a scene object out of context of it's parent
*/
export const activateInActiveParents = activateSceneObjectAndParentTree;

View File

@ -10,7 +10,7 @@ import {
} from '@grafana/data'; } from '@grafana/data';
import { SceneDataProvider, SceneDataTransformer, SceneObject } from '@grafana/scenes'; import { SceneDataProvider, SceneDataTransformer, SceneObject } from '@grafana/scenes';
import { import {
activateInActiveParents, activateSceneObjectAndParentTree,
findVizPanelByKey, findVizPanelByKey,
getVizPanelKeyForPanelId, getVizPanelKeyForPanelId,
} from 'app/features/dashboard-scene/utils/utils'; } from 'app/features/dashboard-scene/utils/utils';
@ -73,7 +73,7 @@ export class DashboardDatasource extends DataSourceApi<DashboardQuery> {
sourceDataProvider?.setContainerWidth(500); sourceDataProvider?.setContainerWidth(500);
} }
const cleanUp = activateInActiveParents(sourceDataProvider!); const cleanUp = activateSceneObjectAndParentTree(sourceDataProvider!);
return sourceDataProvider!.getResultsStream!().pipe( return sourceDataProvider!.getResultsStream!().pipe(
map((result) => { map((result) => {