From 15757110cff780a72637b52037676f598e0a4072 Mon Sep 17 00:00:00 2001 From: Anton Kovalev Date: Mon, 28 Jul 2025 10:37:23 +0300 Subject: [PATCH] feat: default value option for select input fields (#21192) Co-authored-by: crazywoola <427733928@qq.com> Co-authored-by: GuanMu --- .../config-var/config-modal/index.tsx | 28 +++++++++++++-- .../base/chat/chat-with-history/hooks.tsx | 2 +- .../chat-with-history/inputs-form/content.tsx | 2 +- .../base/chat/embedded-chatbot/hooks.tsx | 2 +- .../embedded-chatbot/inputs-form/content.tsx | 2 +- .../components/before-run-form/form-item.tsx | 2 +- .../panel/debug-and-preview/chat-wrapper.tsx | 35 +++++++++++++++++-- web/i18n/de-DE/app-debug.ts | 3 ++ web/i18n/en-US/app-debug.ts | 3 ++ web/i18n/es-ES/app-debug.ts | 3 ++ web/i18n/fr-FR/app-debug.ts | 3 ++ web/i18n/hi-IN/app-debug.ts | 3 ++ web/i18n/it-IT/app-debug.ts | 3 ++ web/i18n/ja-JP/app-debug.ts | 3 ++ web/i18n/ko-KR/app-debug.ts | 3 ++ web/i18n/pl-PL/app-debug.ts | 3 ++ web/i18n/pt-BR/app-debug.ts | 3 ++ web/i18n/ro-RO/app-debug.ts | 3 ++ web/i18n/ru-RU/app-debug.ts | 3 ++ web/i18n/tr-TR/app-debug.ts | 3 ++ web/i18n/uk-UA/app-debug.ts | 3 ++ web/i18n/vi-VN/app-debug.ts | 3 ++ web/i18n/zh-Hans/app-debug.ts | 3 ++ web/i18n/zh-Hant/app-debug.ts | 3 ++ 24 files changed, 113 insertions(+), 11 deletions(-) diff --git a/web/app/components/app/configuration/config-var/config-modal/index.tsx b/web/app/components/app/configuration/config-var/config-modal/index.tsx index 8fcc0f4c0..72c66cf76 100644 --- a/web/app/components/app/configuration/config-var/config-modal/index.tsx +++ b/web/app/components/app/configuration/config-var/config-modal/index.tsx @@ -20,6 +20,7 @@ import FileUploadSetting from '@/app/components/workflow/nodes/_base/components/ import Checkbox from '@/app/components/base/checkbox' import { DEFAULT_FILE_UPLOAD_SETTING } from '@/app/components/workflow/constants' import { DEFAULT_VALUE_MAX_LEN } from '@/config' +import { SimpleSelect } from '@/app/components/base/select' const TEXT_MAX_LENGTH = 256 @@ -234,9 +235,30 @@ const ConfigModal: FC = ({ )} {type === InputVarType.select && ( - - - + <> + + + + {options && options.length > 0 && ( + + opt.trim() !== '').map(option => ({ + value: option, + name: option, + })), + ]} + defaultValue={tempPayload.default || ''} + onSelect={item => handlePayloadChange('default')(item.value === '' ? undefined : item.value)} + placeholder={t('appDebug.variableConfig.selectDefaultValue')} + allowSearch={false} + /> + + )} + )} {[InputVarType.singleFile, InputVarType.multiFiles].includes(type) && ( diff --git a/web/app/components/base/chat/chat-with-history/hooks.tsx b/web/app/components/base/chat/chat-with-history/hooks.tsx index 76eb89164..382ded320 100644 --- a/web/app/components/base/chat/chat-with-history/hooks.tsx +++ b/web/app/components/base/chat/chat-with-history/hooks.tsx @@ -211,7 +211,7 @@ export const useChatWithHistory = (installedAppInfo?: InstalledApp) => { const isInputInOptions = item.select.options.includes(initInputs[item.select.variable]) return { ...item.select, - default: (isInputInOptions ? initInputs[item.select.variable] : undefined) || item.default, + default: (isInputInOptions ? initInputs[item.select.variable] : undefined) || item.select.default, type: 'select', } } diff --git a/web/app/components/base/chat/chat-with-history/inputs-form/content.tsx b/web/app/components/base/chat/chat-with-history/inputs-form/content.tsx index 73a1f07b6..3304d50a5 100644 --- a/web/app/components/base/chat/chat-with-history/inputs-form/content.tsx +++ b/web/app/components/base/chat/chat-with-history/inputs-form/content.tsx @@ -73,7 +73,7 @@ const InputsFormContent = ({ showTip }: Props) => { {form.type === InputVarType.select && ( ({ value: option, name: option }))} onSelect={item => handleFormChange(form.variable, item.value as string)} placeholder={form.label} diff --git a/web/app/components/base/chat/embedded-chatbot/hooks.tsx b/web/app/components/base/chat/embedded-chatbot/hooks.tsx index 8ae86bda8..4e86ad50e 100644 --- a/web/app/components/base/chat/embedded-chatbot/hooks.tsx +++ b/web/app/components/base/chat/embedded-chatbot/hooks.tsx @@ -199,7 +199,7 @@ export const useEmbeddedChatbot = () => { const isInputInOptions = item.select.options.includes(initInputs[item.select.variable]) return { ...item.select, - default: (isInputInOptions ? initInputs[item.select.variable] : undefined) || item.default, + default: (isInputInOptions ? initInputs[item.select.variable] : undefined) || item.select.default, type: 'select', } } diff --git a/web/app/components/base/chat/embedded-chatbot/inputs-form/content.tsx b/web/app/components/base/chat/embedded-chatbot/inputs-form/content.tsx index c5f39718f..29fa5394e 100644 --- a/web/app/components/base/chat/embedded-chatbot/inputs-form/content.tsx +++ b/web/app/components/base/chat/embedded-chatbot/inputs-form/content.tsx @@ -73,7 +73,7 @@ const InputsFormContent = ({ showTip }: Props) => { {form.type === InputVarType.select && ( ({ value: option, name: option }))} onSelect={item => handleFormChange(form.variable, item.value as string)} placeholder={form.label} diff --git a/web/app/components/workflow/nodes/_base/components/before-run-form/form-item.tsx b/web/app/components/workflow/nodes/_base/components/before-run-form/form-item.tsx index 269f5e0a9..430359b84 100644 --- a/web/app/components/workflow/nodes/_base/components/before-run-form/form-item.tsx +++ b/web/app/components/workflow/nodes/_base/components/before-run-form/form-item.tsx @@ -158,7 +158,7 @@ const FormItem: FC = ({ type === InputVarType.select && (