From de59956db4dfc840adec8a79404d4b68bc2451df Mon Sep 17 00:00:00 2001 From: Sergej-Vlasov <37613182+Sergej-Vlasov@users.noreply.github.com> Date: Fri, 20 Jun 2025 09:28:52 +0100 Subject: [PATCH] Undo/Redo: add support for variable repeat options (#106617) * add undo support for panel repeat variable change * add undo support for panel repeat direction and max per row * i18n * adjust actions naming --- .../layout-auto-grid/AutoGridItemEditor.tsx | 10 ++- .../DashboardGridItemEditor.tsx | 64 +++++++++++++------ public/locales/en-US/grafana.json | 3 + 3 files changed, 58 insertions(+), 19 deletions(-) diff --git a/public/app/features/dashboard-scene/scene/layout-auto-grid/AutoGridItemEditor.tsx b/public/app/features/dashboard-scene/scene/layout-auto-grid/AutoGridItemEditor.tsx index 63a224e4d37..dc20ec7a8bd 100644 --- a/public/app/features/dashboard-scene/scene/layout-auto-grid/AutoGridItemEditor.tsx +++ b/public/app/features/dashboard-scene/scene/layout-auto-grid/AutoGridItemEditor.tsx @@ -4,6 +4,7 @@ import { OptionsPaneItemDescriptor } from 'app/features/dashboard/components/Pan import { RepeatRowSelect2 } from 'app/features/dashboard/components/RepeatRowSelect/RepeatRowSelect'; import { useConditionalRenderingEditor } from '../../conditional-rendering/ConditionalRenderingEditor'; +import { dashboardEditActions } from '../../edit-pane/shared'; import { AutoGridItem } from './AutoGridItem'; @@ -37,7 +38,14 @@ function RepeatByOption({ item, id }: { item: AutoGridItem; id?: string }) { id={id} sceneContext={item} repeat={variableName} - onChange={(value?: string) => item.setRepeatByVariable(value)} + onChange={(value?: string) => { + dashboardEditActions.edit({ + description: t('dashboard.edit-actions.panel-repeat-variable', 'Panel repeat by'), + source: item, + perform: () => item.setRepeatByVariable(value), + undo: () => item.setRepeatByVariable(variableName), + }); + }} /> ); } diff --git a/public/app/features/dashboard-scene/scene/layout-default/DashboardGridItemEditor.tsx b/public/app/features/dashboard-scene/scene/layout-default/DashboardGridItemEditor.tsx index 1da05331002..3b18200fadc 100644 --- a/public/app/features/dashboard-scene/scene/layout-default/DashboardGridItemEditor.tsx +++ b/public/app/features/dashboard-scene/scene/layout-default/DashboardGridItemEditor.tsx @@ -1,3 +1,5 @@ +import { useCallback } from 'react'; + import { SelectableValue } from '@grafana/data'; import { t } from '@grafana/i18n'; import { sceneGraph, SceneGridLayout } from '@grafana/scenes'; @@ -6,6 +8,8 @@ import { OptionsPaneCategoryDescriptor } from 'app/features/dashboard/components import { OptionsPaneItemDescriptor } from 'app/features/dashboard/components/PanelEditor/OptionsPaneItemDescriptor'; import { RepeatRowSelect2 } from 'app/features/dashboard/components/RepeatRowSelect/RepeatRowSelect'; +import { dashboardEditActions } from '../../edit-pane/shared'; + import { DashboardGridItem } from './DashboardGridItem'; export function getDashboardGridItemOptions(gridItem: DashboardGridItem): OptionsPaneCategoryDescriptor[] { @@ -65,7 +69,14 @@ function RepeatDirectionOption({ gridItem }: OptionComponentProps) { gridItem.setRepeatDirection(value)} + onChange={(value) => { + dashboardEditActions.edit({ + description: t('dashboard.edit-actions.panel-repeat-direction', 'Repeat direction'), + source: gridItem, + perform: () => gridItem.setRepeatDirection(value), + undo: () => gridItem.setRepeatDirection(repeatDirection ?? 'h'), + }); + }} /> ); } @@ -81,7 +92,14 @@ function MaxPerRowOption({ gridItem }: OptionComponentProps) {