AutoGridLayoutManager: Add undo/redo functionality for pasting a panel (#108797)

This commit is contained in:
kay delaney
2025-07-29 11:20:39 +01:00
committed by GitHub
parent c32aaf63e8
commit df46b45a29
@@ -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();
}