Fix variable config (#23070)
This commit is contained in:
@@ -244,6 +244,7 @@ const ConfigModal: FC<IConfigModalProps> = ({
|
|||||||
<SimpleSelect
|
<SimpleSelect
|
||||||
key={`default-select-${options.join('-')}`}
|
key={`default-select-${options.join('-')}`}
|
||||||
className="w-full"
|
className="w-full"
|
||||||
|
optionWrapClassName="max-h-[140px] overflow-y-auto"
|
||||||
items={[
|
items={[
|
||||||
{ value: '', name: t('appDebug.variableConfig.noDefaultValue') },
|
{ value: '', name: t('appDebug.variableConfig.noDefaultValue') },
|
||||||
...options.filter(opt => opt.trim() !== '').map(option => ({
|
...options.filter(opt => opt.trim() !== '').map(option => ({
|
||||||
|
@@ -77,7 +77,6 @@ const Select: FC<ISelectProps> = ({
|
|||||||
defaultSelect = existed
|
defaultSelect = existed
|
||||||
|
|
||||||
setSelectedItem(defaultSelect)
|
setSelectedItem(defaultSelect)
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
||||||
}, [defaultValue])
|
}, [defaultValue])
|
||||||
|
|
||||||
const filteredItems: Item[]
|
const filteredItems: Item[]
|
||||||
@@ -201,7 +200,6 @@ const SimpleSelect: FC<ISelectProps> = ({
|
|||||||
defaultSelect = existed
|
defaultSelect = existed
|
||||||
|
|
||||||
setSelectedItem(defaultSelect)
|
setSelectedItem(defaultSelect)
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
||||||
}, [defaultValue])
|
}, [defaultValue])
|
||||||
|
|
||||||
const listboxRef = useRef<HTMLDivElement>(null)
|
const listboxRef = useRef<HTMLDivElement>(null)
|
||||||
@@ -344,7 +342,7 @@ const PortalSelect: FC<PortalSelectProps> = ({
|
|||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
className={`
|
className={`
|
||||||
grow truncate
|
grow truncate text-text-secondary
|
||||||
${!selectedItem?.name && 'text-components-input-text-placeholder'}
|
${!selectedItem?.name && 'text-components-input-text-placeholder'}
|
||||||
`}
|
`}
|
||||||
>
|
>
|
||||||
|
@@ -66,7 +66,9 @@ const RunOnce: FC<IRunOnceProps> = ({
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const newInputs: Record<string, any> = {}
|
const newInputs: Record<string, any> = {}
|
||||||
promptConfig.prompt_variables.forEach((item) => {
|
promptConfig.prompt_variables.forEach((item) => {
|
||||||
if (item.type === 'string' || item.type === 'paragraph')
|
if (item.type === 'select')
|
||||||
|
newInputs[item.key] = item.default
|
||||||
|
else if (item.type === 'string' || item.type === 'paragraph')
|
||||||
newInputs[item.key] = ''
|
newInputs[item.key] = ''
|
||||||
else
|
else
|
||||||
newInputs[item.key] = undefined
|
newInputs[item.key] = undefined
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
memo,
|
memo,
|
||||||
useCallback,
|
useCallback,
|
||||||
|
useEffect,
|
||||||
useMemo,
|
useMemo,
|
||||||
} from 'react'
|
} from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
@@ -32,9 +33,12 @@ type Props = {
|
|||||||
const InputsPanel = ({ onRun }: Props) => {
|
const InputsPanel = ({ onRun }: Props) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const workflowStore = useWorkflowStore()
|
const workflowStore = useWorkflowStore()
|
||||||
|
const { inputs, setInputs } = useStore(s => ({
|
||||||
|
inputs: s.inputs,
|
||||||
|
setInputs: s.setInputs,
|
||||||
|
}))
|
||||||
const fileSettings = useFeatures(s => s.features.file)
|
const fileSettings = useFeatures(s => s.features.file)
|
||||||
const nodes = useNodes<StartNodeType>()
|
const nodes = useNodes<StartNodeType>()
|
||||||
const inputs = useStore(s => s.inputs)
|
|
||||||
const files = useStore(s => s.files)
|
const files = useStore(s => s.files)
|
||||||
const workflowRunningData = useStore(s => s.workflowRunningData)
|
const workflowRunningData = useStore(s => s.workflowRunningData)
|
||||||
const {
|
const {
|
||||||
@@ -44,6 +48,24 @@ const InputsPanel = ({ onRun }: Props) => {
|
|||||||
const startVariables = startNode?.data.variables
|
const startVariables = startNode?.data.variables
|
||||||
const { checkInputsForm } = useCheckInputsForms()
|
const { checkInputsForm } = useCheckInputsForms()
|
||||||
|
|
||||||
|
const initialInputs = useMemo(() => {
|
||||||
|
const initInputs: Record<string, any> = {}
|
||||||
|
if (startVariables) {
|
||||||
|
startVariables.forEach((variable) => {
|
||||||
|
if (variable.default)
|
||||||
|
initInputs[variable.variable] = variable.default
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return initInputs
|
||||||
|
}, [startVariables])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setInputs({
|
||||||
|
...initialInputs,
|
||||||
|
...inputs,
|
||||||
|
})
|
||||||
|
}, [initialInputs])
|
||||||
|
|
||||||
const variables = useMemo(() => {
|
const variables = useMemo(() => {
|
||||||
const data = startVariables || []
|
const data = startVariables || []
|
||||||
if (fileSettings?.image?.enabled) {
|
if (fileSettings?.image?.enabled) {
|
||||||
|
@@ -62,6 +62,7 @@ export const userInputsFormToPromptVariables = (useInputs: UserInputFormItem[] |
|
|||||||
options: content.options,
|
options: content.options,
|
||||||
is_context_var,
|
is_context_var,
|
||||||
hide: content.hide,
|
hide: content.hide,
|
||||||
|
default: content.default,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
else if (type === 'file') {
|
else if (type === 'file') {
|
||||||
@@ -148,7 +149,7 @@ export const promptVariablesToUserInputsForm = (promptVariables: PromptVariable[
|
|||||||
variable: item.key,
|
variable: item.key,
|
||||||
required: item.required !== false, // default true
|
required: item.required !== false, // default true
|
||||||
options: item.options,
|
options: item.options,
|
||||||
default: '',
|
default: item.default ?? '',
|
||||||
hide: item.hide,
|
hide: item.hide,
|
||||||
},
|
},
|
||||||
} as any)
|
} as any)
|
||||||
|
Reference in New Issue
Block a user