mirror of
https://github.com/labring/FastGPT.git
synced 2025-10-20 10:45:52 +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 { Controller } from 'react-hook-form';
|
||||||
import RenderPluginInput from './renderPluginInput';
|
import RenderPluginInput from './renderPluginInput';
|
||||||
import { Button, Flex } from '@chakra-ui/react';
|
import { Button, Flex } from '@chakra-ui/react';
|
||||||
@@ -6,6 +6,7 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import { useContextSelector } from 'use-context-selector';
|
import { useContextSelector } from 'use-context-selector';
|
||||||
import { PluginRunContext } from '../context';
|
import { PluginRunContext } from '../context';
|
||||||
import { WorkflowIOValueTypeEnum } from '@fastgpt/global/core/workflow/constants';
|
import { WorkflowIOValueTypeEnum } from '@fastgpt/global/core/workflow/constants';
|
||||||
|
import { isEqual } from 'lodash';
|
||||||
|
|
||||||
const RenderInput = () => {
|
const RenderInput = () => {
|
||||||
const { pluginInputs, variablesForm, histories, onStartChat, onNewChat, onSubmit, isChatting } =
|
const { pluginInputs, variablesForm, histories, onStartChat, onNewChat, onSubmit, isChatting } =
|
||||||
@@ -16,20 +17,25 @@ const RenderInput = () => {
|
|||||||
control,
|
control,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
reset,
|
reset,
|
||||||
|
getValues,
|
||||||
formState: { errors }
|
formState: { errors }
|
||||||
} = variablesForm;
|
} = variablesForm;
|
||||||
|
|
||||||
useEffect(() => {
|
const defaultFormValues = useMemo(() => {
|
||||||
reset(
|
return pluginInputs.reduce(
|
||||||
pluginInputs.reduce(
|
|
||||||
(acc, input) => {
|
(acc, input) => {
|
||||||
acc[input.key] = input.defaultValue;
|
acc[input.key] = input.defaultValue;
|
||||||
return acc;
|
return acc;
|
||||||
},
|
},
|
||||||
{} as Record<string, any>
|
{} as Record<string, any>
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}, [pluginInputs, histories]);
|
}, [pluginInputs]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isEqual(getValues(), defaultFormValues)) return;
|
||||||
|
reset(defaultFormValues);
|
||||||
|
}, [defaultFormValues, histories]);
|
||||||
|
|
||||||
const isDisabledInput = histories.length > 0;
|
const isDisabledInput = histories.length > 0;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
Reference in New Issue
Block a user