| <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 => ({ |
| defaultSelect = existed | defaultSelect = existed | ||||
| setSelectedItem(defaultSelect) | setSelectedItem(defaultSelect) | ||||
| // eslint-disable-next-line react-hooks/exhaustive-deps | |||||
| }, [defaultValue]) | }, [defaultValue]) | ||||
| const filteredItems: Item[] | const filteredItems: Item[] | ||||
| 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) | ||||
| > | > | ||||
| <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'} | ||||
| `} | `} | ||||
| > | > |
| 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 |
| import { | import { | ||||
| memo, | memo, | ||||
| useCallback, | useCallback, | ||||
| useEffect, | |||||
| useMemo, | useMemo, | ||||
| } from 'react' | } from 'react' | ||||
| import { useTranslation } from 'react-i18next' | import { useTranslation } from 'react-i18next' | ||||
| 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 { | ||||
| 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) { |
| 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') { | ||||
| 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) |