mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-20 19:32:15 +00:00
feat(editor): Add undo/redo create connection in new canvas (no-changelog) (#10141)
This commit is contained in:
@@ -30,6 +30,7 @@ import {
|
||||
WEBHOOK_NODE_TYPE,
|
||||
} from '@/constants';
|
||||
import {
|
||||
AddConnectionCommand,
|
||||
AddNodeCommand,
|
||||
MoveNodeCommand,
|
||||
RemoveConnectionCommand,
|
||||
@@ -55,6 +56,7 @@ import {
|
||||
getUniqueNodeName,
|
||||
mapCanvasConnectionToLegacyConnection,
|
||||
mapLegacyConnectionsToCanvasConnections,
|
||||
mapLegacyConnectionToCanvasConnection,
|
||||
parseCanvasConnectionHandleString,
|
||||
} from '@/utils/canvasUtilsV2';
|
||||
import * as NodeViewUtils from '@/utils/nodeViewUtils';
|
||||
@@ -949,13 +951,21 @@ export function useCanvasOperations({
|
||||
* Connection operations
|
||||
*/
|
||||
|
||||
function createConnection(connection: Connection) {
|
||||
function createConnection(connection: Connection, { trackHistory = false } = {}) {
|
||||
const sourceNode = workflowsStore.getNodeById(connection.source);
|
||||
const targetNode = workflowsStore.getNodeById(connection.target);
|
||||
if (!sourceNode || !targetNode) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (trackHistory) {
|
||||
historyStore.pushCommandToUndo(
|
||||
new AddConnectionCommand(
|
||||
mapCanvasConnectionToLegacyConnection(sourceNode, targetNode, connection),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
const mappedConnection = mapCanvasConnectionToLegacyConnection(
|
||||
sourceNode,
|
||||
targetNode,
|
||||
@@ -976,6 +986,19 @@ export function useCanvasOperations({
|
||||
uiStore.stateIsDirty = true;
|
||||
}
|
||||
|
||||
function revertCreateConnection(connection: [IConnection, IConnection]) {
|
||||
const sourceNodeName = connection[0].node;
|
||||
const sourceNode = workflowsStore.getNodeByName(sourceNodeName);
|
||||
const targetNodeName = connection[1].node;
|
||||
const targetNode = workflowsStore.getNodeByName(targetNodeName);
|
||||
|
||||
if (!sourceNode || !targetNode) {
|
||||
return;
|
||||
}
|
||||
|
||||
deleteConnection(mapLegacyConnectionToCanvasConnection(sourceNode, targetNode, connection));
|
||||
}
|
||||
|
||||
function deleteConnection(
|
||||
connection: Connection,
|
||||
{ trackHistory = false, trackBulk = true } = {},
|
||||
@@ -1607,6 +1630,7 @@ export function useCanvasOperations({
|
||||
revertDeleteNode,
|
||||
addConnections,
|
||||
createConnection,
|
||||
revertCreateConnection,
|
||||
deleteConnection,
|
||||
revertDeleteConnection,
|
||||
isConnectionAllowed,
|
||||
|
||||
Reference in New Issue
Block a user