mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-01-03 19:15:30 +08:00
fix: malformed dynamic translation key chunk.docType.${chunkType} (#12329)
### What problem does this PR solve? Back-end may returns empty array on `"doc_type_kwd"` property which causes translation key malformed. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
@ -116,7 +116,7 @@ export interface ITenantInfo {
|
|||||||
tts_id: string;
|
tts_id: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ChunkDocType = 'image' | 'table';
|
export type ChunkDocType = 'image' | 'table' | 'text';
|
||||||
|
|
||||||
export interface IChunk {
|
export interface IChunk {
|
||||||
available_int: number; // Whether to enable, 0: not enabled, 1: enabled
|
available_int: number; // Whether to enable, 0: not enabled, 1: enabled
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import {
|
|||||||
TooltipContent,
|
TooltipContent,
|
||||||
TooltipTrigger,
|
TooltipTrigger,
|
||||||
} from '@/components/ui/tooltip';
|
} from '@/components/ui/tooltip';
|
||||||
import { IChunk } from '@/interfaces/database/knowledge';
|
import type { ChunkDocType, IChunk } from '@/interfaces/database/knowledge';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
import { CheckedState } from '@radix-ui/react-checkbox';
|
import { CheckedState } from '@radix-ui/react-checkbox';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
@ -67,6 +67,10 @@ const ChunkCard = ({
|
|||||||
setEnabled(available === 1);
|
setEnabled(available === 1);
|
||||||
}, [available]);
|
}, [available]);
|
||||||
|
|
||||||
|
const chunkType =
|
||||||
|
((item.doc_type_kwd &&
|
||||||
|
String(item.doc_type_kwd)?.toLowerCase()) as ChunkDocType) || 'text';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card
|
<Card
|
||||||
className={classNames('relative flex-none', styles.chunkCard, {
|
className={classNames('relative flex-none', styles.chunkCard, {
|
||||||
@ -81,9 +85,7 @@ const ChunkCard = ({
|
|||||||
bg-bg-card rounded-bl-2xl rounded-tr-lg
|
bg-bg-card rounded-bl-2xl rounded-tr-lg
|
||||||
border-l-0.5 border-b-0.5 border-border-button"
|
border-l-0.5 border-b-0.5 border-border-button"
|
||||||
>
|
>
|
||||||
{t(
|
{t(`chunk.docType.${chunkType}`)}
|
||||||
`chunk.docType.${item.doc_type_kwd ? String(item.doc_type_kwd).toLowerCase() : 'text'}`,
|
|
||||||
)}
|
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<div className="flex items-start justify-between gap-2">
|
<div className="flex items-start justify-between gap-2">
|
||||||
|
|||||||
@ -22,6 +22,7 @@ import { Switch } from '@/components/ui/switch';
|
|||||||
import { Textarea } from '@/components/ui/textarea';
|
import { Textarea } from '@/components/ui/textarea';
|
||||||
import { useFetchChunk } from '@/hooks/use-chunk-request';
|
import { useFetchChunk } from '@/hooks/use-chunk-request';
|
||||||
import { IModalProps } from '@/interfaces/common';
|
import { IModalProps } from '@/interfaces/common';
|
||||||
|
import type { ChunkDocType } from '@/interfaces/database/knowledge';
|
||||||
import React, { useCallback, useEffect, useState } from 'react';
|
import React, { useCallback, useEffect, useState } from 'react';
|
||||||
import { FieldValues, FormProvider, useForm } from 'react-hook-form';
|
import { FieldValues, FormProvider, useForm } from 'react-hook-form';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
@ -151,20 +152,25 @@ const ChunkCreatingModal: React.FC<IModalProps<any> & kFProps> = ({
|
|||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="doc_type_kwd"
|
name="doc_type_kwd"
|
||||||
render={({ field }) => (
|
render={({ field }) => {
|
||||||
|
const chunkType =
|
||||||
|
((field.value &&
|
||||||
|
String(field.value)?.toLowerCase()) as ChunkDocType) ||
|
||||||
|
'text';
|
||||||
|
|
||||||
|
return (
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>{t(`chunk.type`)}</FormLabel>
|
<FormLabel>{t(`chunk.type`)}</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Input
|
<Input
|
||||||
type="text"
|
type="text"
|
||||||
value={t(
|
value={t(`chunk.docType.${chunkType}`)}
|
||||||
`chunk.docType.${field.value ? String(field.value).toLowerCase() : 'text'}`,
|
|
||||||
)}
|
|
||||||
readOnly
|
readOnly
|
||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user