feat: Add default value support for all workflow start node variable types (#24129)

Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
17hz
2025-08-22 18:44:48 +08:00
committed by GitHub
parent 51cc2bf429
commit ffe1685b54
6 changed files with 100 additions and 36 deletions

View File

@@ -1,5 +1,5 @@
import type { ChangeEvent, FC, FormEvent } from 'react'
import { useEffect } from 'react'
import { useEffect, useState } from 'react'
import React, { useCallback } from 'react'
import { useTranslation } from 'react-i18next'
import {
@@ -41,6 +41,7 @@ const RunOnce: FC<IRunOnceProps> = ({
const { t } = useTranslation()
const media = useBreakpoints()
const isPC = media === MediaType.pc
const [isInitialized, setIsInitialized] = useState(false)
const onClear = () => {
const newInputs: Record<string, any> = {}
@@ -64,16 +65,24 @@ const RunOnce: FC<IRunOnceProps> = ({
}, [onInputsChange, inputsRef])
useEffect(() => {
if (isInitialized) return
const newInputs: Record<string, any> = {}
promptConfig.prompt_variables.forEach((item) => {
if (item.type === 'select')
newInputs[item.key] = item.default
else if (item.type === 'string' || item.type === 'paragraph')
newInputs[item.key] = ''
newInputs[item.key] = item.default || ''
else if (item.type === 'number')
newInputs[item.key] = item.default
else if (item.type === 'file')
newInputs[item.key] = item.default
else if (item.type === 'file-list')
newInputs[item.key] = item.default || []
else
newInputs[item.key] = undefined
})
onInputsChange(newInputs)
setIsInitialized(true)
}, [promptConfig.prompt_variables, onInputsChange])
return (
@@ -81,7 +90,7 @@ const RunOnce: FC<IRunOnceProps> = ({
<section>
{/* input form */}
<form onSubmit={onSubmit}>
{(inputs === null || inputs === undefined || Object.keys(inputs).length === 0) ? null
{(inputs === null || inputs === undefined || Object.keys(inputs).length === 0) || !isInitialized ? null
: promptConfig.prompt_variables.map(item => (
<div className='mt-4 w-full' key={item.key}>
<label className='system-md-semibold flex h-6 items-center text-text-secondary'>{item.name}</label>
@@ -122,6 +131,7 @@ const RunOnce: FC<IRunOnceProps> = ({
)}
{item.type === 'file' && (
<FileUploaderInAttachmentWrapper
value={inputs[item.key] ? [inputs[item.key]] : []}
onChange={(files) => { handleInputsChange({ ...inputsRef.current, [item.key]: getProcessedFiles(files)[0] }) }}
fileConfig={{
...item.config,
@@ -131,6 +141,7 @@ const RunOnce: FC<IRunOnceProps> = ({
)}
{item.type === 'file-list' && (
<FileUploaderInAttachmentWrapper
value={inputs[item.key]}
onChange={(files) => { handleInputsChange({ ...inputsRef.current, [item.key]: getProcessedFiles(files) }) }}
fileConfig={{
...item.config,