From 9cf8c4e89057ecb6f8d95ba2ba404abf0ae1ca76 Mon Sep 17 00:00:00 2001 From: "grafana-delivery-bot[bot]" <132647405+grafana-delivery-bot[bot]@users.noreply.github.com> Date: Thu, 28 Mar 2024 17:03:12 +0200 Subject: [PATCH] [v11.0.x] Scenes: Fix row crash when removing a panel from it (#85360) Scenes: Fix row crash when removing a panel from it (#85339) * Fix row crash when removing a panel from it * fix tests * fix tests (cherry picked from commit 30c930753903fb37925603662f40f00022b36df5) Co-authored-by: Victor Marin <36818606+mdvictor@users.noreply.github.com> --- .../app/features/dashboard-scene/scene/DashboardScene.test.tsx | 3 +++ public/app/features/dashboard-scene/scene/DashboardScene.tsx | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/public/app/features/dashboard-scene/scene/DashboardScene.test.tsx b/public/app/features/dashboard-scene/scene/DashboardScene.test.tsx index 98b0088aed5..fb8bb08a8bf 100644 --- a/public/app/features/dashboard-scene/scene/DashboardScene.test.tsx +++ b/public/app/features/dashboard-scene/scene/DashboardScene.test.tsx @@ -30,6 +30,7 @@ import { DashboardControls } from './DashboardControls'; import { DashboardGridItem } from './DashboardGridItem'; import { DashboardScene, DashboardSceneState } from './DashboardScene'; import { LibraryVizPanel } from './LibraryVizPanel'; +import { RowActions } from './row-actions/RowActions'; jest.mock('../settings/version-history/HistorySrv'); jest.mock('../serialization/transformSaveModelToScene'); @@ -535,6 +536,7 @@ describe('DashboardScene', () => { const body = scene.state.body as SceneGridLayout; const gridRow = body.state.children[2] as SceneGridRow; + expect(gridRow.state.children.length).toBe(1); }); @@ -888,6 +890,7 @@ function buildTestScene(overrides?: Partial) { }), new SceneGridRow({ key: 'panel-3', + actions: new RowActions({}), children: [ new DashboardGridItem({ body: new VizPanel({ diff --git a/public/app/features/dashboard-scene/scene/DashboardScene.tsx b/public/app/features/dashboard-scene/scene/DashboardScene.tsx index 1e786eeceec..f9f90ebf0a4 100644 --- a/public/app/features/dashboard-scene/scene/DashboardScene.tsx +++ b/public/app/features/dashboard-scene/scene/DashboardScene.tsx @@ -661,7 +661,7 @@ export class DashboardScene extends SceneObjectBase { } if (row) { - row.forEachChild((child: SceneObject) => { + row.state.children.forEach((child: SceneObject) => { if (child.state.key !== key) { panels.push(child); }