mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-30 16:45:35 +08:00
### What problem does this PR solve? Feat: Fixed the issue where variables were not displayed in the switch operator #3221 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
25 lines
970 B
TypeScript
25 lines
970 B
TypeScript
import { ISwitchCondition } from '@/interfaces/database/agent';
|
|
import { useEffect } from 'react';
|
|
import { UseFormReturn, useWatch } from 'react-hook-form';
|
|
import useGraphStore from '../../store';
|
|
|
|
export function useWatchFormChange(id?: string, form?: UseFormReturn) {
|
|
let values = useWatch({ control: form?.control });
|
|
const updateNodeForm = useGraphStore((state) => state.updateNodeForm);
|
|
|
|
useEffect(() => {
|
|
// Manually triggered form updates are synchronized to the canvas
|
|
console.log('🚀 ~ useWatchFormChange ~ values:', form?.formState.isDirty);
|
|
if (id) {
|
|
values = form?.getValues() || {};
|
|
let nextValues: any = {
|
|
...values,
|
|
conditions:
|
|
values?.conditions?.map((x: ISwitchCondition) => ({ ...x })) ?? [], // Changing the form value with useFieldArray does not change the array reference
|
|
};
|
|
|
|
updateNodeForm(id, nextValues);
|
|
}
|
|
}, [form?.formState.isDirty, id, updateNodeForm, values]);
|
|
}
|