mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 13:03:50 +00:00
fix: add check for reset (#2226)
This commit is contained in:
@@ -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 (
|
||||
|
Reference in New Issue
Block a user