mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-05-05 01:37:46 +08:00
Fix: The chunk method of the knowledge base cannot be saved. (#13813)
### What problem does this PR solve? Fix: The chunk method of the knowledge base cannot be saved. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
@ -1,75 +0,0 @@
|
||||
// https://github.com/hsuanyi-chou/shadcn-ui-expansions/blob/main/components/ui/loading-button.tsx
|
||||
|
||||
import { cn } from '@/lib/utils';
|
||||
import { Slot, Slottable } from '@radix-ui/react-slot';
|
||||
import { cva, type VariantProps } from 'class-variance-authority';
|
||||
import { Loader2 } from 'lucide-react';
|
||||
import * as React from 'react';
|
||||
|
||||
const buttonVariants = cva(
|
||||
'inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50',
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: 'bg-primary text-primary-foreground hover:bg-primary/90',
|
||||
destructive:
|
||||
'bg-destructive text-destructive-foreground hover:bg-destructive/90',
|
||||
outline:
|
||||
'border border-input bg-background hover:bg-accent hover:text-accent-foreground',
|
||||
secondary:
|
||||
'bg-secondary text-secondary-foreground hover:bg-secondary/80',
|
||||
ghost: 'hover:bg-accent hover:text-accent-foreground',
|
||||
link: 'text-primary underline-offset-4 hover:underline',
|
||||
},
|
||||
size: {
|
||||
default: 'h-10 px-4 py-2',
|
||||
sm: 'h-9 rounded-md px-3',
|
||||
lg: 'h-11 rounded-md px-8',
|
||||
icon: 'h-10 w-10',
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: 'default',
|
||||
size: 'default',
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
export interface ButtonProps
|
||||
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
||||
VariantProps<typeof buttonVariants> {
|
||||
asChild?: boolean;
|
||||
loading?: boolean;
|
||||
}
|
||||
|
||||
const LoadingButton = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
||||
(
|
||||
{
|
||||
className,
|
||||
loading = false,
|
||||
children,
|
||||
disabled,
|
||||
variant,
|
||||
size,
|
||||
asChild = false,
|
||||
...props
|
||||
},
|
||||
ref,
|
||||
) => {
|
||||
const Comp = asChild ? Slot : 'button';
|
||||
return (
|
||||
<Comp
|
||||
className={cn(buttonVariants({ variant, size, className }))}
|
||||
ref={ref}
|
||||
disabled={loading || disabled}
|
||||
{...props}
|
||||
>
|
||||
{loading && <Loader2 className="mr-2 h-5 w-5 animate-spin" />}
|
||||
<Slottable>{children}</Slottable>
|
||||
</Comp>
|
||||
);
|
||||
},
|
||||
);
|
||||
LoadingButton.displayName = 'LoadingButton';
|
||||
|
||||
export { LoadingButton, buttonVariants };
|
||||
@ -19,7 +19,6 @@ import { Input, NumberInput } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import { Switch } from '@/components/ui/switch';
|
||||
import { LlmModelType } from '@/constants/knowledge';
|
||||
import { useFindLlmByUuid } from '@/hooks/use-llm-request';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { get } from 'lodash';
|
||||
@ -218,7 +217,7 @@ function AgentForm({ node }: INextOperatorForm) {
|
||||
name={`cite`}
|
||||
render={({ field }) => (
|
||||
<FormItem className="flex-1">
|
||||
<FormLabel tooltip={t('flow.citeTip')}>
|
||||
<FormLabel tooltip={t('chat.quoteTip')}>
|
||||
{t('flow.cite')}
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
|
||||
@ -207,14 +207,20 @@ export function EmbeddingModelItem({ line = 1, isEdit }: IProps) {
|
||||
);
|
||||
}
|
||||
|
||||
export function ParseTypeItem({ line = 2 }: { line?: number }) {
|
||||
export function ParseTypeItem({
|
||||
line = 2,
|
||||
name = 'parseType',
|
||||
}: {
|
||||
line?: number;
|
||||
name?: string;
|
||||
}) {
|
||||
const { t } = useTranslate('knowledgeConfiguration');
|
||||
const form = useFormContext();
|
||||
|
||||
return (
|
||||
<FormField
|
||||
control={form.control}
|
||||
name={'parseType'}
|
||||
name={name}
|
||||
render={({ field }) => (
|
||||
<FormItem className=" items-center space-y-0 ">
|
||||
<div
|
||||
|
||||
@ -3,7 +3,7 @@ import { z } from 'zod';
|
||||
|
||||
export const formSchema = z
|
||||
.object({
|
||||
parseType: z.number(),
|
||||
parse_type: z.number(),
|
||||
name: z.string().min(1, {
|
||||
message: 'Username must be at least 2 characters.',
|
||||
}),
|
||||
|
||||
@ -66,7 +66,7 @@ export default function DatasetSettings() {
|
||||
resolver: zodResolver(formSchema),
|
||||
defaultValues: {
|
||||
name: '',
|
||||
parser_id: DocumentParserType.Naive,
|
||||
chunk_method: DocumentParserType.Naive,
|
||||
permission: PermissionRole.Me,
|
||||
language: 'English',
|
||||
parser_config: {
|
||||
@ -111,7 +111,7 @@ export default function DatasetSettings() {
|
||||
llm_id: '',
|
||||
},
|
||||
pipeline_id: '',
|
||||
parseType: 1,
|
||||
parse_type: 1,
|
||||
pagerank: 0,
|
||||
connectors: [],
|
||||
},
|
||||
@ -157,7 +157,7 @@ export default function DatasetSettings() {
|
||||
finish_at: knowledgeDetails.raptor_task_finish_at,
|
||||
task_id: knowledgeDetails.raptor_task_id,
|
||||
} as IGenerateLogButtonProps);
|
||||
form.setValue('parseType', knowledgeDetails.pipeline_id ? 2 : 1);
|
||||
form.setValue('parse_type', knowledgeDetails.pipeline_id ? 2 : 1);
|
||||
form.setValue('pipeline_id', knowledgeDetails.pipeline_id || '');
|
||||
}
|
||||
}, [knowledgeDetails, form]);
|
||||
@ -215,18 +215,20 @@ export default function DatasetSettings() {
|
||||
|
||||
const parseType = useWatch({
|
||||
control: form.control,
|
||||
name: 'parseType',
|
||||
name: 'parse_type',
|
||||
defaultValue: knowledgeDetails.pipeline_id ? 2 : 1,
|
||||
});
|
||||
const selectedTag = useWatch({
|
||||
name: 'chunk_method',
|
||||
control: form.control,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (parseType === 1) {
|
||||
form.setValue('pipeline_id', '');
|
||||
} else {
|
||||
form.setValue('chunk_method', DocumentParserType.Naive);
|
||||
}
|
||||
console.log('parseType', parseType);
|
||||
}, [parseType, form]);
|
||||
|
||||
const unbindFunc = (data: IDataSourceBase) => {
|
||||
@ -301,9 +303,12 @@ export default function DatasetSettings() {
|
||||
<div className="text-base font-medium text-text-primary">
|
||||
{t('knowledgeConfiguration.dataPipeline')}
|
||||
</div>
|
||||
<ParseTypeItem line={1} />
|
||||
<ParseTypeItem line={1} name="parse_type" />
|
||||
{parseType === 1 && (
|
||||
<ChunkMethodItem line={1}></ChunkMethodItem>
|
||||
<ChunkMethodItem
|
||||
line={1}
|
||||
name="chunk_method"
|
||||
></ChunkMethodItem>
|
||||
)}
|
||||
{parseType === 2 && (
|
||||
<DataFlowSelect
|
||||
|
||||
@ -25,7 +25,7 @@ export function GeneralSavingButton() {
|
||||
data-testid="ds-settings-basic-save-btn"
|
||||
onClick={() => {
|
||||
(async () => {
|
||||
let isValidate = await form.trigger('name');
|
||||
const isValidate = await form.trigger('name');
|
||||
const { name, description, permission, avatar } = form.getValues();
|
||||
|
||||
if (isValidate) {
|
||||
@ -60,16 +60,20 @@ export function SavingButton() {
|
||||
onClick={() => {
|
||||
(async () => {
|
||||
try {
|
||||
let beValid = await form.trigger();
|
||||
const beValid = await form.trigger();
|
||||
if (!beValid) {
|
||||
const errors = form.formState.errors;
|
||||
console.error('Validation errors:', errors);
|
||||
}
|
||||
if (beValid) {
|
||||
form.handleSubmit(async (values) => {
|
||||
console.log('saveKnowledgeConfiguration: ', values);
|
||||
delete values['parseType'];
|
||||
// delete values['avatar'];
|
||||
form.handleSubmit(async (originalValues) => {
|
||||
const values = originalValues;
|
||||
if (originalValues.parse_type === 1) {
|
||||
values.pipeline_id = null;
|
||||
} else {
|
||||
values.chunk_method = null;
|
||||
}
|
||||
|
||||
await saveKnowledgeConfiguration({
|
||||
kb_id,
|
||||
...values,
|
||||
@ -91,7 +95,6 @@ export function SavingButton() {
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
} finally {
|
||||
}
|
||||
})();
|
||||
}}
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { ButtonLoading } from '@/components/ui/button';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
@ -5,7 +6,6 @@ import {
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
import { LoadingButton } from '@/components/ui/loading-button';
|
||||
import { TagRenameId } from '@/constants/knowledge';
|
||||
import { useTagIsRenaming } from '@/hooks/use-knowledge-request';
|
||||
import { IModalProps } from '@/interfaces/common';
|
||||
@ -30,9 +30,9 @@ export function RenameDialog({
|
||||
hideModal={hideModal}
|
||||
></RenameForm>
|
||||
<DialogFooter>
|
||||
<LoadingButton type="submit" form={TagRenameId} loading={loading}>
|
||||
<ButtonLoading type="submit" form={TagRenameId} loading={loading}>
|
||||
{t('common.save')}
|
||||
</LoadingButton>
|
||||
</ButtonLoading>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { ButtonLoading } from '@/components/ui/button';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
@ -5,7 +6,6 @@ import {
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
import { LoadingButton } from '@/components/ui/loading-button';
|
||||
import { TagRenameId } from '@/constants/knowledge';
|
||||
import { IModalProps } from '@/interfaces/common';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
@ -26,9 +26,9 @@ export function CreateFolderDialog({
|
||||
</DialogHeader>
|
||||
<CreateFolderForm hideModal={hideModal} onOk={onOk}></CreateFolderForm>
|
||||
<DialogFooter>
|
||||
<LoadingButton type="submit" form={TagRenameId} loading={loading}>
|
||||
<ButtonLoading type="submit" form={TagRenameId} loading={loading}>
|
||||
{t('common.save')}
|
||||
</LoadingButton>
|
||||
</ButtonLoading>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { ButtonLoading } from '@/components/ui/button';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
@ -5,7 +6,6 @@ import {
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
import { LoadingButton } from '@/components/ui/loading-button';
|
||||
import { TagRenameId } from '@/constants/knowledge';
|
||||
import { IModalProps } from '@/interfaces/common';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
@ -26,9 +26,9 @@ export function ImportMcpDialog({
|
||||
</DialogHeader>
|
||||
<ImportMcpForm hideModal={hideModal} onOk={onOk}></ImportMcpForm>
|
||||
<DialogFooter>
|
||||
<LoadingButton type="submit" form={TagRenameId} loading={loading}>
|
||||
<ButtonLoading type="submit" form={TagRenameId} loading={loading}>
|
||||
{t('common.save')}
|
||||
</LoadingButton>
|
||||
</ButtonLoading>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { ConfirmDeleteDialog } from '@/components/confirm-delete-dialog';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Button, ButtonLoading } from '@/components/ui/button';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
@ -8,7 +8,6 @@ import {
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from '@/components/ui/dialog';
|
||||
import { LoadingButton } from '@/components/ui/loading-button';
|
||||
import { useDeleteLangfuseConfig } from '@/hooks/use-user-setting-request';
|
||||
import { IModalProps } from '@/interfaces/common';
|
||||
import { ExternalLink, Trash2 } from 'lucide-react';
|
||||
@ -61,9 +60,9 @@ export function LangfuseConfigurationDialog({
|
||||
</Button>
|
||||
</ConfirmDeleteDialog>
|
||||
|
||||
<LoadingButton type="submit" form={FormId} loading={loading}>
|
||||
<ButtonLoading type="submit" form={FormId} loading={loading}>
|
||||
{t('common.save')}
|
||||
</LoadingButton>
|
||||
</ButtonLoading>
|
||||
</div>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
|
||||
Reference in New Issue
Block a user