Files
grafana/public/app/features/dashboard-scene/utils/utils.ts
Torkel Ödegaard 412e545503 DashboardScene: Support for discard, start at transform back to save model and save drawer (#73873)
* SceneDashboard: Discard changes now works

* To save model works and start at save drawer

* Update

* Added missing file

* Refactorings to keep responsibility more logical

* Refactorings

* Removed file

* Fixed state issue

* Update

* Update
2023-08-29 14:17:55 +02:00

51 lines
1.5 KiB
TypeScript

import { SceneDeactivationHandler, SceneObject } from '@grafana/scenes';
export function getVizPanelKeyForPanelId(panelId: number) {
return `panel-${panelId}`;
}
export function getPanelIdForVizPanelKey(key: string) {
return parseInt(key.replace('panel-', ''), 10);
}
/**
* Useful from tests to simulate mounting a full scene. Children are activated before parents to simulate the real order
* of React mount order and useEffect ordering.
*
*/
export function activateFullSceneTree(scene: SceneObject): SceneDeactivationHandler {
const deactivationHandlers: SceneDeactivationHandler[] = [];
scene.forEachChild((child) => {
deactivationHandlers.push(activateFullSceneTree(child));
});
deactivationHandlers.push(scene.activate());
return () => {
for (const handler of deactivationHandlers) {
handler();
}
};
}
/**
* Force re-render children. This is useful in some edge case scenarios when
* children deep down the scene graph needs to be re-rendered when some parent state change.
*
* Example could be isEditing bool flag or a layout IsDraggable state flag.
*
* @param model The model whose children should be re-rendered. It does not force render this model, only the children.
* @param recursive if it should keep force rendering down to leaf nodess
*/
export function forceRenderChildren(model: SceneObject, recursive?: boolean) {
model.forEachChild((child) => {
if (!child.isActive) {
return;
}
child.forceRender();
forceRenderChildren(child, recursive);
});
}