浏览代码

Feat: Solved the problem that BeginForm would get stuck when modifying data #3221 (#8080)

### What problem does this PR solve?

Feat: Solved the problem that BeginForm would get stuck when modifying
data #3221
### Type of change


- [x] New Feature (non-breaking change which adds functionality)
tags/v0.19.1
balibabu 4 个月前
父节点
当前提交
7c7359a9b2
没有帐户链接到提交者的电子邮件

+ 5
- 11
web/src/pages/agent/form/begin-form/index.tsx 查看文件

@@ -39,15 +39,9 @@ const BeginForm = ({ node }: INextOperatorForm) => {

const FormSchema = z.object({
enablePrologue: z.boolean().optional(),
prologue: z
.string()
.min(1, {
message: t('common.namePlaceholder'),
})
.trim()
.optional(),
prologue: z.string().trim().optional(),
mode: z.string(),
query: z
inputs: z
.array(
z.object({
key: z.string(),
@@ -68,7 +62,7 @@ const BeginForm = ({ node }: INextOperatorForm) => {

useWatchFormChange(node?.id, form);

const query = useWatch({ control: form.control, name: 'query' });
const inputs = useWatch({ control: form.control, name: 'inputs' });
const mode = useWatch({ control: form.control, name: 'mode' });

const enablePrologue = useWatch({
@@ -160,7 +154,7 @@ const BeginForm = ({ node }: INextOperatorForm) => {
{/* Create a hidden field to make Form instance record this */}
<FormField
control={form.control}
name={'query'}
name={'inputs'}
render={() => <div></div>}
/>
<Collapse
@@ -183,7 +177,7 @@ const BeginForm = ({ node }: INextOperatorForm) => {
}
>
<QueryTable
data={query}
data={inputs}
showModal={showModal}
deleteRecord={handleDeleteRecord}
></QueryTable>

+ 11
- 11
web/src/pages/agent/form/begin-form/use-edit-query.ts 查看文件

@@ -8,9 +8,9 @@ export function useUpdateQueryToNodeForm({ form, node }: INextOperatorForm) {
const updateNodeForm = useGraphStore((state) => state.updateNodeForm);

const update = useCallback(
(query: BeginQuery[]) => {
(inputs: BeginQuery[]) => {
const values = form.getValues();
const nextValues = { ...values, query };
const nextValues = { ...values, inputs };
if (node?.id) {
updateNodeForm(node.id, nextValues);
}
@@ -28,19 +28,19 @@ export const useEditQueryRecord = ({ form, node }: INextOperatorForm) => {
const { update } = useUpdateQueryToNodeForm({ form, node });

const otherThanCurrentQuery = useMemo(() => {
const query: BeginQuery[] = form?.getValues('query') || [];
return query.filter((item, idx) => idx !== index);
const inputs: BeginQuery[] = form?.getValues('inputs') || [];
return inputs.filter((item, idx) => idx !== index);
}, [form, index]);

const handleEditRecord = useCallback(
(record: BeginQuery) => {
const query: BeginQuery[] = form?.getValues('query') || [];
console.log('🚀 ~ useEditQueryRecord ~ query:', query);
const inputs: BeginQuery[] = form?.getValues('inputs') || [];
console.log('🚀 ~ useEditQueryRecord ~ inputs:', inputs);

const nextQuery: BeginQuery[] =
index > -1 ? query.toSpliced(index, 1, record) : [...query, record];
index > -1 ? inputs.toSpliced(index, 1, record) : [...inputs, record];

form.setValue('query', nextQuery, {
form.setValue('inputs', nextQuery, {
shouldDirty: true,
shouldTouch: true,
});
@@ -63,12 +63,12 @@ export const useEditQueryRecord = ({ form, node }: INextOperatorForm) => {

const handleDeleteRecord = useCallback(
(idx: number) => {
const query = form?.getValues('query') || [];
const nextQuery = query.filter(
const inputs = form?.getValues('inputs') || [];
const nextQuery = inputs.filter(
(item: BeginQuery, index: number) => index !== idx,
);

form.setValue('query', nextQuery, { shouldDirty: true });
form.setValue('inputs', nextQuery, { shouldDirty: true });

update(nextQuery);
},

+ 1
- 0
web/src/pages/agent/form/begin-form/use-values.ts 查看文件

@@ -12,6 +12,7 @@ export function useValues(node?: RAGFlowNodeType) {
enablePrologue: true,
prologue: t('chat.setAnOpenerInitial'),
mode: AgentDialogueMode.Conversational,
inputs: [],
}),
[t],
);

正在加载...
取消
保存