mirror of
https://github.com/labring/FastGPT.git
synced 2025-08-01 11:58:38 +00:00
fix: plugin input default value & validate (#2171)
* fix: plugin input default value & validate * delete console
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import React from 'react';
|
||||
import React, { useEffect } from 'react';
|
||||
import { Controller } from 'react-hook-form';
|
||||
import RenderPluginInput from './renderPluginInput';
|
||||
import { Button, Flex } from '@chakra-ui/react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useContextSelector } from 'use-context-selector';
|
||||
import { PluginRunContext } from '../context';
|
||||
import { WorkflowIOValueTypeEnum } from '@fastgpt/global/core/workflow/constants';
|
||||
|
||||
const RenderInput = () => {
|
||||
const { pluginInputs, variablesForm, histories, onStartChat, onNewChat, onSubmit, isChatting } =
|
||||
@@ -14,8 +15,21 @@ const RenderInput = () => {
|
||||
const {
|
||||
control,
|
||||
handleSubmit,
|
||||
reset,
|
||||
formState: { errors }
|
||||
} = variablesForm;
|
||||
|
||||
useEffect(() => {
|
||||
reset(
|
||||
pluginInputs.reduce(
|
||||
(acc, input) => {
|
||||
acc[input.key] = input.defaultValue;
|
||||
return acc;
|
||||
},
|
||||
{} as Record<string, any>
|
||||
)
|
||||
);
|
||||
}, [pluginInputs, histories]);
|
||||
const isDisabledInput = histories.length > 0;
|
||||
|
||||
return (
|
||||
@@ -26,7 +40,14 @@ const RenderInput = () => {
|
||||
key={input.key}
|
||||
control={control}
|
||||
name={input.key}
|
||||
rules={{ required: input.required }}
|
||||
rules={{
|
||||
validate: (value) => {
|
||||
if (input.valueType === WorkflowIOValueTypeEnum.boolean) {
|
||||
return value !== undefined;
|
||||
}
|
||||
return !!value;
|
||||
}
|
||||
}}
|
||||
render={({ field: { onChange, value } }) => {
|
||||
return (
|
||||
<RenderPluginInput
|
||||
|
@@ -18,6 +18,7 @@ const JsonEditor = dynamic(() => import('@fastgpt/web/components/common/Textarea
|
||||
|
||||
const RenderPluginInput = ({
|
||||
value,
|
||||
defaultValue,
|
||||
onChange,
|
||||
label,
|
||||
description,
|
||||
@@ -30,6 +31,7 @@ const RenderPluginInput = ({
|
||||
isInvalid
|
||||
}: {
|
||||
value: any;
|
||||
defaultValue?: any;
|
||||
onChange: () => void;
|
||||
label: string;
|
||||
description?: string;
|
||||
@@ -48,6 +50,7 @@ const RenderPluginInput = ({
|
||||
return (
|
||||
<Textarea
|
||||
value={value}
|
||||
defaultValue={defaultValue}
|
||||
onChange={onChange}
|
||||
isDisabled={isDisabled}
|
||||
placeholder={t(placeholder as any)}
|
||||
@@ -66,7 +69,7 @@ const RenderPluginInput = ({
|
||||
isDisabled={isDisabled}
|
||||
isInvalid={isInvalid}
|
||||
>
|
||||
<NumberInputField value={value} onChange={onChange} />
|
||||
<NumberInputField value={value} onChange={onChange} defaultValue={defaultValue} />
|
||||
<NumberInputStepper>
|
||||
<NumberIncrementStepper />
|
||||
<NumberDecrementStepper />
|
||||
@@ -81,6 +84,7 @@ const RenderPluginInput = ({
|
||||
onChange={onChange}
|
||||
isDisabled={isDisabled}
|
||||
isInvalid={isInvalid}
|
||||
defaultChecked={defaultValue}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -93,6 +97,7 @@ const RenderPluginInput = ({
|
||||
value={value}
|
||||
onChange={onChange}
|
||||
isInvalid={isInvalid}
|
||||
defaultValue={defaultValue}
|
||||
/>
|
||||
);
|
||||
})();
|
||||
|
Reference in New Issue
Block a user