refactor: update input type mappings and enums for consistency across components

This commit is contained in:
twwu 2025-05-23 16:57:27 +08:00
parent c9bf99a1e2
commit 3af61f4b5d
8 changed files with 30 additions and 37 deletions

View File

@ -1,5 +1,5 @@
import { InputVarType } from '@/app/components/workflow/types'
import { InputType } from './types'
import { PipelineInputVarType } from '@/models/pipeline'
import { useTranslation } from 'react-i18next'
import {
RiAlignLeft,
@ -12,28 +12,29 @@ import {
} from '@remixicon/react'
const i18nFileTypeMap: Record<string, string> = {
'number-input': 'number',
'file': 'single-file',
'file-list': 'multi-files',
}
const INPUT_TYPE_ICON = {
[InputVarType.textInput]: RiTextSnippet,
[InputVarType.paragraph]: RiAlignLeft,
[InputVarType.number]: RiHashtag,
[InputVarType.select]: RiListCheck3,
[InputVarType.checkbox]: RiCheckboxLine,
[InputVarType.singleFile]: RiFileTextLine,
[InputVarType.multiFiles]: RiFileCopy2Line,
[PipelineInputVarType.textInput]: RiTextSnippet,
[PipelineInputVarType.paragraph]: RiAlignLeft,
[PipelineInputVarType.number]: RiHashtag,
[PipelineInputVarType.select]: RiListCheck3,
[PipelineInputVarType.checkbox]: RiCheckboxLine,
[PipelineInputVarType.singleFile]: RiFileTextLine,
[PipelineInputVarType.multiFiles]: RiFileCopy2Line,
}
const DATA_TYPE = {
[InputVarType.textInput]: 'string',
[InputVarType.paragraph]: 'string',
[InputVarType.number]: 'number',
[InputVarType.select]: 'string',
[InputVarType.checkbox]: 'boolean',
[InputVarType.singleFile]: 'file',
[InputVarType.multiFiles]: 'array[file]',
[PipelineInputVarType.textInput]: 'string',
[PipelineInputVarType.paragraph]: 'string',
[PipelineInputVarType.number]: 'number',
[PipelineInputVarType.select]: 'string',
[PipelineInputVarType.checkbox]: 'boolean',
[PipelineInputVarType.singleFile]: 'file',
[PipelineInputVarType.multiFiles]: 'array[file]',
}
export const useInputTypeOptions = (supportFile: boolean) => {

View File

@ -4,7 +4,7 @@ import { z } from 'zod'
export const InputType = z.enum([
'text-input',
'paragraph',
'number',
'number-input',
'select',
'checkbox',
'file',

View File

@ -3,13 +3,13 @@ import type { Option } from '../../../select/pure'
import type { CustomActionsProps } from '../../components/form/actions'
export enum BaseFieldType {
textInput = 'textInput',
textInput = 'text-input',
paragraph = 'paragraph',
numberInput = 'numberInput',
numberInput = 'number-input',
checkbox = 'checkbox',
select = 'select',
file = 'file',
fileList = 'fileList',
fileList = 'file-list',
}
export type ShowCondition = {

View File

@ -10,6 +10,7 @@ export const generateZodSchema = (fields: BaseConfiguration[]) => {
switch (field.type) {
case BaseFieldType.textInput:
case BaseFieldType.paragraph:
zodType = z.string()
break
case BaseFieldType.numberInput:
@ -27,7 +28,7 @@ export const generateZodSchema = (fields: BaseConfiguration[]) => {
}
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}`)
}
@ -42,7 +43,7 @@ export const generateZodSchema = (fields: BaseConfiguration[]) => {
}
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`)
}
else {

View File

@ -35,5 +35,5 @@ export type InputFieldConfiguration = {
tooltip?: string // Tooltip for this field
listeners?: FieldListeners<Record<string, any>, DeepKeys<Record<string, any>>> // Listener for this field
} & NumberConfiguration & Partial<InputTypeSelectConfiguration>
& Partial<NumberSliderConfiguration>
& Partial<SelectConfiguration>
& Partial<NumberSliderConfiguration>
& Partial<SelectConfiguration>

View File

@ -70,8 +70,8 @@ export const useConfigurations = (props: {
const { t } = useTranslation()
const { setFieldValue, supportFile } = props
const handleTypeChange = useCallback((type: string) => {
if ([PipelineInputVarType.singleFile, PipelineInputVarType.multiFiles].includes(type as PipelineInputVarType)) {
const handleTypeChange = useCallback((type: PipelineInputVarType) => {
if ([PipelineInputVarType.singleFile, PipelineInputVarType.multiFiles].includes(type)) {
setFieldValue('allowedFileUploadMethods', DEFAULT_FILE_UPLOAD_SETTING.allowed_file_upload_methods)
setFieldValue('allowedTypesAndExtensions', {
allowedFileTypes: DEFAULT_FILE_UPLOAD_SETTING.allowed_file_types,
@ -92,7 +92,7 @@ export const useConfigurations = (props: {
required: true,
showConditions: [],
listeners: {
onChange: ({ value }) => handleTypeChange(value as string),
onChange: ({ value }) => handleTypeChange(value),
},
supportFile,
}, {

View File

@ -3,19 +3,10 @@ import type { TFunction } from 'i18next'
import { z } from 'zod'
import type { SchemaOptions } from './types'
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 InputType = z.enum([
'text-input',
'paragraph',
'number',
'select',
'checkbox',
'file',
'file-list',
])
export const TransferMethod = z.enum([
'all',
'local_file',

View File

@ -7,7 +7,7 @@ import { PipelineInputVarType } from '@/models/pipeline'
const VAR_TYPE_MAP: Record<PipelineInputVarType, BaseFieldType> = {
[PipelineInputVarType.textInput]: BaseFieldType.textInput,
[PipelineInputVarType.paragraph]: BaseFieldType.textInput,
[PipelineInputVarType.paragraph]: BaseFieldType.paragraph,
[PipelineInputVarType.select]: BaseFieldType.select,
[PipelineInputVarType.singleFile]: BaseFieldType.file,
[PipelineInputVarType.multiFiles]: BaseFieldType.fileList,