diff --git a/web/app/components/base/form/components/field/input-type-select/hooks.tsx b/web/app/components/base/form/components/field/input-type-select/hooks.tsx index 44a3b2a67b..7ec5b40474 100644 --- a/web/app/components/base/form/components/field/input-type-select/hooks.tsx +++ b/web/app/components/base/form/components/field/input-type-select/hooks.tsx @@ -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 = { + '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) => { diff --git a/web/app/components/base/form/components/field/input-type-select/types.tsx b/web/app/components/base/form/components/field/input-type-select/types.tsx index 751061b11f..8f059c0faa 100644 --- a/web/app/components/base/form/components/field/input-type-select/types.tsx +++ b/web/app/components/base/form/components/field/input-type-select/types.tsx @@ -4,7 +4,7 @@ import { z } from 'zod' export const InputType = z.enum([ 'text-input', 'paragraph', - 'number', + 'number-input', 'select', 'checkbox', 'file', diff --git a/web/app/components/base/form/form-scenarios/base/types.ts b/web/app/components/base/form/form-scenarios/base/types.ts index 9cdb60ae14..15a76dc1c3 100644 --- a/web/app/components/base/form/form-scenarios/base/types.ts +++ b/web/app/components/base/form/form-scenarios/base/types.ts @@ -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 = { diff --git a/web/app/components/base/form/form-scenarios/base/utils.ts b/web/app/components/base/form/form-scenarios/base/utils.ts index a89c4fb2c7..97a10c316b 100644 --- a/web/app/components/base/form/form-scenarios/base/utils.ts +++ b/web/app/components/base/form/form-scenarios/base/utils.ts @@ -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 { diff --git a/web/app/components/base/form/form-scenarios/input-field/types.ts b/web/app/components/base/form/form-scenarios/input-field/types.ts index 5ffbacb721..9f9b8bd52d 100644 --- a/web/app/components/base/form/form-scenarios/input-field/types.ts +++ b/web/app/components/base/form/form-scenarios/input-field/types.ts @@ -35,5 +35,5 @@ export type InputFieldConfiguration = { tooltip?: string // Tooltip for this field listeners?: FieldListeners, DeepKeys>> // Listener for this field } & NumberConfiguration & Partial -& Partial -& Partial + & Partial + & Partial diff --git a/web/app/components/rag-pipeline/components/input-field/editor/form/hooks.ts b/web/app/components/rag-pipeline/components/input-field/editor/form/hooks.ts index 86e9265677..5ece09bb38 100644 --- a/web/app/components/rag-pipeline/components/input-field/editor/form/hooks.ts +++ b/web/app/components/rag-pipeline/components/input-field/editor/form/hooks.ts @@ -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, }, { diff --git a/web/app/components/rag-pipeline/components/input-field/editor/form/schema.ts b/web/app/components/rag-pipeline/components/input-field/editor/form/schema.ts index c816c007ed..9ac28a5f1e 100644 --- a/web/app/components/rag-pipeline/components/input-field/editor/form/schema.ts +++ b/web/app/components/rag-pipeline/components/input-field/editor/form/schema.ts @@ -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', diff --git a/web/app/components/rag-pipeline/components/panel/test-run/document-processing/hooks.ts b/web/app/components/rag-pipeline/components/panel/test-run/document-processing/hooks.ts index 2fcde8321c..fecb355e46 100644 --- a/web/app/components/rag-pipeline/components/panel/test-run/document-processing/hooks.ts +++ b/web/app/components/rag-pipeline/components/panel/test-run/document-processing/hooks.ts @@ -7,7 +7,7 @@ import { PipelineInputVarType } from '@/models/pipeline' const VAR_TYPE_MAP: Record = { [PipelineInputVarType.textInput]: BaseFieldType.textInput, - [PipelineInputVarType.paragraph]: BaseFieldType.textInput, + [PipelineInputVarType.paragraph]: BaseFieldType.paragraph, [PipelineInputVarType.select]: BaseFieldType.select, [PipelineInputVarType.singleFile]: BaseFieldType.file, [PipelineInputVarType.multiFiles]: BaseFieldType.fileList,