From 462be53b764c73be35c901104483e52b7e57bcbd Mon Sep 17 00:00:00 2001 From: balibabu Date: Fri, 10 Apr 2026 19:05:14 +0800 Subject: [PATCH] Fix: When creating a dataset, if no `chunk_method` is selected, there is no indication that this is a required field. (#14039) ### What problem does this PR solve? Fix: When creating a dataset, if no `chunk_method` is selected, there is no indication that this is a required field. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- .../components/chunk-method-dialog/index.tsx | 81 +++++------- .../components/data-pipeline-select/index.tsx | 1 + web/src/constants/knowledge.ts | 5 + web/src/hooks/use-knowledge-request.ts | 3 +- web/src/locales/en.ts | 1 + web/src/locales/zh.ts | 1 + .../configuration/common-item.tsx | 6 +- .../dataset/dataset-setting/form-schema.ts | 5 +- .../pages/dataset/dataset-setting/hooks.ts | 2 +- .../pages/dataset/dataset-setting/index.tsx | 26 ++-- .../dataset/dataset-setting/saving-button.tsx | 3 +- .../datasets/dataset-creating-dialog.tsx | 38 +++--- .../dataset-dataflow-creating-dialog.tsx | 123 ------------------ web/src/pages/datasets/hooks.ts | 3 +- 14 files changed, 93 insertions(+), 205 deletions(-) delete mode 100644 web/src/pages/datasets/dataset-dataflow-creating-dialog.tsx diff --git a/web/src/components/chunk-method-dialog/index.tsx b/web/src/components/chunk-method-dialog/index.tsx index c845fda35e..ddf39b637e 100644 --- a/web/src/components/chunk-method-dialog/index.tsx +++ b/web/src/components/chunk-method-dialog/index.tsx @@ -13,7 +13,7 @@ import { FormLabel, FormMessage, } from '@/components/ui/form'; -import { DocumentParserType } from '@/constants/knowledge'; +import { DocumentParserType, ParseType } from '@/constants/knowledge'; import { useFetchKnowledgeBaseConfiguration } from '@/hooks/use-knowledge-request'; import { IModalProps } from '@/interfaces/common'; import { IParserConfig } from '@/interfaces/database/document'; @@ -102,7 +102,7 @@ export function ChunkMethodDialog({ const FormSchema = z .object({ - parseType: z.number(), + parseType: z.nativeEnum(ParseType), parser_id: z .string() .min(1, { @@ -156,7 +156,7 @@ export function ChunkMethodDialog({ }), }) .superRefine((data, ctx) => { - if (data.parseType === 2 && !data.pipeline_id) { + if (data.parseType === ParseType.Pipeline && !data.pipeline_id) { ctx.addIssue({ path: ['pipeline_id'], message: t('common.pleaseSelect'), @@ -170,7 +170,7 @@ export function ChunkMethodDialog({ defaultValues: { parser_id: parserId || '', pipeline_id: pipelineId || '', - parseType: pipelineId ? 2 : 1, + parseType: pipelineId ? ParseType.Pipeline : ParseType.BuiltIn, parser_config: defaultParserValues, }, }); @@ -248,7 +248,7 @@ export function ChunkMethodDialog({ form.reset({ parser_id: parserId || '', pipeline_id: pipelineId || '', - parseType: pipelineId ? 2 : 1, + parseType: pipelineId ? ParseType.Pipeline : ParseType.BuiltIn, parser_config: fillDefaultParserValue({ pages: pages.length > 0 ? pages : [{ from: 1, to: 1024 }], ...omit(parserConfig, 'pages'), @@ -279,10 +279,10 @@ export function ChunkMethodDialog({ const parseType = useWatch({ control: form.control, name: 'parseType', - defaultValue: pipelineId ? 2 : 1, + defaultValue: pipelineId ? ParseType.Pipeline : ParseType.BuiltIn, }); useEffect(() => { - if (parseType === 1) { + if (parseType === ParseType.BuiltIn) { form.setValue('pipeline_id', ''); } }, [parseType, form]); @@ -301,49 +301,36 @@ export function ChunkMethodDialog({ >
- {parseType === 1 && } + {parseType === ParseType.BuiltIn && } - {/* ( - - {t('knowledgeDetails.chunkMethod')} - - - - - - )} - /> */} - - {showPages && parseType === 1 && } - - {showPages && parseType === 1 && layoutRecognize && ( - ( - - - {t('knowledgeDetails.taskPageSize')} - - - - - - - )} - /> + {showPages && parseType === ParseType.BuiltIn && ( + )} + + {showPages && + parseType === ParseType.BuiltIn && + layoutRecognize && ( + ( + + + {t('knowledgeDetails.taskPageSize')} + + + + + + + )} + /> + )}
- {parseType === 1 && ( + {parseType === ParseType.BuiltIn && ( <>
{showOne && ( @@ -411,7 +398,7 @@ export function ChunkMethodDialog({ )}
- {parseType === 2 && ( + {parseType === ParseType.Pipeline && ( {t('manualSetup')} diff --git a/web/src/constants/knowledge.ts b/web/src/constants/knowledge.ts index afd2e218bd..58f8ffac18 100644 --- a/web/src/constants/knowledge.ts +++ b/web/src/constants/knowledge.ts @@ -95,3 +95,8 @@ export enum DocumentParserType { } export const TagRenameId = 'tagRename'; + +export enum ParseType { + BuiltIn = 1, + Pipeline = 2, +} diff --git a/web/src/hooks/use-knowledge-request.ts b/web/src/hooks/use-knowledge-request.ts index f8390e4f83..2d4be01f12 100644 --- a/web/src/hooks/use-knowledge-request.ts +++ b/web/src/hooks/use-knowledge-request.ts @@ -1,5 +1,6 @@ import { useHandleFilterSubmit } from '@/components/list-filter-bar/use-handle-filter-submit'; import message from '@/components/ui/message'; +import { ParseType } from '@/constants/knowledge'; import { ResponsePostType } from '@/interfaces/database/base'; import { IKnowledge, @@ -208,7 +209,7 @@ export const useCreateKnowledge = () => { name: string; embedding_model?: string; chunk_method?: string; - parseType?: number; + parseType?: ParseType; pipeline_id?: string | null; ext?: { language?: string; diff --git a/web/src/locales/en.ts b/web/src/locales/en.ts index ef1f687f86..56b4121aef 100644 --- a/web/src/locales/en.ts +++ b/web/src/locales/en.ts @@ -211,6 +211,7 @@ Example: A 1 KB message with 1024-dim embedding uses ~9 KB. The 5 MB default lim searchKnowledgePlaceholder: 'Search', noMoreData: `That's all. Nothing more.`, parserRequired: 'Chunk method is required', + dataFlowRequired: 'Data flow is required', }, knowledgeDetails: { metadata: { diff --git a/web/src/locales/zh.ts b/web/src/locales/zh.ts index 5e749d80af..c297603296 100644 --- a/web/src/locales/zh.ts +++ b/web/src/locales/zh.ts @@ -180,6 +180,7 @@ export default { searchKnowledgePlaceholder: '搜索', noMoreData: '没有更多数据了', parserRequired: '分块方法必填', + dataFlowRequired: '数据流必填', }, knowledgeDetails: { metadata: { diff --git a/web/src/pages/dataset/dataset-setting/configuration/common-item.tsx b/web/src/pages/dataset/dataset-setting/configuration/common-item.tsx index c83766a8e4..1115a547db 100644 --- a/web/src/pages/dataset/dataset-setting/configuration/common-item.tsx +++ b/web/src/pages/dataset/dataset-setting/configuration/common-item.tsx @@ -19,7 +19,7 @@ import { import { Radio } from '@/components/ui/radio'; import { Spin } from '@/components/ui/spin'; import { Switch } from '@/components/ui/switch'; -import { LlmModelType } from '@/constants/knowledge'; +import { LlmModelType, ParseType } from '@/constants/knowledge'; import { useTranslate } from '@/hooks/common-hooks'; import { useComposeLlmOptionsByModelTypes } from '@/hooks/use-llm-request'; import { cn } from '@/lib/utils'; @@ -248,8 +248,8 @@ export function ParseTypeItem({ line === 1 ? 'w-1/2' : 'w-3/4', )} > - {t('builtIn')} - {t('manualSetup')} + {t('builtIn')} + {t('manualSetup')}
diff --git a/web/src/pages/dataset/dataset-setting/form-schema.ts b/web/src/pages/dataset/dataset-setting/form-schema.ts index a8a7dd69af..18801349da 100644 --- a/web/src/pages/dataset/dataset-setting/form-schema.ts +++ b/web/src/pages/dataset/dataset-setting/form-schema.ts @@ -1,9 +1,10 @@ +import { ParseType } from '@/constants/knowledge'; import { t } from 'i18next'; import { z } from 'zod'; export const formSchema = z .object({ - parse_type: z.number(), + parse_type: z.nativeEnum(ParseType), name: z.string().min(1, { message: 'Username must be at least 2 characters.', }), @@ -110,7 +111,7 @@ export const formSchema = z // icon: z.array(z.instanceof(File)), }) .superRefine((data, ctx) => { - if (data.parseType === 2 && !data.pipeline_id) { + if (data.parse_type === ParseType.Pipeline && !data.pipeline_id) { ctx.addIssue({ path: ['pipeline_id'], message: t('common.pleaseSelect'), diff --git a/web/src/pages/dataset/dataset-setting/hooks.ts b/web/src/pages/dataset/dataset-setting/hooks.ts index 6a21985204..536e356035 100644 --- a/web/src/pages/dataset/dataset-setting/hooks.ts +++ b/web/src/pages/dataset/dataset-setting/hooks.ts @@ -35,7 +35,7 @@ export function useHasParsedDocument(isEdit?: boolean) { } export const useFetchKnowledgeConfigurationOnMount = ( - form: UseFormReturn, any, undefined>, + form: UseFormReturn>, ) => { const { data: knowledgeDetails, loading } = useFetchKnowledgeBaseConfiguration(); diff --git a/web/src/pages/dataset/dataset-setting/index.tsx b/web/src/pages/dataset/dataset-setting/index.tsx index e24b0e5797..2060d0361d 100644 --- a/web/src/pages/dataset/dataset-setting/index.tsx +++ b/web/src/pages/dataset/dataset-setting/index.tsx @@ -12,7 +12,7 @@ import { import Divider from '@/components/ui/divider'; import { Form } from '@/components/ui/form'; import { FormLayout } from '@/constants/form'; -import { DocumentParserType } from '@/constants/knowledge'; +import { DocumentParserType, ParseType } from '@/constants/knowledge'; import { PermissionRole } from '@/constants/permission'; import { IConnector, IKnowledge } from '@/interfaces/database/knowledge'; import { useDataSourceInfo } from '@/pages/user-setting/data-source/constant'; @@ -111,7 +111,7 @@ export default function DatasetSettings() { llm_id: '', }, pipeline_id: '', - parse_type: 1, + parse_type: ParseType.BuiltIn, pagerank: 0, connectors: [], }, @@ -157,7 +157,10 @@ export default function DatasetSettings() { finish_at: knowledgeDetails.raptor_task_finish_at, task_id: knowledgeDetails.raptor_task_id, } as IGenerateLogButtonProps); - form.setValue('parse_type', knowledgeDetails.pipeline_id ? 2 : 1); + form.setValue( + 'parse_type', + knowledgeDetails.pipeline_id ? ParseType.Pipeline : ParseType.BuiltIn, + ); form.setValue('pipeline_id', knowledgeDetails.pipeline_id || ''); } }, [knowledgeDetails, form]); @@ -216,7 +219,9 @@ export default function DatasetSettings() { const parseType = useWatch({ control: form.control, name: 'parse_type', - defaultValue: knowledgeDetails.pipeline_id ? 2 : 1, + defaultValue: knowledgeDetails.pipeline_id + ? ParseType.Pipeline + : ParseType.BuiltIn, }); const selectedTag = useWatch({ name: 'chunk_method', @@ -224,7 +229,7 @@ export default function DatasetSettings() { }); useEffect(() => { - if (parseType === 1) { + if (parseType === ParseType.BuiltIn) { form.setValue('pipeline_id', ''); } else { form.setValue('chunk_method', DocumentParserType.Naive); @@ -236,7 +241,6 @@ export default function DatasetSettings() { const connectors = sourceData?.filter((connector) => { return connector.id !== data.id; }); - console.log('🚀 ~ DatasetSettings ~ connectors:', connectors); setSourceData(connectors as IDataSourceNodeProps[]); form.setValue('connectors', connectors || []); // form.setValue('pipeline_name', data.name || ''); @@ -304,13 +308,13 @@ export default function DatasetSettings() { {t('knowledgeConfiguration.dataPipeline')}
- {parseType === 1 && ( + {parseType === ParseType.BuiltIn && ( )} - {parseType === 2 && ( + {parseType === ParseType.Pipeline && ( */} - {parseType === 1 && } + {parseType === ParseType.BuiltIn && } {/*
- {parseType === 1 && } + {parseType === ParseType.BuiltIn && ( + + )}
diff --git a/web/src/pages/dataset/dataset-setting/saving-button.tsx b/web/src/pages/dataset/dataset-setting/saving-button.tsx index ef3f372827..37b0bd2350 100644 --- a/web/src/pages/dataset/dataset-setting/saving-button.tsx +++ b/web/src/pages/dataset/dataset-setting/saving-button.tsx @@ -1,4 +1,5 @@ import { ButtonLoading } from '@/components/ui/button'; +import { ParseType } from '@/constants/knowledge'; import { useUpdateKnowledge } from '@/hooks/use-knowledge-request'; import { useMemo } from 'react'; import { useFormContext } from 'react-hook-form'; @@ -68,7 +69,7 @@ export function SavingButton() { if (beValid) { form.handleSubmit(async (originalValues) => { const values = originalValues; - if (originalValues.parse_type === 1) { + if (originalValues.parse_type === ParseType.BuiltIn) { values.pipeline_id = null; } else { values.chunk_method = null; diff --git a/web/src/pages/datasets/dataset-creating-dialog.tsx b/web/src/pages/datasets/dataset-creating-dialog.tsx index a4de2b9636..315e823c50 100644 --- a/web/src/pages/datasets/dataset-creating-dialog.tsx +++ b/web/src/pages/datasets/dataset-creating-dialog.tsx @@ -18,6 +18,7 @@ import { } from '@/components/ui/form'; import { Input } from '@/components/ui/input'; import { FormLayout } from '@/constants/form'; +import { ParseType } from '@/constants/knowledge'; import { useFetchTenantInfo } from '@/hooks/use-user-setting-request'; import { IModalProps } from '@/interfaces/common'; import { zodResolver } from '@hookform/resolvers/zod'; @@ -34,6 +35,8 @@ import { const FormId = 'dataset-creating-form'; +const ChunkMethodName = 'chunk_method'; + export function InputForm({ onOk }: IModalProps) { const { t } = useTranslation(); const { data: tenantInfo } = useFetchTenantInfo(); @@ -46,30 +49,30 @@ export function InputForm({ onOk }: IModalProps) { message: t('knowledgeList.namePlaceholder'), }) .trim(), - parseType: z.number().optional(), + parseType: z.nativeEnum(ParseType).optional(), embedding_model: z .string() .min(1, { message: t('knowledgeConfiguration.embeddingModelPlaceholder'), }) .trim(), - chunk_method: z.string().optional(), + [ChunkMethodName]: z.string().optional(), pipeline_id: z.string().optional(), }) .superRefine((data, ctx) => { - // When parseType === 1, chunk_method is required + // When parseType === BuiltIn, chunk_method is required if ( - data.parseType === 1 && - (!data.chunk_method || data.chunk_method.trim() === '') + data.parseType === ParseType.BuiltIn && + (!data[ChunkMethodName] || data[ChunkMethodName].trim() === '') ) { ctx.addIssue({ code: z.ZodIssueCode.custom, message: t('knowledgeList.parserRequired'), - path: ['parser_id'], + path: [ChunkMethodName], }); } - // When parseType === 1, pipline_id required - if (data.parseType === 2 && !data.pipeline_id) { + // When parseType === Pipeline, pipeline_id required + if (data.parseType === ParseType.Pipeline && !data.pipeline_id) { ctx.addIssue({ code: z.ZodIssueCode.custom, message: t('knowledgeList.dataFlowRequired'), @@ -82,8 +85,8 @@ export function InputForm({ onOk }: IModalProps) { resolver: zodResolver(FormSchema), defaultValues: { name: '', - parseType: 1, - chunk_method: '', + parseType: ParseType.BuiltIn, + [ChunkMethodName]: '', embedding_model: tenantInfo?.embd_id, }, }); @@ -94,12 +97,13 @@ export function InputForm({ onOk }: IModalProps) { }); function onSubmit(data: z.infer) { - const nextData = parseType === 1 ? data : omit(data, 'chunk_method'); + const nextData = + parseType === ParseType.BuiltIn ? data : omit(data, ChunkMethodName); onOk?.(nextData); } useEffect(() => { - if (parseType === 1) { + if (parseType === ParseType.BuiltIn) { form.setValue('pipeline_id', ''); } }, [parseType, form]); @@ -107,7 +111,9 @@ export function InputForm({ onOk }: IModalProps) { return (
{ + console.warn(errors); + })} className="space-y-6" id={FormId} > @@ -133,10 +139,10 @@ export function InputForm({ onOk }: IModalProps) { - {parseType === 1 && ( - + {parseType === ParseType.BuiltIn && ( + )} - {parseType === 2 && ( + {parseType === ParseType.Pipeline && ( ) { - const { t } = useTranslation(); - - const FormSchema = z.object({ - name: z - .string() - .min(1, { - message: t('knowledgeList.namePlaceholder'), - }) - .trim(), - parseType: z.number().optional(), - }); - - const form = useForm>({ - resolver: zodResolver(FormSchema), - defaultValues: { - name: '', - parseType: 1, - }, - }); - - function onSubmit(data: z.infer) { - onOk?.(data.name); - } - const parseType = useWatch({ - control: form.control, - name: 'parseType', - }); - return ( - - - ( - - - * - {t('knowledgeList.name')} - - - - - - - )} - /> - - - {parseType === 2 && ( - <> - - - - - )} - - - ); -} - -export function DatasetCreatingDialog({ - hideModal, - onOk, - loading, -}: IModalProps) { - const { t } = useTranslation(); - - return ( - - - - {t('knowledgeList.createKnowledgeBase')} - - - - - {t('common.save')} - - - - - ); -} diff --git a/web/src/pages/datasets/hooks.ts b/web/src/pages/datasets/hooks.ts index 140976ee77..08ccba15cc 100644 --- a/web/src/pages/datasets/hooks.ts +++ b/web/src/pages/datasets/hooks.ts @@ -1,3 +1,4 @@ +import { ParseType } from '@/constants/knowledge'; import { useSetModalState } from '@/hooks/common-hooks'; import { useNavigatePage } from '@/hooks/logic-hooks/navigate-hooks'; import { useCreateKnowledge } from '@/hooks/use-knowledge-request'; @@ -18,7 +19,7 @@ export interface Iknowledge { name: string; embedding_model?: string; chunk_method?: string; - parseType?: number; + parseType?: ParseType; pipeline_id?: string | null; ext?: { language?: string;