import { memo, useRef, useState } from "react"; import { FilterFilled as FilterFilledIcon, FilterOutlined as FilterOutlinedIcon, MoreOutlined as MoreOutlinedIcon } from "@ant-design/icons"; import { Button, Card, Popover } from "antd"; import { produce } from "immer"; import { useZustandShallowSelector } from "@/hooks"; import { useWorkflowStore } from "@/stores/workflow"; import SharedNode, { type SharedNodeProps } from "./_SharedNode"; import AddNode from "./AddNode"; import ConditionNodeConfigForm, { type ConditionNodeConfigFormFieldValues, type ConditionNodeConfigFormInstance } from "./ConditionNodeConfigForm"; export type ConditionNodeProps = SharedNodeProps & { branchId: string; branchIndex: number; }; const ConditionNode = ({ node, disabled, branchId, branchIndex }: ConditionNodeProps) => { const { updateNode } = useWorkflowStore(useZustandShallowSelector(["updateNode"])); const [formPending, setFormPending] = useState(false); const formRef = useRef(null); const getFormValues = () => formRef.current!.getFieldsValue() as ConditionNodeConfigFormFieldValues; const [drawerOpen, setDrawerOpen] = useState(false); const handleDrawerConfirm = async () => { setFormPending(true); try { await formRef.current!.validateFields(); } catch (err) { setFormPending(false); throw err; } try { const newValues = getFormValues(); const newNode = produce(node, (draft) => { draft.config = { ...newValues, }; draft.validated = true; }); await updateNode(newNode); } finally { setFormPending(false); } }; return ( <> } variant="text" />} /> } placement="rightTop" > setDrawerOpen(true)}>
e.stopPropagation()}>
setDrawerOpen(true)}> {node.config?.expression ? (
setDrawerOpen(open)} > ); }; export default memo(ConditionNode);