Skip to content

fix: workflow one step run form validate #14934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client'
import type { FC } from 'react'
import React, { useCallback, useMemo } from 'react'
import React, { useCallback, useEffect, useMemo, useRef } from 'react'
import produce from 'immer'
import type { InputVar } from '../../../../types'
import FormItem from './form-item'
Expand All @@ -9,7 +9,7 @@ import { InputVarType } from '@/app/components/workflow/types'
import AddButton from '@/app/components/base/button/add-button'
import { RETRIEVAL_OUTPUT_STRUCT } from '@/app/components/workflow/constants'

export interface Props {
export type Props = {
className?: string
label?: string
inputs: InputVar[]
Expand Down Expand Up @@ -46,17 +46,20 @@ const Form: FC<Props> = ({

return m
}, [inputs])

const valuesRef = useRef(values)
useEffect(() => {
valuesRef.current = values
}, [values])
const handleChange = useCallback((key: string) => {
const mKeys = mapKeysWithSameValueSelector.get(key) ?? [key]
return (value: any) => {
const newValues = produce(values, (draft) => {
const newValues = produce(valuesRef.current, (draft) => {
for (const k of mKeys)
draft[k] = value
})
onChange(newValues)
}
}, [values, onChange, mapKeysWithSameValueSelector])
}, [valuesRef, onChange, mapKeysWithSameValueSelector])
const isArrayLikeType = [InputVarType.contexts, InputVarType.iterator].includes(inputs[0]?.type)
const isContext = inputs[0]?.type === InputVarType.contexts
const handleAddContext = useCallback(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,20 @@ const BeforeRunForm: FC<BeforeRunFormProps> = ({
let errMsg = ''
forms.forEach((form) => {
form.inputs.forEach((input) => {
const value = form.values[input.variable]
const value = form.values[input.variable] as any
if (!errMsg && input.required && (value === '' || value === undefined || value === null || (input.type === InputVarType.files && value.length === 0)))
errMsg = t('workflow.errorMsg.fieldRequired', { field: typeof input.label === 'object' ? input.label.variable : input.label })

if (!errMsg && (input.type === InputVarType.singleFile || input.type === InputVarType.multiFiles) && value) {
let fileIsUploading = false
if (Array.isArray(value))
fileIsUploading = value.find(item => item.transferMethod === TransferMethod.local_file && !item.uploadedId)
else
fileIsUploading = value.transferMethod === TransferMethod.local_file && !value.uploadedId

if (fileIsUploading)
errMsg = t('appDebug.errorMessage.waitForFileUpload')
}
})
})
if (errMsg) {
Expand Down
Loading