Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

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

zxhlyh9ab4f35b84a5
diff --git a/web/app/components/workflow/nodes/_base/components/before-run-form/form.tsx b/web/app/components/workflow/nodes/_base/components/before-run-form/form.tsx
index e9ac4426804..be5de9018a8 100644
--- a/web/app/components/workflow/nodes/_base/components/before-run-form/form.tsx
+++ b/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(() => {
diff --git a/web/app/components/workflow/nodes/_base/components/before-run-form/index.tsx b/web/app/components/workflow/nodes/_base/components/before-run-form/index.tsx
index bd1b053395f..ee3e04c5a21 100644
--- a/web/app/components/workflow/nodes/_base/components/before-run-form/index.tsx
+++ b/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) {