mirror of
https://github.com/langgenius/dify.git
synced 2025-11-13 09:53:04 +00:00
refactor: update input type mappings and enums for consistency across components
This commit is contained in:
parent
c9bf99a1e2
commit
3af61f4b5d
@ -1,5 +1,5 @@
|
|||||||
import { InputVarType } from '@/app/components/workflow/types'
|
|
||||||
import { InputType } from './types'
|
import { InputType } from './types'
|
||||||
|
import { PipelineInputVarType } from '@/models/pipeline'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import {
|
import {
|
||||||
RiAlignLeft,
|
RiAlignLeft,
|
||||||
@ -12,28 +12,29 @@ import {
|
|||||||
} from '@remixicon/react'
|
} from '@remixicon/react'
|
||||||
|
|
||||||
const i18nFileTypeMap: Record<string, string> = {
|
const i18nFileTypeMap: Record<string, string> = {
|
||||||
|
'number-input': 'number',
|
||||||
'file': 'single-file',
|
'file': 'single-file',
|
||||||
'file-list': 'multi-files',
|
'file-list': 'multi-files',
|
||||||
}
|
}
|
||||||
|
|
||||||
const INPUT_TYPE_ICON = {
|
const INPUT_TYPE_ICON = {
|
||||||
[InputVarType.textInput]: RiTextSnippet,
|
[PipelineInputVarType.textInput]: RiTextSnippet,
|
||||||
[InputVarType.paragraph]: RiAlignLeft,
|
[PipelineInputVarType.paragraph]: RiAlignLeft,
|
||||||
[InputVarType.number]: RiHashtag,
|
[PipelineInputVarType.number]: RiHashtag,
|
||||||
[InputVarType.select]: RiListCheck3,
|
[PipelineInputVarType.select]: RiListCheck3,
|
||||||
[InputVarType.checkbox]: RiCheckboxLine,
|
[PipelineInputVarType.checkbox]: RiCheckboxLine,
|
||||||
[InputVarType.singleFile]: RiFileTextLine,
|
[PipelineInputVarType.singleFile]: RiFileTextLine,
|
||||||
[InputVarType.multiFiles]: RiFileCopy2Line,
|
[PipelineInputVarType.multiFiles]: RiFileCopy2Line,
|
||||||
}
|
}
|
||||||
|
|
||||||
const DATA_TYPE = {
|
const DATA_TYPE = {
|
||||||
[InputVarType.textInput]: 'string',
|
[PipelineInputVarType.textInput]: 'string',
|
||||||
[InputVarType.paragraph]: 'string',
|
[PipelineInputVarType.paragraph]: 'string',
|
||||||
[InputVarType.number]: 'number',
|
[PipelineInputVarType.number]: 'number',
|
||||||
[InputVarType.select]: 'string',
|
[PipelineInputVarType.select]: 'string',
|
||||||
[InputVarType.checkbox]: 'boolean',
|
[PipelineInputVarType.checkbox]: 'boolean',
|
||||||
[InputVarType.singleFile]: 'file',
|
[PipelineInputVarType.singleFile]: 'file',
|
||||||
[InputVarType.multiFiles]: 'array[file]',
|
[PipelineInputVarType.multiFiles]: 'array[file]',
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useInputTypeOptions = (supportFile: boolean) => {
|
export const useInputTypeOptions = (supportFile: boolean) => {
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import { z } from 'zod'
|
|||||||
export const InputType = z.enum([
|
export const InputType = z.enum([
|
||||||
'text-input',
|
'text-input',
|
||||||
'paragraph',
|
'paragraph',
|
||||||
'number',
|
'number-input',
|
||||||
'select',
|
'select',
|
||||||
'checkbox',
|
'checkbox',
|
||||||
'file',
|
'file',
|
||||||
|
|||||||
@ -3,13 +3,13 @@ import type { Option } from '../../../select/pure'
|
|||||||
import type { CustomActionsProps } from '../../components/form/actions'
|
import type { CustomActionsProps } from '../../components/form/actions'
|
||||||
|
|
||||||
export enum BaseFieldType {
|
export enum BaseFieldType {
|
||||||
textInput = 'textInput',
|
textInput = 'text-input',
|
||||||
paragraph = 'paragraph',
|
paragraph = 'paragraph',
|
||||||
numberInput = 'numberInput',
|
numberInput = 'number-input',
|
||||||
checkbox = 'checkbox',
|
checkbox = 'checkbox',
|
||||||
select = 'select',
|
select = 'select',
|
||||||
file = 'file',
|
file = 'file',
|
||||||
fileList = 'fileList',
|
fileList = 'file-list',
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ShowCondition = {
|
export type ShowCondition = {
|
||||||
|
|||||||
@ -10,6 +10,7 @@ export const generateZodSchema = (fields: BaseConfiguration[]) => {
|
|||||||
|
|
||||||
switch (field.type) {
|
switch (field.type) {
|
||||||
case BaseFieldType.textInput:
|
case BaseFieldType.textInput:
|
||||||
|
case BaseFieldType.paragraph:
|
||||||
zodType = z.string()
|
zodType = z.string()
|
||||||
break
|
break
|
||||||
case BaseFieldType.numberInput:
|
case BaseFieldType.numberInput:
|
||||||
@ -27,7 +28,7 @@ export const generateZodSchema = (fields: BaseConfiguration[]) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (field.maxLength) {
|
if (field.maxLength) {
|
||||||
if ([BaseFieldType.textInput].includes(field.type))
|
if ([BaseFieldType.textInput, BaseFieldType.paragraph].includes(field.type))
|
||||||
zodType = (zodType as ZodString).max(field.maxLength, `${field.label} exceeds max length of ${field.maxLength}`)
|
zodType = (zodType as ZodString).max(field.maxLength, `${field.label} exceeds max length of ${field.maxLength}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,7 +43,7 @@ export const generateZodSchema = (fields: BaseConfiguration[]) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (field.required) {
|
if (field.required) {
|
||||||
if ([BaseFieldType.textInput].includes(field.type))
|
if ([BaseFieldType.textInput, BaseFieldType.paragraph].includes(field.type))
|
||||||
zodType = (zodType as ZodString).nonempty(`${field.label} is required`)
|
zodType = (zodType as ZodString).nonempty(`${field.label} is required`)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@ -35,5 +35,5 @@ export type InputFieldConfiguration = {
|
|||||||
tooltip?: string // Tooltip for this field
|
tooltip?: string // Tooltip for this field
|
||||||
listeners?: FieldListeners<Record<string, any>, DeepKeys<Record<string, any>>> // Listener for this field
|
listeners?: FieldListeners<Record<string, any>, DeepKeys<Record<string, any>>> // Listener for this field
|
||||||
} & NumberConfiguration & Partial<InputTypeSelectConfiguration>
|
} & NumberConfiguration & Partial<InputTypeSelectConfiguration>
|
||||||
& Partial<NumberSliderConfiguration>
|
& Partial<NumberSliderConfiguration>
|
||||||
& Partial<SelectConfiguration>
|
& Partial<SelectConfiguration>
|
||||||
|
|||||||
@ -70,8 +70,8 @@ export const useConfigurations = (props: {
|
|||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { setFieldValue, supportFile } = props
|
const { setFieldValue, supportFile } = props
|
||||||
|
|
||||||
const handleTypeChange = useCallback((type: string) => {
|
const handleTypeChange = useCallback((type: PipelineInputVarType) => {
|
||||||
if ([PipelineInputVarType.singleFile, PipelineInputVarType.multiFiles].includes(type as PipelineInputVarType)) {
|
if ([PipelineInputVarType.singleFile, PipelineInputVarType.multiFiles].includes(type)) {
|
||||||
setFieldValue('allowedFileUploadMethods', DEFAULT_FILE_UPLOAD_SETTING.allowed_file_upload_methods)
|
setFieldValue('allowedFileUploadMethods', DEFAULT_FILE_UPLOAD_SETTING.allowed_file_upload_methods)
|
||||||
setFieldValue('allowedTypesAndExtensions', {
|
setFieldValue('allowedTypesAndExtensions', {
|
||||||
allowedFileTypes: DEFAULT_FILE_UPLOAD_SETTING.allowed_file_types,
|
allowedFileTypes: DEFAULT_FILE_UPLOAD_SETTING.allowed_file_types,
|
||||||
@ -92,7 +92,7 @@ export const useConfigurations = (props: {
|
|||||||
required: true,
|
required: true,
|
||||||
showConditions: [],
|
showConditions: [],
|
||||||
listeners: {
|
listeners: {
|
||||||
onChange: ({ value }) => handleTypeChange(value as string),
|
onChange: ({ value }) => handleTypeChange(value),
|
||||||
},
|
},
|
||||||
supportFile,
|
supportFile,
|
||||||
}, {
|
}, {
|
||||||
|
|||||||
@ -3,19 +3,10 @@ import type { TFunction } from 'i18next'
|
|||||||
import { z } from 'zod'
|
import { z } from 'zod'
|
||||||
import type { SchemaOptions } from './types'
|
import type { SchemaOptions } from './types'
|
||||||
import { PipelineInputVarType } from '@/models/pipeline'
|
import { PipelineInputVarType } from '@/models/pipeline'
|
||||||
|
import { InputType } from '@/app/components/base/form/components/field/input-type-select/types'
|
||||||
|
|
||||||
export const TEXT_MAX_LENGTH = 256
|
export const TEXT_MAX_LENGTH = 256
|
||||||
|
|
||||||
export const InputType = z.enum([
|
|
||||||
'text-input',
|
|
||||||
'paragraph',
|
|
||||||
'number',
|
|
||||||
'select',
|
|
||||||
'checkbox',
|
|
||||||
'file',
|
|
||||||
'file-list',
|
|
||||||
])
|
|
||||||
|
|
||||||
export const TransferMethod = z.enum([
|
export const TransferMethod = z.enum([
|
||||||
'all',
|
'all',
|
||||||
'local_file',
|
'local_file',
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import { PipelineInputVarType } from '@/models/pipeline'
|
|||||||
|
|
||||||
const VAR_TYPE_MAP: Record<PipelineInputVarType, BaseFieldType> = {
|
const VAR_TYPE_MAP: Record<PipelineInputVarType, BaseFieldType> = {
|
||||||
[PipelineInputVarType.textInput]: BaseFieldType.textInput,
|
[PipelineInputVarType.textInput]: BaseFieldType.textInput,
|
||||||
[PipelineInputVarType.paragraph]: BaseFieldType.textInput,
|
[PipelineInputVarType.paragraph]: BaseFieldType.paragraph,
|
||||||
[PipelineInputVarType.select]: BaseFieldType.select,
|
[PipelineInputVarType.select]: BaseFieldType.select,
|
||||||
[PipelineInputVarType.singleFile]: BaseFieldType.file,
|
[PipelineInputVarType.singleFile]: BaseFieldType.file,
|
||||||
[PipelineInputVarType.multiFiles]: BaseFieldType.fileList,
|
[PipelineInputVarType.multiFiles]: BaseFieldType.fileList,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user