import { useRef } from 'react' import { useTranslation } from 'react-i18next' import clsx from 'clsx'; import type { ReactShapeConfig } from '@antv/x6-react-shape'; import { Flex } from 'antd'; import { CheckCircleFilled, CloseCircleFilled, LoadingOutlined } from '@ant-design/icons'; import NodeTools from './NodeTools' import { useVariableList } from '../Properties/hooks/useVariableList' import { isSubExprSet } from '../../utils' import { fileSubFieldOperators } from '../Properties/CaseList' const calculateIsSet = (item: any, type: string) => { switch (type) { case 'categories': return typeof item?.class_name === 'string' && item?.class_name !== '' case 'cases': { if (item?.sub_variable_condition !== undefined) { return !!item.left && !!item.operator } if (!item.left) return false if (['not_empty', 'empty'].includes(item.operator)) return true return !!item.left && (!!item.right || typeof item.right === 'boolean' || typeof item.right === 'number') } } } const ConditionNode: ReactShapeConfig['component'] = ({ node }) => { const data = node?.getData() || {}; const { t } = useTranslation() const graphRef = useRef(node?.model?.graph) const variableList = useVariableList(node ?? null, graphRef, data.chatVariables ?? []) const getLocaleField = (field: string, filedType: string) => { const key = filedType === 'boolean' ? `workflow.config.if-else..boolean.${field}` : filedType === 'number' ? `workflow.config.if-else.num.${field}` : `workflow.config.if-else.${field}` const value = t(key) return value !== key ? value : t(`workflow.config.if-else.num.${field}`) }; const getSubLocaleField = (field: string, fieldKey: string) => { const operators = fileSubFieldOperators[fieldKey] ?? fileSubFieldOperators.default const match = operators?.find(op => op.value === field) return match?.label ? t(match.label as string) : field } const labelRender = (value: string) => { const filterOption = variableList.find(vo => `{{${vo.value}}}` === value) ?? variableList.flatMap(vo => vo.children ?? []).find(child => `{{${child.value}}}` === value) ?? variableList.flatMap(vo => vo.children ?? []).flatMap((child: any) => child.children ?? []).find((grandchild: any) => `{{${grandchild.value}}}` === value) if (filterOption) { return ( {`{x}`} {filterOption.label} ) } return null } return (