mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* 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
51 lines
1.5 KiB
TypeScript
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);
|
|
});
|
|
}
|