mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-20 19:32:15 +00:00
feat(editor): Add undo/redo creating a node in new canvas (no-changelog) (#10142)
This commit is contained in:
@@ -395,11 +395,17 @@ export function useCanvasOperations({
|
||||
options: {
|
||||
dragAndDrop?: boolean;
|
||||
position?: XYPosition;
|
||||
trackHistory?: boolean;
|
||||
trackBulk?: boolean;
|
||||
} = {},
|
||||
) {
|
||||
let insertPosition = options.position;
|
||||
let lastAddedNode: INodeUi | undefined;
|
||||
|
||||
if (options.trackBulk) {
|
||||
historyStore.startRecordingUndo();
|
||||
}
|
||||
|
||||
for (const nodeAddData of nodes) {
|
||||
const { isAutoAdd, openDetail: openNDV, ...node } = nodeAddData;
|
||||
const position = node.position ?? insertPosition;
|
||||
@@ -414,7 +420,7 @@ export function useCanvasOperations({
|
||||
...options,
|
||||
openNDV,
|
||||
isAutoAdd,
|
||||
trackHistory: true,
|
||||
trackHistory: options.trackHistory,
|
||||
},
|
||||
);
|
||||
} catch (error) {
|
||||
@@ -433,6 +439,10 @@ export function useCanvasOperations({
|
||||
// @TODO Figure out what this does and why it's needed
|
||||
updatePositionForNodeWithMultipleInputs(lastAddedNode);
|
||||
}
|
||||
|
||||
if (options.trackBulk) {
|
||||
historyStore.stopRecordingUndo();
|
||||
}
|
||||
}
|
||||
|
||||
function updatePositionForNodeWithMultipleInputs(node: INodeUi) {
|
||||
@@ -507,6 +517,15 @@ export function useCanvasOperations({
|
||||
return nodeData;
|
||||
}
|
||||
|
||||
async function revertAddNode(nodeName: string) {
|
||||
const node = workflowsStore.getNodeByName(nodeName);
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
|
||||
deleteNode(node.id);
|
||||
}
|
||||
|
||||
function createConnectionToLastInteractedWithNode(node: INodeUi, options: AddNodeOptions = {}) {
|
||||
const lastInteractedWithNode = uiStore.lastInteractedWithNode;
|
||||
if (!lastInteractedWithNode) {
|
||||
@@ -1628,6 +1647,7 @@ export function useCanvasOperations({
|
||||
triggerNodes,
|
||||
addNodes,
|
||||
addNode,
|
||||
revertAddNode,
|
||||
updateNodePosition,
|
||||
setNodeActive,
|
||||
setNodeActiveByName,
|
||||
|
||||
Reference in New Issue
Block a user