From 39b7d866603d9e59cf6d0198e307767eb5e7ef70 Mon Sep 17 00:00:00 2001 From: "Marc M." <146180665+grafakus@users.noreply.github.com> Date: Tue, 9 Dec 2025 10:23:44 +0100 Subject: [PATCH] Dashboards: support undo/redo when grouping panels (#114787) --- .../dashboard-scene/scene/layout-rows/RowItem.tsx | 14 +++++++++++++- .../dashboard-scene/scene/layout-tabs/TabItem.tsx | 14 +++++++++++++- public/locales/en-US/grafana.json | 2 ++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/public/app/features/dashboard-scene/scene/layout-rows/RowItem.tsx b/public/app/features/dashboard-scene/scene/layout-rows/RowItem.tsx index 4568db703d0..e3f3155497b 100644 --- a/public/app/features/dashboard-scene/scene/layout-rows/RowItem.tsx +++ b/public/app/features/dashboard-scene/scene/layout-rows/RowItem.tsx @@ -19,6 +19,7 @@ import kbn from 'app/core/utils/kbn'; import { ShowConfirmModalEvent } from 'app/types/events'; import { ConditionalRenderingGroup } from '../../conditional-rendering/group/ConditionalRenderingGroup'; +import { dashboardEditActions } from '../../edit-pane/shared'; import { serializeRow } from '../../serialization/layoutSerializers/RowsLayoutSerializer'; import { getElements } from '../../serialization/layoutSerializers/utils'; import { getDashboardSceneFor } from '../../utils/utils'; @@ -110,7 +111,18 @@ export class RowItem } public switchLayout(layout: DashboardLayoutManager) { - this.setState({ layout }); + const currentLayout = this.state.layout; + + dashboardEditActions.edit({ + description: t('dashboard.edit-actions.switch-layout-row', 'Switch layout'), + source: this, + perform: () => { + this.setState({ layout }); + }, + undo: () => { + this.setState({ layout: currentLayout }); + }, + }); } public useEditPaneOptions = useEditOptions.bind(this); diff --git a/public/app/features/dashboard-scene/scene/layout-tabs/TabItem.tsx b/public/app/features/dashboard-scene/scene/layout-tabs/TabItem.tsx index 8ee0b26633f..5bcaba4b140 100644 --- a/public/app/features/dashboard-scene/scene/layout-tabs/TabItem.tsx +++ b/public/app/features/dashboard-scene/scene/layout-tabs/TabItem.tsx @@ -19,6 +19,7 @@ import kbn from 'app/core/utils/kbn'; import { ShowConfirmModalEvent } from 'app/types/events'; import { ConditionalRenderingGroup } from '../../conditional-rendering/group/ConditionalRenderingGroup'; +import { dashboardEditActions } from '../../edit-pane/shared'; import { serializeTab } from '../../serialization/layoutSerializers/TabsLayoutSerializer'; import { getElements } from '../../serialization/layoutSerializers/utils'; import { getDashboardSceneFor } from '../../utils/utils'; @@ -108,7 +109,18 @@ export class TabItem } public switchLayout(layout: DashboardLayoutManager) { - this.setState({ layout }); + const currentLayout = this.state.layout; + + dashboardEditActions.edit({ + description: t('dashboard.edit-actions.switch-layout-tab', 'Switch layout'), + source: this, + perform: () => { + this.setState({ layout }); + }, + undo: () => { + this.setState({ layout: currentLayout }); + }, + }); } public useEditPaneOptions = useEditOptions.bind(this); diff --git a/public/locales/en-US/grafana.json b/public/locales/en-US/grafana.json index 701b3488b2e..295a9cd0ca8 100644 --- a/public/locales/en-US/grafana.json +++ b/public/locales/en-US/grafana.json @@ -4781,6 +4781,8 @@ "remove": "Remove {{typeName}}", "row-title": "Change row title", "switch-layout": "Switch layout", + "switch-layout-row": "Switch layout", + "switch-layout-tab": "Switch layout", "tab-title": "Change tab title" }, "edit-pane": {