瀏覽代碼

fix: workflow one step run form validate (#14934)

zxhlyh 1 月之前
父節點
當前提交
9ab4f35b84

+ 8 - 5
web/app/components/workflow/nodes/_base/components/before-run-form/form.tsx

@@ -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(() => {

+ 12 - 1
web/app/components/workflow/nodes/_base/components/before-run-form/index.tsx

@@ -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) {