feat(editor): Add undo/redo create connection in new canvas (no-changelog) (#10141)

This commit is contained in:
Alex Grozav
2024-07-22 20:26:47 +03:00
committed by GitHub
parent 7e1eeb4c31
commit ada1256898
4 changed files with 77 additions and 4 deletions

View File

@@ -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,