import { FormContainer } from '@/components/form-container'; import { IconFont } from '@/components/icon-font'; import { SelectWithSearch } from '@/components/originui/select-with-search'; import { BlockButton, Button } from '@/components/ui/button'; import { Card, CardContent } from '@/components/ui/card'; import { Form, FormControl, FormField, FormItem, FormMessage, } from '@/components/ui/form'; import { RAGFlowSelect } from '@/components/ui/select'; import { Separator } from '@/components/ui/separator'; import { Textarea } from '@/components/ui/textarea'; import { cn } from '@/lib/utils'; import { zodResolver } from '@hookform/resolvers/zod'; import { toLower } from 'lodash'; import { X } from 'lucide-react'; import { memo, useCallback, useMemo } from 'react'; import { useFieldArray, useForm, useFormContext } from 'react-hook-form'; import { useTranslation } from 'react-i18next'; import { z } from 'zod'; import { SwitchLogicOperatorOptions, SwitchOperatorOptions, VariableType, } from '../../constant'; import { useBuildQueryVariableOptions } from '../../hooks/use-get-begin-query'; import { IOperatorForm } from '../../interface'; import { FormWrapper } from '../components/form-wrapper'; import { useValues } from './use-values'; import { useWatchFormChange } from './use-watch-change'; const ConditionKey = 'conditions'; const ItemKey = 'items'; type ConditionCardsProps = { name: string; removeParent(index: number): void; parentIndex: number; parentLength: number; } & IOperatorForm; export const LogicalOperatorIcon = function OperatorIcon({ icon, value, }: Omit<(typeof SwitchOperatorOptions)[0], 'label'>) { if (typeof icon === 'string') { return ( ', })} > ); } return icon; }; function useBuildSwitchOperatorOptions() { const { t } = useTranslation(); const switchOperatorOptions = useMemo(() => { return SwitchOperatorOptions.map((x) => ({ value: x.value, icon: ( ), label: t(`flow.switchOperatorOptions.${x.label}`), })); }, [t]); return switchOperatorOptions; } function ConditionCards({ name: parentName, parentIndex, removeParent, parentLength, }: ConditionCardsProps) { const form = useFormContext(); const nextOptions = useBuildQueryVariableOptions(); const finalOptions = useMemo(() => { return nextOptions.map((x) => { return { ...x, options: x.options.filter( (y) => !toLower(y.type).includes(VariableType.Array), ), }; }); }, [nextOptions]); const switchOperatorOptions = useBuildSwitchOperatorOptions(); const name = `${parentName}.${ItemKey}`; const { fields, remove, append } = useFieldArray({ name: name, control: form.control, }); const handleRemove = useCallback( (index: number) => () => { remove(index); if (parentIndex !== 0 && index === 0 && parentLength === 1) { removeParent(parentIndex); } }, [parentIndex, parentLength, remove, removeParent], ); return (
{fields.map((field, index) => { return (
1 && (index === 0 || index === fields.length - 1), }, )} >
( )} />
( )} />
(