Skip to content

Commit b77628c

Browse files
authored
fix: text-generation webapp file form (#10578)
1 parent 40c5e6d commit b77628c

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

web/app/components/share/text-generation/index.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ const TextGeneration: FC<IMainProps> = ({
9494
const [isCallBatchAPI, setIsCallBatchAPI] = useState(false)
9595
const isInBatchTab = currentTab === 'batch'
9696
const [inputs, setInputs] = useState<Record<string, any>>({})
97+
const inputsRef = useRef(inputs)
9798
const [appId, setAppId] = useState<string>('')
9899
const [siteInfo, setSiteInfo] = useState<SiteInfo | null>(null)
99100
const [canReplaceLogo, setCanReplaceLogo] = useState<boolean>(false)
@@ -604,6 +605,7 @@ const TextGeneration: FC<IMainProps> = ({
604605
<RunOnce
605606
siteInfo={siteInfo}
606607
inputs={inputs}
608+
inputsRef={inputsRef}
607609
onInputsChange={setInputs}
608610
promptConfig={promptConfig}
609611
onSend={handleSend}

web/app/components/share/text-generation/run-once/index.tsx

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { FC, FormEvent } from 'react'
2-
import React from 'react'
2+
import React, { useCallback } from 'react'
33
import { useTranslation } from 'react-i18next'
44
import {
55
PlayIcon,
@@ -19,6 +19,7 @@ export type IRunOnceProps = {
1919
siteInfo: SiteInfo
2020
promptConfig: PromptConfig
2121
inputs: Record<string, any>
22+
inputsRef: React.MutableRefObject<Record<string, any>>
2223
onInputsChange: (inputs: Record<string, any>) => void
2324
onSend: () => void
2425
visionConfig: VisionSettings
@@ -27,6 +28,7 @@ export type IRunOnceProps = {
2728
const RunOnce: FC<IRunOnceProps> = ({
2829
promptConfig,
2930
inputs,
31+
inputsRef,
3032
onInputsChange,
3133
onSend,
3234
visionConfig,
@@ -47,6 +49,11 @@ const RunOnce: FC<IRunOnceProps> = ({
4749
onSend()
4850
}
4951

52+
const handleInputsChange = useCallback((newInputs: Record<string, any>) => {
53+
onInputsChange(newInputs)
54+
inputsRef.current = newInputs
55+
}, [onInputsChange, inputsRef])
56+
5057
return (
5158
<div className="">
5259
<section>
@@ -60,7 +67,7 @@ const RunOnce: FC<IRunOnceProps> = ({
6067
<Select
6168
className='w-full'
6269
defaultValue={inputs[item.key]}
63-
onSelect={(i) => { onInputsChange({ ...inputs, [item.key]: i.value }) }}
70+
onSelect={(i) => { handleInputsChange({ ...inputsRef.current, [item.key]: i.value }) }}
6471
items={(item.options || []).map(i => ({ name: i, value: i }))}
6572
allowSearch={false}
6673
bgClassName='bg-gray-50'
@@ -72,7 +79,7 @@ const RunOnce: FC<IRunOnceProps> = ({
7279
className="block w-full p-2 text-gray-900 border border-gray-300 rounded-lg bg-gray-50 sm:text-xs focus:ring-blue-500 focus:border-blue-500 "
7380
placeholder={`${item.name}${!item.required ? `(${t('appDebug.variableTable.optional')})` : ''}`}
7481
value={inputs[item.key]}
75-
onChange={(e) => { onInputsChange({ ...inputs, [item.key]: e.target.value }) }}
82+
onChange={(e) => { handleInputsChange({ ...inputsRef.current, [item.key]: e.target.value }) }}
7683
maxLength={item.max_length || DEFAULT_VALUE_MAX_LEN}
7784
/>
7885
)}
@@ -81,7 +88,7 @@ const RunOnce: FC<IRunOnceProps> = ({
8188
className='h-[104px] sm:text-xs'
8289
placeholder={`${item.name}${!item.required ? `(${t('appDebug.variableTable.optional')})` : ''}`}
8390
value={inputs[item.key]}
84-
onChange={(e) => { onInputsChange({ ...inputs, [item.key]: e.target.value }) }}
91+
onChange={(e) => { handleInputsChange({ ...inputsRef.current, [item.key]: e.target.value }) }}
8592
/>
8693
)}
8794
{item.type === 'number' && (
@@ -90,12 +97,12 @@ const RunOnce: FC<IRunOnceProps> = ({
9097
className="block w-full p-2 text-gray-900 border border-gray-300 rounded-lg bg-gray-50 sm:text-xs focus:ring-blue-500 focus:border-blue-500 "
9198
placeholder={`${item.name}${!item.required ? `(${t('appDebug.variableTable.optional')})` : ''}`}
9299
value={inputs[item.key]}
93-
onChange={(e) => { onInputsChange({ ...inputs, [item.key]: e.target.value }) }}
100+
onChange={(e) => { handleInputsChange({ ...inputsRef.current, [item.key]: e.target.value }) }}
94101
/>
95102
)}
96103
{item.type === 'file' && (
97104
<FileUploaderInAttachmentWrapper
98-
onChange={(files) => { onInputsChange({ ...inputs, [item.key]: getProcessedFiles(files)[0] }) }}
105+
onChange={(files) => { handleInputsChange({ ...inputsRef.current, [item.key]: getProcessedFiles(files)[0] }) }}
99106
fileConfig={{
100107
...item.config,
101108
fileUploadConfig: (visionConfig as any).fileUploadConfig,
@@ -104,7 +111,7 @@ const RunOnce: FC<IRunOnceProps> = ({
104111
)}
105112
{item.type === 'file-list' && (
106113
<FileUploaderInAttachmentWrapper
107-
onChange={(files) => { onInputsChange({ ...inputs, [item.key]: getProcessedFiles(files) }) }}
114+
onChange={(files) => { handleInputsChange({ ...inputsRef.current, [item.key]: getProcessedFiles(files) }) }}
108115
fileConfig={{
109116
...item.config,
110117
fileUploadConfig: (visionConfig as any).fileUploadConfig,

0 commit comments

Comments
 (0)