From 4705d07e11731c2e3882b8258348696018f544d7 Mon Sep 17 00:00:00 2001 From: Jimmy Ben Klieve Date: Tue, 30 Dec 2025 19:33:20 +0800 Subject: [PATCH] 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) --- web/src/interfaces/database/knowledge.ts | 2 +- .../components/chunk-card/index.tsx | 10 +++--- .../components/chunk-creating-modal/index.tsx | 34 +++++++++++-------- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/web/src/interfaces/database/knowledge.ts b/web/src/interfaces/database/knowledge.ts index 2dabbb931..5c460389a 100644 --- a/web/src/interfaces/database/knowledge.ts +++ b/web/src/interfaces/database/knowledge.ts @@ -116,7 +116,7 @@ export interface ITenantInfo { tts_id: string; } -export type ChunkDocType = 'image' | 'table'; +export type ChunkDocType = 'image' | 'table' | 'text'; export interface IChunk { available_int: number; // Whether to enable, 0: not enabled, 1: enabled diff --git a/web/src/pages/chunk/parsed-result/add-knowledge/components/knowledge-chunk/components/chunk-card/index.tsx b/web/src/pages/chunk/parsed-result/add-knowledge/components/knowledge-chunk/components/chunk-card/index.tsx index a2e9bac40..97a5af714 100644 --- a/web/src/pages/chunk/parsed-result/add-knowledge/components/knowledge-chunk/components/chunk-card/index.tsx +++ b/web/src/pages/chunk/parsed-result/add-knowledge/components/knowledge-chunk/components/chunk-card/index.tsx @@ -8,7 +8,7 @@ import { TooltipContent, TooltipTrigger, } from '@/components/ui/tooltip'; -import { IChunk } from '@/interfaces/database/knowledge'; +import type { ChunkDocType, IChunk } from '@/interfaces/database/knowledge'; import { cn } from '@/lib/utils'; import { CheckedState } from '@radix-ui/react-checkbox'; import classNames from 'classnames'; @@ -67,6 +67,10 @@ const ChunkCard = ({ setEnabled(available === 1); }, [available]); + const chunkType = + ((item.doc_type_kwd && + String(item.doc_type_kwd)?.toLowerCase()) as ChunkDocType) || 'text'; + return ( - {t( - `chunk.docType.${item.doc_type_kwd ? String(item.doc_type_kwd).toLowerCase() : 'text'}`, - )} + {t(`chunk.docType.${chunkType}`)}
diff --git a/web/src/pages/chunk/parsed-result/add-knowledge/components/knowledge-chunk/components/chunk-creating-modal/index.tsx b/web/src/pages/chunk/parsed-result/add-knowledge/components/knowledge-chunk/components/chunk-creating-modal/index.tsx index 87b9520a0..94e771ce2 100644 --- a/web/src/pages/chunk/parsed-result/add-knowledge/components/knowledge-chunk/components/chunk-creating-modal/index.tsx +++ b/web/src/pages/chunk/parsed-result/add-knowledge/components/knowledge-chunk/components/chunk-creating-modal/index.tsx @@ -22,6 +22,7 @@ import { Switch } from '@/components/ui/switch'; import { Textarea } from '@/components/ui/textarea'; import { useFetchChunk } from '@/hooks/use-chunk-request'; import { IModalProps } from '@/interfaces/common'; +import type { ChunkDocType } from '@/interfaces/database/knowledge'; import React, { useCallback, useEffect, useState } from 'react'; import { FieldValues, FormProvider, useForm } from 'react-hook-form'; import { useTranslation } from 'react-i18next'; @@ -151,20 +152,25 @@ const ChunkCreatingModal: React.FC & kFProps> = ({ ( - - {t(`chunk.type`)} - - - - - )} + render={({ field }) => { + const chunkType = + ((field.value && + String(field.value)?.toLowerCase()) as ChunkDocType) || + 'text'; + + return ( + + {t(`chunk.type`)} + + + + + ); + }} /> )}