'use client'; import { SideDown } from '@/assets/icon/Icon'; import { Button } from '@/components/ui/button'; import { Collapsible, CollapsibleContent, CollapsibleTrigger, } from '@/components/ui/collapsible'; import { FormControl, FormDescription, FormField, FormItem, FormMessage, } from '@/components/ui/form'; import { Input } from '@/components/ui/input'; import { RAGFlowSelect } from '@/components/ui/select'; import { RAGFlowNodeType } from '@/interfaces/database/flow'; import { Plus, Trash2 } from 'lucide-react'; import { useFieldArray, useFormContext } from 'react-hook-form'; import { useTranslation } from 'react-i18next'; import { useBuildComponentIdSelectOptions } from '../../hooks/use-get-begin-query'; interface IProps { node?: RAGFlowNodeType; } enum VariableType { Reference = 'reference', Input = 'input', } const getVariableName = (type: string) => type === VariableType.Reference ? 'component_id' : 'value'; export function DynamicVariableForm({ node }: IProps) { const { t } = useTranslation(); const form = useFormContext(); const { fields, remove, append } = useFieldArray({ name: 'query', control: form.control, }); const valueOptions = useBuildComponentIdSelectOptions( node?.id, node?.parentId, ); const options = [ { value: VariableType.Reference, label: t('flow.reference') }, { value: VariableType.Input, label: t('flow.text') }, ]; return (
{fields.map((field, index) => { const typeField = `query.${index}.type`; const typeValue = form.watch(typeField); return (
( { field.onChange(val); form.resetField(`query.${index}.value`); form.resetField(`query.${index}.component_id`); }} > )} /> ( {typeValue === VariableType.Reference ? ( ) : ( )} )} /> remove(index)} />
); })}
); } export function DynamicInputVariable({ node }: IProps) { const { t } = useTranslation(); return ( {t('flow.input')} ); }