mirror of
https://github.com/langgenius/dify.git
synced 2026-05-06 02:18:08 +08:00
feat: Implement document processing component with configuration and action handling
This commit is contained in:
@ -5,7 +5,7 @@ import Button from '../../../button'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
type ActionsProps = {
|
||||
CustomActions?: (form: FormType) => React.ReactNode
|
||||
CustomActions?: (form: FormType) => React.ReactNode | React.JSX.Element
|
||||
}
|
||||
|
||||
const Actions = ({
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import type { ZodSchema, ZodString } from 'zod'
|
||||
import type { ZodNumber, ZodSchema, ZodString } from 'zod'
|
||||
import { z } from 'zod'
|
||||
import { type BaseConfiguration, BaseFieldType } from './types'
|
||||
|
||||
@ -26,6 +26,21 @@ export const generateZodSchema = <T>(fields: BaseConfiguration<T>[]) => {
|
||||
break
|
||||
}
|
||||
|
||||
if (field.maxLength) {
|
||||
if ([BaseFieldType.textInput].includes(field.type))
|
||||
zodType = (zodType as ZodString).max(field.maxLength, `${field.label} exceeds max length of ${field.maxLength}`)
|
||||
}
|
||||
|
||||
if (field.min) {
|
||||
if ([BaseFieldType.numberInput].includes(field.type))
|
||||
zodType = (zodType as ZodNumber).min(field.min, `${field.label} must be at least ${field.min}`)
|
||||
}
|
||||
|
||||
if (field.max) {
|
||||
if ([BaseFieldType.numberInput].includes(field.type))
|
||||
zodType = (zodType as ZodNumber).max(field.max, `${field.label} exceeds max value of ${field.max}`)
|
||||
}
|
||||
|
||||
if (field.required) {
|
||||
if ([BaseFieldType.textInput].includes(field.type))
|
||||
zodType = (zodType as ZodString).nonempty(`${field.label} is required`)
|
||||
@ -34,21 +49,6 @@ export const generateZodSchema = <T>(fields: BaseConfiguration<T>[]) => {
|
||||
zodType = zodType.optional()
|
||||
}
|
||||
|
||||
if (field.maxLength) {
|
||||
if ([BaseFieldType.textInput].includes(field.type))
|
||||
zodType = (zodType as ZodString).max(field.maxLength, `${field.label} exceeds max length of ${field.maxLength}`)
|
||||
}
|
||||
|
||||
if (field.min) {
|
||||
if ([BaseFieldType.numberInput].includes(field.type))
|
||||
zodType = (zodType as ZodString).min(field.min, `${field.label} must be at least ${field.min}`)
|
||||
}
|
||||
|
||||
if (field.max) {
|
||||
if ([BaseFieldType.numberInput].includes(field.type))
|
||||
zodType = (zodType as ZodString).max(field.max, `${field.label} exceeds max value of ${field.max}`)
|
||||
}
|
||||
|
||||
shape[field.variable] = zodType
|
||||
})
|
||||
|
||||
|
||||
@ -45,14 +45,6 @@ export const generateZodSchema = <T>(fields: InputFieldConfiguration<T>[]) => {
|
||||
break
|
||||
}
|
||||
|
||||
if (field.required) {
|
||||
if ([InputFieldType.textInput].includes(field.type))
|
||||
zodType = (zodType as ZodString).nonempty(`${field.label} is required`)
|
||||
}
|
||||
else {
|
||||
zodType = zodType.optional()
|
||||
}
|
||||
|
||||
if (field.maxLength) {
|
||||
if ([InputFieldType.textInput].includes(field.type))
|
||||
zodType = (zodType as ZodString).max(field.maxLength, `${field.label} exceeds max length of ${field.maxLength}`)
|
||||
@ -68,6 +60,14 @@ export const generateZodSchema = <T>(fields: InputFieldConfiguration<T>[]) => {
|
||||
zodType = (zodType as ZodString).max(field.max, `${field.label} exceeds max value of ${field.max}`)
|
||||
}
|
||||
|
||||
if (field.required) {
|
||||
if ([InputFieldType.textInput].includes(field.type))
|
||||
zodType = (zodType as ZodString).nonempty(`${field.label} is required`)
|
||||
}
|
||||
else {
|
||||
zodType = zodType.optional()
|
||||
}
|
||||
|
||||
shape[field.variable] = zodType
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user