fix: add check for reset (#2226)

This commit is contained in:
heheer
2024-07-31 15:42:59 +08:00
committed by GitHub
parent 41da52d6ed
commit 8c7f4a3a30

View File

@@ -1,4 +1,4 @@
import React, { useEffect } from 'react';
import React, { useEffect, useMemo } from 'react';
import { Controller } from 'react-hook-form';
import RenderPluginInput from './renderPluginInput';
import { Button, Flex } from '@chakra-ui/react';
@@ -6,6 +6,7 @@ import { useTranslation } from 'react-i18next';
import { useContextSelector } from 'use-context-selector';
import { PluginRunContext } from '../context';
import { WorkflowIOValueTypeEnum } from '@fastgpt/global/core/workflow/constants';
import { isEqual } from 'lodash';
const RenderInput = () => {
const { pluginInputs, variablesForm, histories, onStartChat, onNewChat, onSubmit, isChatting } =
@@ -16,20 +17,25 @@ const RenderInput = () => {
control,
handleSubmit,
reset,
getValues,
formState: { errors }
} = variablesForm;
useEffect(() => {
reset(
pluginInputs.reduce(
(acc, input) => {
acc[input.key] = input.defaultValue;
return acc;
},
{} as Record<string, any>
)
const defaultFormValues = useMemo(() => {
return pluginInputs.reduce(
(acc, input) => {
acc[input.key] = input.defaultValue;
return acc;
},
{} as Record<string, any>
);
}, [pluginInputs, histories]);
}, [pluginInputs]);
useEffect(() => {
if (isEqual(getValues(), defaultFormValues)) return;
reset(defaultFormValues);
}, [defaultFormValues, histories]);
const isDisabledInput = histories.length > 0;
return (