From 754a5e1cee3db75d837bf24655ddd8af76d24785 Mon Sep 17 00:00:00 2001 From: balibabu Date: Wed, 21 May 2025 17:03:16 +0800 Subject: [PATCH] Feat: Fixed the issue where the page would refresh continuously when opening the sheet on the right side of the canvas #3221 (#7756) ### What problem does this PR solve? Feat: Fixed the issue where the page would refresh continuously when opening the sheet on the right side of the canvas #3221 ### Type of change - [x] New Feature (non-breaking change which adds functionality) --- web/src/pages/agent/form-sheet/next.tsx | 1 + .../agent/form-sheet/use-form-config-map.tsx | 8 +- web/src/pages/agent/form/code-form/index.tsx | 9 +- .../agent/form/code-form/next-variable.tsx | 113 ++++++++++++++++++ web/src/pages/agent/hooks.tsx | 5 +- 5 files changed, 125 insertions(+), 11 deletions(-) create mode 100644 web/src/pages/agent/form/code-form/next-variable.tsx diff --git a/web/src/pages/agent/form-sheet/next.tsx b/web/src/pages/agent/form-sheet/next.tsx index cecb7a3f0..4601ccfa5 100644 --- a/web/src/pages/agent/form-sheet/next.tsx +++ b/web/src/pages/agent/form-sheet/next.tsx @@ -85,6 +85,7 @@ const FormSheet = ({ const formData = node?.data?.form; if (isPlainObject(formData)) { // form.setFieldsValue({ ...formData, items }); + console.info('xxx'); form.reset({ ...formData, items }); } } else { diff --git a/web/src/pages/agent/form-sheet/use-form-config-map.tsx b/web/src/pages/agent/form-sheet/use-form-config-map.tsx index 9cde6628d..fe2662ae5 100644 --- a/web/src/pages/agent/form-sheet/use-form-config-map.tsx +++ b/web/src/pages/agent/form-sheet/use-form-config-map.tsx @@ -137,9 +137,11 @@ export function useFormConfigMap() { message_history_window_size: 6, }, schema: z.object({ - llm_id: z.string(), - message_history_window_size: z.number(), - language: z.string(), + script: z.string(), + arguments: z + .array(z.object({ name: z.string(), component_id: z.string() })) + .optional(), + lang: z.string(), }), }, [Operator.Baidu]: { diff --git a/web/src/pages/agent/form/code-form/index.tsx b/web/src/pages/agent/form/code-form/index.tsx index e081b40c1..992e04fa5 100644 --- a/web/src/pages/agent/form/code-form/index.tsx +++ b/web/src/pages/agent/form/code-form/index.tsx @@ -1,6 +1,5 @@ import Editor, { loader } from '@monaco-editor/react'; import { INextOperatorForm } from '../../interface'; -import { DynamicInputVariable } from './dynamic-input-variable'; import { Form, @@ -13,7 +12,7 @@ import { import { RAGFlowSelect } from '@/components/ui/select'; import { ProgrammingLanguage } from '@/constants/agent'; import { ICodeForm } from '@/interfaces/database/flow'; -import { useTranslation } from 'react-i18next'; +import { DynamicInputVariable } from './next-variable'; loader.config({ paths: { vs: '/vs' } }); @@ -24,7 +23,6 @@ const options = [ const CodeForm = ({ form, node }: INextOperatorForm) => { const formData = node?.data.form as ICodeForm; - const { t } = useTranslation(); // useEffect(() => { // setTimeout(() => { @@ -47,12 +45,9 @@ const CodeForm = ({ form, node }: INextOperatorForm) => { ( - - {t('channel')} - diff --git a/web/src/pages/agent/form/code-form/next-variable.tsx b/web/src/pages/agent/form/code-form/next-variable.tsx new file mode 100644 index 000000000..d0e5790df --- /dev/null +++ b/web/src/pages/agent/form/code-form/next-variable.tsx @@ -0,0 +1,113 @@ +'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; + name?: string; +} + +export function DynamicVariableForm({ node, name = 'arguments' }: IProps) { + const { t } = useTranslation(); + const form = useFormContext(); + + const { fields, remove, append } = useFieldArray({ + name: name, + control: form.control, + }); + + const valueOptions = useBuildComponentIdSelectOptions( + node?.id, + node?.parentId, + ); + + return ( +
+ {fields.map((field, index) => { + const typeField = `${name}.${index}.name`; + return ( +
+ ( + + + + + + + + )} + /> + ( + + + + + + + + )} + /> + remove(index)} + /> +
+ ); + })} + +
+ ); +} + +export function DynamicInputVariable({ node }: IProps) { + const { t } = useTranslation(); + + return ( + + + + {t('flow.input')} + + + + + + + + ); +} diff --git a/web/src/pages/agent/hooks.tsx b/web/src/pages/agent/hooks.tsx index 5319434e5..ab55dbf0f 100644 --- a/web/src/pages/agent/hooks.tsx +++ b/web/src/pages/agent/hooks.tsx @@ -320,7 +320,10 @@ export const useHandleFormValuesChange = ( category_description: buildCategorizeObjectFromList(value.items), }; } - updateNodeForm(id, nextValues); + if (type) { + // Manually triggered form updates are synchronized to the canvas + updateNodeForm(id, nextValues); + } } }); return () => subscription?.unsubscribe();