Skip to content

Commit a0ee93e

Browse files
committed
refactor: copy node file
1 parent 8991126 commit a0ee93e

File tree

1 file changed

+1
-15
lines changed

1 file changed

+1
-15
lines changed

src/store/thunks.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -965,18 +965,14 @@ export const copyNode = (nodeToCopy: RenderNode) => (
965965
flowContext: { nodes }
966966
} = getState();
967967

968-
// Deep clone the node
969968
const clonedNode: RenderNode = JSON.parse(JSON.stringify(nodeToCopy));
970969

971-
// Create UUID mapping for all UUIDs that need to be remapped
972970
const uuidMap: { [oldUUID: string]: string } = {};
973971

974-
// Remap node UUID
975972
const newNodeUUID = createUUID();
976973
uuidMap[clonedNode.node.uuid] = newNodeUUID;
977974
clonedNode.node.uuid = newNodeUUID;
978975

979-
// Remap action UUIDs
980976
if (clonedNode.node.actions) {
981977
clonedNode.node.actions.forEach((action: AnyAction) => {
982978
const newActionUUID = createUUID();
@@ -985,18 +981,16 @@ export const copyNode = (nodeToCopy: RenderNode) => (
985981
});
986982
}
987983

988-
// Remap exit UUIDs
989984
if (clonedNode.node.exits) {
990985
clonedNode.node.exits.forEach((exit: Exit) => {
991986
const newExitUUID = createUUID();
992987
uuidMap[exit.uuid] = newExitUUID;
993988
exit.uuid = newExitUUID;
994-
// Clear destination since it's a copy
989+
995990
exit.destination_uuid = null;
996991
});
997992
}
998993

999-
// Remap router category and case UUIDs if router exists
1000994
if (clonedNode.node.router) {
1001995
const router = clonedNode.node.router as SwitchRouter;
1002996

@@ -1006,7 +1000,6 @@ export const copyNode = (nodeToCopy: RenderNode) => (
10061000
uuidMap[category.uuid] = newCategoryUUID;
10071001
category.uuid = newCategoryUUID;
10081002

1009-
// Remap exit_uuid reference
10101003
if (uuidMap[category.exit_uuid]) {
10111004
category.exit_uuid = uuidMap[category.exit_uuid];
10121005
}
@@ -1019,32 +1012,25 @@ export const copyNode = (nodeToCopy: RenderNode) => (
10191012
uuidMap[caseItem.uuid] = newCaseUUID;
10201013
caseItem.uuid = newCaseUUID;
10211014

1022-
// Remap category_uuid reference
10231015
if (uuidMap[caseItem.category_uuid]) {
10241016
caseItem.category_uuid = uuidMap[caseItem.category_uuid];
10251017
}
10261018
});
10271019
}
10281020

1029-
// Remap default_category_uuid
10301021
if (router.default_category_uuid && uuidMap[router.default_category_uuid]) {
10311022
router.default_category_uuid = uuidMap[router.default_category_uuid];
10321023
}
10331024
}
10341025

1035-
// Offset position to avoid overlap (offset by NODE_SPACING)
10361026
clonedNode.ui.position = {
10371027
left: clonedNode.ui.position.left + NODE_SPACING * 2,
10381028
top: clonedNode.ui.position.top + NODE_SPACING * 2
10391029
};
10401030

1041-
// Clear inbound connections since it's a copy
10421031
clonedNode.inboundConnections = {};
1043-
1044-
// Remove ghost flag if present
10451032
delete clonedNode.ghost;
10461033

1047-
// Add the copied node to the flow
10481034
const updatedNodes = mutators.mergeNode(nodes, clonedNode);
10491035
dispatch(updateNodes(updatedNodes));
10501036
markDirty();

0 commit comments

Comments
 (0)