mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 04:34:06 -08:00
feat(editor): Add undo/redo for importing workflow data on new canvas (no-changelog) (#11101)
This commit is contained in:
parent
d537cea363
commit
71e75e8a68
|
@ -1376,26 +1376,40 @@ export function useCanvasOperations({ router }: { router: ReturnType<typeof useR
|
|||
return targetNodeHasInputConnectionOfType;
|
||||
}
|
||||
|
||||
function addConnections(connections: CanvasConnectionCreateData[] | CanvasConnection[]) {
|
||||
function addConnections(
|
||||
connections: CanvasConnectionCreateData[] | CanvasConnection[],
|
||||
{ trackBulk = true, trackHistory = false } = {},
|
||||
) {
|
||||
if (trackBulk) {
|
||||
historyStore.startRecordingUndo();
|
||||
}
|
||||
|
||||
for (const { source, target, data } of connections) {
|
||||
createConnection({
|
||||
source,
|
||||
sourceHandle: createCanvasConnectionHandleString({
|
||||
mode: CanvasConnectionMode.Output,
|
||||
type: isValidNodeConnectionType(data?.source.type)
|
||||
? data?.source.type
|
||||
: NodeConnectionType.Main,
|
||||
index: data?.source.index ?? 0,
|
||||
}),
|
||||
target,
|
||||
targetHandle: createCanvasConnectionHandleString({
|
||||
mode: CanvasConnectionMode.Input,
|
||||
type: isValidNodeConnectionType(data?.target.type)
|
||||
? data?.target.type
|
||||
: NodeConnectionType.Main,
|
||||
index: data?.target.index ?? 0,
|
||||
}),
|
||||
});
|
||||
createConnection(
|
||||
{
|
||||
source,
|
||||
sourceHandle: createCanvasConnectionHandleString({
|
||||
mode: CanvasConnectionMode.Output,
|
||||
type: isValidNodeConnectionType(data?.source.type)
|
||||
? data?.source.type
|
||||
: NodeConnectionType.Main,
|
||||
index: data?.source.index ?? 0,
|
||||
}),
|
||||
target,
|
||||
targetHandle: createCanvasConnectionHandleString({
|
||||
mode: CanvasConnectionMode.Input,
|
||||
type: isValidNodeConnectionType(data?.target.type)
|
||||
? data?.target.type
|
||||
: NodeConnectionType.Main,
|
||||
index: data?.target.index ?? 0,
|
||||
}),
|
||||
},
|
||||
{ trackHistory },
|
||||
);
|
||||
}
|
||||
|
||||
if (trackBulk) {
|
||||
historyStore.stopRecordingUndo();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1462,6 +1476,7 @@ export function useCanvasOperations({ router }: { router: ReturnType<typeof useR
|
|||
|
||||
async function addImportedNodesToWorkflow(
|
||||
data: IWorkflowDataUpdate,
|
||||
{ trackBulk = true, trackHistory = false } = {},
|
||||
): Promise<IWorkflowDataUpdate> {
|
||||
// Because nodes with the same name maybe already exist, it could
|
||||
// be needed that they have to be renamed. Also could it be possible
|
||||
|
@ -1602,17 +1617,23 @@ export function useCanvasOperations({ router }: { router: ReturnType<typeof useR
|
|||
}
|
||||
|
||||
// Add the nodes with the changed node names, expressions and connections
|
||||
historyStore.startRecordingUndo();
|
||||
if (trackBulk) {
|
||||
historyStore.startRecordingUndo();
|
||||
}
|
||||
|
||||
await addNodes(Object.values(tempWorkflow.nodes));
|
||||
await addNodes(Object.values(tempWorkflow.nodes), { trackBulk: false, trackHistory: true });
|
||||
addConnections(
|
||||
mapLegacyConnectionsToCanvasConnections(
|
||||
tempWorkflow.connectionsBySourceNode,
|
||||
Object.values(tempWorkflow.nodes),
|
||||
),
|
||||
{ trackBulk: false, trackHistory },
|
||||
);
|
||||
|
||||
historyStore.stopRecordingUndo();
|
||||
if (trackBulk) {
|
||||
historyStore.stopRecordingUndo();
|
||||
}
|
||||
|
||||
uiStore.stateIsDirty = true;
|
||||
|
||||
return {
|
||||
|
|
Loading…
Reference in a new issue