import { CloseOutlined } from '@ant-design/icons'; import { Button, Card, Divider, Form, Input, Select } from 'antd'; import { useMemo } from 'react'; import { useTranslation } from 'react-i18next'; import { Operator, SwitchElseTo, SwitchLogicOperatorOptions, SwitchOperatorOptions, } from '../constant'; import { useBuildFormSelectOptions } from '../form-hooks'; import { useBuildComponentIdSelectOptions } from '../hooks'; import { IOperatorForm, ISwitchForm } from '../interface'; import { getOtherFieldValues } from '../utils'; const subLabelCol = { span: 11, }; const subWrapperCol = { span: 13, }; const SwitchForm = ({ onValuesChange, node, form }: IOperatorForm) => { const { t } = useTranslation(); const buildCategorizeToOptions = useBuildFormSelectOptions( Operator.Switch, node?.id, ); const getSelectedConditionTos = () => { const conditions: ISwitchForm['conditions'] = form?.getFieldValue('conditions'); return conditions?.filter((x) => !!x).map((x) => x?.to) ?? []; }; const switchOperatorOptions = useMemo(() => { return SwitchOperatorOptions.map((x) => ({ value: x.value, label: t(`flow.switchOperatorOptions.${x.label}`), })); }, [t]); const switchLogicOperatorOptions = useMemo(() => { return SwitchLogicOperatorOptions.map((x) => ({ value: x, label: t(`flow.switchLogicOperatorOptions.${x}`), })); }, [t]); const componentIdOptions = useBuildComponentIdSelectOptions(node?.id); return (
{(fields, { add, remove }) => (
{fields.map((field) => ( { remove(field.name); }} /> } > {({ getFieldValue }) => getFieldValue(['conditions', field.name, 'items'])?.length > 1 && ( {(subFields, subOpt) => (
{subFields.map((subField) => ( { subOpt.remove(subField.name); }} /> } > ))}
)}
))}
)}