refactor: remove unused copy node functionality from SharedNodeMenu

This commit is contained in:
wood chen 2025-05-28 18:51:12 +08:00
parent b829080c0f
commit 6c1e3bfcf6

View File

@ -2,7 +2,6 @@ import { memo, useMemo, useRef } from "react";
import { useTranslation } from "react-i18next";
import {
CloseCircleOutlined as CloseCircleOutlinedIcon,
CopyOutlined as CopyOutlinedIcon,
EllipsisOutlined as EllipsisOutlinedIcon,
FormOutlined as FormOutlinedIcon,
MoreOutlined as MoreOutlinedIcon,
@ -12,7 +11,7 @@ import { Button, Card, Drawer, Dropdown, Input, type InputRef, type MenuProps, M
import { produce } from "immer";
import { isEqual } from "radash";
import { type WorkflowNode, WorkflowNodeType, newNode } from "@/domain/workflow";
import { type WorkflowNode, WorkflowNodeType } from "@/domain/workflow";
import { useZustandShallowSelector } from "@/hooks";
import { useWorkflowStore } from "@/stores/workflow";
@ -83,7 +82,7 @@ const isNodeReadOnly = (node: WorkflowNode) => {
const SharedNodeMenu = ({ menus, trigger, node, disabled, branchId, branchIndex, afterUpdate, afterDelete }: SharedNodeMenuProps) => {
const { t } = useTranslation();
const { updateNode, removeNode, removeBranch, addNode } = useWorkflowStore(useZustandShallowSelector(["updateNode", "removeNode", "removeBranch", "addNode"]));
const { updateNode, removeNode, removeBranch } = useWorkflowStore(useZustandShallowSelector(["updateNode", "removeNode", "removeBranch"]));
const [modalApi, ModelContextHolder] = Modal.useModal();
@ -106,49 +105,6 @@ const SharedNodeMenu = ({ menus, trigger, node, disabled, branchId, branchIndex,
afterUpdate?.();
};
const handleCopyNode = async () => {
try {
// Clone the node by creating a new node of the same type
const clonedNode = newNode(node.type);
// Copy over configurations
clonedNode.name = `${node.name} (副本)`;
// Copy all configurable properties
if (node.config) {
clonedNode.config = JSON.parse(JSON.stringify(node.config));
}
if (node.inputs) {
clonedNode.inputs = JSON.parse(JSON.stringify(node.inputs));
}
if (node.outputs) {
clonedNode.outputs = JSON.parse(JSON.stringify(node.outputs));
}
if (node.validated !== undefined) {
clonedNode.validated = node.validated;
}
// For branch nodes, we need to deep copy the branches structure
if (node.branches && node.type === WorkflowNodeType.Branch) {
// For branch nodes, we'll keep the structure but with new IDs
// This ensures we don't run into ID conflicts
clonedNode.branches = newNode(WorkflowNodeType.Branch).branches;
} else if (node.branches && node.type === WorkflowNodeType.ExecuteResultBranch) {
// For execute result branches, we'll keep the structure but with new IDs
clonedNode.branches = newNode(WorkflowNodeType.ExecuteResultBranch).branches;
}
// Add the cloned node after the current node
await addNode(clonedNode, node.id);
afterUpdate?.();
} catch (err) {
console.error("Failed to copy node:", err);
}
};
const handleDeleteClick = async () => {
if (isNodeBranchLike(node)) {
await removeBranch(branchId!, branchIndex!);