From 8c7f4a3a307078d44032d8d6d590fc3277f88d95 Mon Sep 17 00:00:00 2001 From: heheer <71265218+newfish-cmyk@users.noreply.github.com> Date: Wed, 31 Jul 2024 15:42:59 +0800 Subject: [PATCH] fix: add check for reset (#2226) --- .../PluginRunBox/components/RenderInput.tsx | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/projects/app/src/components/core/chat/ChatContainer/PluginRunBox/components/RenderInput.tsx b/projects/app/src/components/core/chat/ChatContainer/PluginRunBox/components/RenderInput.tsx index a86db8935..13149d767 100644 --- a/projects/app/src/components/core/chat/ChatContainer/PluginRunBox/components/RenderInput.tsx +++ b/projects/app/src/components/core/chat/ChatContainer/PluginRunBox/components/RenderInput.tsx @@ -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 - ) + const defaultFormValues = useMemo(() => { + return pluginInputs.reduce( + (acc, input) => { + acc[input.key] = input.defaultValue; + return acc; + }, + {} as Record ); - }, [pluginInputs, histories]); + }, [pluginInputs]); + + useEffect(() => { + if (isEqual(getValues(), defaultFormValues)) return; + reset(defaultFormValues); + }, [defaultFormValues, histories]); + const isDisabledInput = histories.length > 0; return (