mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
### What problem does this PR solve? Fix: Added table of contents extraction functionality and optimized form item layout #9869 - Added `EnableTocToggle` component to toggle table of contents extraction on and off - Added multiple parser configuration components (such as naive, book, laws, etc.), displaying different parser components based on built-in slicing methods ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
174 lines
4.5 KiB
TypeScript
174 lines
4.5 KiB
TypeScript
import { DataFlowSelect } from '@/components/data-pipeline-select';
|
|
import { ButtonLoading } from '@/components/ui/button';
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogFooter,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
} from '@/components/ui/dialog';
|
|
import {
|
|
Form,
|
|
FormControl,
|
|
FormField,
|
|
FormItem,
|
|
FormLabel,
|
|
FormMessage,
|
|
} from '@/components/ui/form';
|
|
import { Input } from '@/components/ui/input';
|
|
import { FormLayout } from '@/constants/form';
|
|
import { useNavigatePage } from '@/hooks/logic-hooks/navigate-hooks';
|
|
import { IModalProps } from '@/interfaces/common';
|
|
import { zodResolver } from '@hookform/resolvers/zod';
|
|
import { useEffect } from 'react';
|
|
import { useForm, useWatch } from 'react-hook-form';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { z } from 'zod';
|
|
import {
|
|
ChunkMethodItem,
|
|
EmbeddingModelItem,
|
|
ParseTypeItem,
|
|
} from '../dataset/dataset-setting/configuration/common-item';
|
|
|
|
const FormId = 'dataset-creating-form';
|
|
|
|
export function InputForm({ onOk }: IModalProps<any>) {
|
|
const { t } = useTranslation();
|
|
|
|
const FormSchema = z
|
|
.object({
|
|
name: z
|
|
.string()
|
|
.min(1, {
|
|
message: t('knowledgeList.namePlaceholder'),
|
|
})
|
|
.trim(),
|
|
parseType: z.number().optional(),
|
|
embd_id: z
|
|
.string()
|
|
.min(1, {
|
|
message: t('knowledgeConfiguration.embeddingModelPlaceholder'),
|
|
})
|
|
.trim(),
|
|
parser_id: z.string().optional(),
|
|
pipeline_id: z.string().optional(),
|
|
})
|
|
.superRefine((data, ctx) => {
|
|
// When parseType === 1, parser_id is required
|
|
if (
|
|
data.parseType === 1 &&
|
|
(!data.parser_id || data.parser_id.trim() === '')
|
|
) {
|
|
ctx.addIssue({
|
|
code: z.ZodIssueCode.custom,
|
|
message: t('knowledgeList.parserRequired'),
|
|
path: ['parser_id'],
|
|
});
|
|
}
|
|
|
|
console.log('form-data', data);
|
|
// When parseType === 1, pipline_id required
|
|
if (data.parseType === 2 && !data.pipeline_id) {
|
|
ctx.addIssue({
|
|
code: z.ZodIssueCode.custom,
|
|
message: t('knowledgeList.dataFlowRequired'),
|
|
path: ['pipeline_id'],
|
|
});
|
|
}
|
|
});
|
|
|
|
const form = useForm<z.infer<typeof FormSchema>>({
|
|
resolver: zodResolver(FormSchema),
|
|
defaultValues: {
|
|
name: '',
|
|
parseType: 1,
|
|
parser_id: '',
|
|
embd_id: '',
|
|
},
|
|
});
|
|
|
|
function onSubmit(data: z.infer<typeof FormSchema>) {
|
|
console.log('submit', data);
|
|
onOk?.(data);
|
|
}
|
|
|
|
const parseType = useWatch({
|
|
control: form.control,
|
|
name: 'parseType',
|
|
});
|
|
|
|
useEffect(() => {
|
|
console.log('parseType', parseType);
|
|
if (parseType === 1) {
|
|
form.setValue('pipeline_id', '');
|
|
}
|
|
}, [parseType, form]);
|
|
const { navigateToAgents } = useNavigatePage();
|
|
|
|
return (
|
|
<Form {...form}>
|
|
<form
|
|
onSubmit={form.handleSubmit(onSubmit)}
|
|
className="space-y-6"
|
|
id={FormId}
|
|
>
|
|
<FormField
|
|
control={form.control}
|
|
name="name"
|
|
render={({ field }) => (
|
|
<FormItem>
|
|
<FormLabel>
|
|
<span className="text-destructive mr-1"> *</span>
|
|
{t('knowledgeList.name')}
|
|
</FormLabel>
|
|
<FormControl>
|
|
<Input
|
|
placeholder={t('knowledgeList.namePlaceholder')}
|
|
{...field}
|
|
/>
|
|
</FormControl>
|
|
<FormMessage />
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
|
|
<EmbeddingModelItem line={2} isEdit={false} />
|
|
<ParseTypeItem />
|
|
{parseType === 1 && <ChunkMethodItem></ChunkMethodItem>}
|
|
{parseType === 2 && (
|
|
<DataFlowSelect
|
|
isMult={false}
|
|
showToDataPipeline={true}
|
|
formFieldName="pipeline_id"
|
|
layout={FormLayout.Vertical}
|
|
/>
|
|
)}
|
|
</form>
|
|
</Form>
|
|
);
|
|
}
|
|
|
|
export function DatasetCreatingDialog({
|
|
hideModal,
|
|
onOk,
|
|
loading,
|
|
}: IModalProps<any>) {
|
|
const { t } = useTranslation();
|
|
|
|
return (
|
|
<Dialog open onOpenChange={hideModal}>
|
|
<DialogContent className="sm:max-w-[425px] focus-visible:!outline-none">
|
|
<DialogHeader>
|
|
<DialogTitle>{t('knowledgeList.createKnowledgeBase')}</DialogTitle>
|
|
</DialogHeader>
|
|
<InputForm onOk={onOk}></InputForm>
|
|
<DialogFooter>
|
|
<ButtonLoading type="submit" form={FormId} loading={loading}>
|
|
{t('common.save')}
|
|
</ButtonLoading>
|
|
</DialogFooter>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
}
|