mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-12 17:09:03 +08:00
fix: workflow one step run form validate (#14934)
This commit is contained in:
parent
4668c4996a
commit
9ab4f35b84
@ -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'
|
||||
@ -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[]
|
||||
@ -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(() => {
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user