diff --git a/public/app/features/dashboard-scene/scene/layout-auto-grid/AutoGridLayoutManager.tsx b/public/app/features/dashboard-scene/scene/layout-auto-grid/AutoGridLayoutManager.tsx index 12cd129773c..8e665bc524a 100644 --- a/public/app/features/dashboard-scene/scene/layout-auto-grid/AutoGridLayoutManager.tsx +++ b/public/app/features/dashboard-scene/scene/layout-auto-grid/AutoGridLayoutManager.tsx @@ -1,4 +1,5 @@ import { t } from '@grafana/i18n'; +import { config } from '@grafana/runtime'; import { SceneComponentProps, SceneObject, SceneObjectBase, SceneObjectState, VizPanel } from '@grafana/scenes'; import { Spec as DashboardV2Spec } from '@grafana/schema/dist/esm/schema/dashboard/v2alpha1/types.spec.gen'; import { GRID_CELL_VMARGIN } from 'app/core/constants'; @@ -117,8 +118,25 @@ export class AutoGridLayoutManager public pastePanel() { const panel = getAutoGridItemFromClipboard(getDashboardSceneFor(this)); - this.state.layout.setState({ children: [...this.state.layout.state.children, panel] }); - this.publishEvent(new NewObjectAddedToCanvasEvent(panel), true); + if (config.featureToggles.dashboardNewLayouts) { + dashboardEditActions.edit({ + description: t('dashboard.edit-actions.paste-panel', 'Paste panel'), + addedObject: panel.state.body, + source: this, + perform: () => { + this.state.layout.setState({ children: [...this.state.layout.state.children, panel] }); + }, + undo: () => { + this.state.layout.setState({ + children: this.state.layout.state.children.filter((child) => child !== panel), + }); + }, + }); + } else { + this.state.layout.setState({ children: [...this.state.layout.state.children, panel] }); + this.publishEvent(new NewObjectAddedToCanvasEvent(panel), true); + } + clearClipboard(); }