refactor(ui): clean code
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { useMemo } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import {
|
||||
CloudUploadOutlined as CloudUploadOutlinedIcon,
|
||||
PlusOutlined as PlusOutlinedIcon,
|
||||
@@ -7,60 +9,45 @@ import {
|
||||
} from "@ant-design/icons";
|
||||
import { Dropdown } from "antd";
|
||||
|
||||
import { WorkflowNodeType, newNode, workflowNodeTypeDefaultNames } from "@/domain/workflow";
|
||||
import { type WorkflowNode, WorkflowNodeType, newNode } from "@/domain/workflow";
|
||||
import { useZustandShallowSelector } from "@/hooks";
|
||||
import { useWorkflowStore } from "@/stores/workflow";
|
||||
|
||||
import { type BrandNodeProps, type NodeProps } from "../types";
|
||||
export type AddNodeProps = {
|
||||
node: WorkflowNode;
|
||||
};
|
||||
|
||||
const dropdownMenus = [
|
||||
{
|
||||
type: WorkflowNodeType.Apply,
|
||||
label: workflowNodeTypeDefaultNames.get(WorkflowNodeType.Apply),
|
||||
icon: <SolutionOutlinedIcon />,
|
||||
},
|
||||
{
|
||||
type: WorkflowNodeType.Deploy,
|
||||
label: workflowNodeTypeDefaultNames.get(WorkflowNodeType.Deploy),
|
||||
icon: <CloudUploadOutlinedIcon />,
|
||||
},
|
||||
{
|
||||
type: WorkflowNodeType.Branch,
|
||||
label: workflowNodeTypeDefaultNames.get(WorkflowNodeType.Branch),
|
||||
icon: <SisternodeOutlinedIcon />,
|
||||
},
|
||||
{
|
||||
type: WorkflowNodeType.Notify,
|
||||
label: workflowNodeTypeDefaultNames.get(WorkflowNodeType.Notify),
|
||||
icon: <SendOutlinedIcon />,
|
||||
},
|
||||
];
|
||||
const AddNode = ({ node }: AddNodeProps) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const AddNode = ({ node: supnode }: NodeProps | BrandNodeProps) => {
|
||||
const { addNode } = useWorkflowStore(useZustandShallowSelector(["addNode"]));
|
||||
|
||||
const dropdownMenus = useMemo(() => {
|
||||
return [
|
||||
[WorkflowNodeType.Apply, "workflow_node.apply.label", <SolutionOutlinedIcon />],
|
||||
[WorkflowNodeType.Deploy, "workflow_node.deploy.label", <CloudUploadOutlinedIcon />],
|
||||
[WorkflowNodeType.Branch, "workflow_node.branch.label", <SisternodeOutlinedIcon />],
|
||||
[WorkflowNodeType.Notify, "workflow_node.notify.label", <SendOutlinedIcon />],
|
||||
].map(([type, label, icon]) => {
|
||||
return {
|
||||
key: type as string,
|
||||
label: t(label as string),
|
||||
icon: icon,
|
||||
onClick: () => {
|
||||
handleNodeTypeSelect(type as WorkflowNodeType);
|
||||
},
|
||||
};
|
||||
});
|
||||
}, []);
|
||||
|
||||
const handleNodeTypeSelect = (type: WorkflowNodeType) => {
|
||||
const node = newNode(type);
|
||||
addNode(node, supnode.id);
|
||||
const nextNode = newNode(type);
|
||||
addNode(nextNode, node.id);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="relative py-6 before:absolute before:left-1/2 before:top-0 before:h-full before:w-[2px] before:-translate-x-1/2 before:bg-stone-200 before:content-['']">
|
||||
<Dropdown
|
||||
menu={{
|
||||
items: dropdownMenus.map((item) => {
|
||||
return {
|
||||
key: item.type,
|
||||
label: item.label,
|
||||
icon: item.icon,
|
||||
onClick: () => {
|
||||
handleNodeTypeSelect(item.type);
|
||||
},
|
||||
};
|
||||
}),
|
||||
}}
|
||||
trigger={["click"]}
|
||||
>
|
||||
<Dropdown menu={{ items: dropdownMenus }} trigger={["click"]}>
|
||||
<div className="relative z-[1] flex size-5 cursor-pointer items-center justify-center rounded-full bg-stone-400 hover:bg-stone-500">
|
||||
<PlusOutlinedIcon className="text-white" />
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user