import { memo, useMemo } from "react"; import { useTranslation } from "react-i18next"; import { CloudUploadOutlined as CloudUploadOutlinedIcon, PlusOutlined as PlusOutlinedIcon, SendOutlined as SendOutlinedIcon, SisternodeOutlined as SisternodeOutlinedIcon, SolutionOutlined as SolutionOutlinedIcon, } from "@ant-design/icons"; import { Dropdown } from "antd"; import { WorkflowNodeType, newNode } from "@/domain/workflow"; import { useZustandShallowSelector } from "@/hooks"; import { useWorkflowStore } from "@/stores/workflow"; import { type SharedNodeProps } from "./_SharedNode"; export type AddNodeProps = SharedNodeProps; const AddNode = ({ node, disabled }: AddNodeProps) => { const { t } = useTranslation(); const { addNode } = useWorkflowStore(useZustandShallowSelector(["addNode"])); const dropdownMenus = useMemo(() => { return [ [WorkflowNodeType.Apply, "workflow_node.apply.label", ], [WorkflowNodeType.Deploy, "workflow_node.deploy.label", ], [WorkflowNodeType.Branch, "workflow_node.branch.label", ], [WorkflowNodeType.ExecuteResultBranch, "workflow_node.execute_result_branch.label", ], [WorkflowNodeType.Notify, "workflow_node.notify.label", ], ] .filter(([type]) => { if (node.type !== WorkflowNodeType.Apply && node.type !== WorkflowNodeType.Deploy && type === WorkflowNodeType.ExecuteResultBranch) { return false; } return true; }) .map(([type, label, icon]) => { return { key: type as string, disabled: disabled, label: t(label as string), icon: icon, onClick: () => { const nextNode = newNode(type as WorkflowNodeType); addNode(nextNode, node.id); }, }; }); }, [node.id, disabled, node.type]); return (
); }; export default memo(AddNode);