From e6dc60be3278a598064a667369eb698d6c819eda Mon Sep 17 00:00:00 2001 From: linus-liu-web <395141741@qq.com> Date: Sat, 17 Oct 2026 22:37:58 +0800 Subject: [PATCH] =?UTF-8?q?fix(knowledge):=20=E6=96=87=E4=BB=B6=E5=A4=B9?= =?UTF-8?q?=E6=A0=91=E6=98=BE=E7=A4=BA=E9=80=92=E5=BD=92=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E6=95=B0=EF=BC=8C=E4=B8=8D=E5=86=8D=E6=8A=8A=E6=9C=89=E5=AD=90?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E7=9A=84=E6=96=87=E4=BB=B6=E5=A4=B9=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E6=88=90=200=20(#4428)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(knowledge): show recursive folder counts in the folder tree Connector-synced knowledge bases now come with multi-level folders, so a parent folder often holds no documents of its own while its subtree holds several. The folder tree, the breadcrumb and the empty state all read document_count (documents directly in the folder), so those parents rendered 0 and the document list stated "this folder has no documents yet" even though the documents were one level down. The API was already correct: total_count carries the recursive number. - KbFolderTree renders the row's totalCount; the existing tooltip still spells out the direct/recursive split. - KnowledgeBase reports the selected folder's recursive total in the breadcrumb. Filtering keeps the flat result count, and a tree that is missing or stale falls back to the loaded list total. - The empty state gains a third branch for folders whose documents all live in sub-folders, with a new emptyFolderWithSubfolders message in all six locales. - folderTree.ts exposes folderDocumentCounts() and shares the node lookup with childFolders(). Tests render the tree through Vite SSR (a 0/5 parent and the root row) and cover the breadcrumb/empty-state computed values plus the template wiring. * fix(knowledge): count sub-folders beside the breadcrumb document count The breadcrumb reported the selected folder's recursive document total while the document list only renders that folder's own documents. A folder holding 2 documents and 1 sub-folder therefore claimed "3 documents" next to a list of 2. Report the two numbers the page can actually account for, the way the DingTalk original does: "{documents} documents / {folders} folders". - The breadcrumb renders a new two-part folderContentsCount message in all six locales. Browsing counts the loaded list total (the documents on screen) and the folder's direct sub-folders; filtering keeps the flat result count and adds no folder number, since it searches documents rather than folders. - The sub-folder number is childFolders().length: the tree's top-level folders at the root, the selected node's children in a folder, and 0 when the tree is unavailable or the path is stale. - The recursive total stays where it is useful: the tree row (totalCount) and the empty state, whose folderSubfolderDocumentCount is a different quantity (documents below the folder) and is left untouched. * fix(knowledge): list sub-folders in the document views Render the current folder's direct sub-folders as rows in the list and as cards in the grid, ahead of the documents, so browsing matches a file manager and the DingTalk folder view. Folder entries are navigation only: they carry no batch checkbox and never enter document selection or sorting. Filtering still searches the subtree and shows documents only. When the folder tree is unavailable the views receive an empty list instead of crashing. Also hide the breadcrumb's folder segment when the folder has no sub-folders (falling back to the document-only message) and pluralize the folder count in English and Russian. * fix(knowledge): use t-icon sizes so the style guard stays at its baseline The folder row/card icons were sized with literal CSS font-size values, which the style guard counts against a fixed baseline. Use the t-icon size attribute instead, as the guard's own guidance asks. * fix(knowledge): preserve folder list icon size after style guard cleanup --------- Co-authored-by: linus-liu-web Co-authored-by: wizardchen --- frontend/src/i18n/index.ts | 2 + frontend/src/i18n/locales/en-US.ts | 6 +- frontend/src/i18n/locales/ja-JP.ts | 2 + frontend/src/i18n/locales/ko-KR.ts | 2 + frontend/src/i18n/locales/ru-RU.ts | 2 + frontend/src/i18n/locales/zh-CN.ts | 2 + frontend/src/i18n/locales/zh-TW.ts | 2 + frontend/src/i18n/pluralizationRules.ts | 18 ++ .../src/views/knowledge/KnowledgeBase.vue | 71 +++- .../KnowledgeBaseFolderCounts.test.ts | 306 ++++++++++++++++++ .../knowledge/components/DocumentCardView.vue | 54 ++++ .../components/DocumentFolderEntries.test.ts | 305 +++++++++++++++++ .../knowledge/components/DocumentListView.vue | 47 +++ .../knowledge/components/KbFolderTree.test.ts | 87 ++++- .../knowledge/components/KbFolderTree.vue | 2 +- .../src/views/knowledge/folderTree.test.ts | 41 +++ frontend/src/views/knowledge/folderTree.ts | 56 +++- 17 files changed, 983 insertions(+), 22 deletions(-) create mode 100644 frontend/src/i18n/pluralizationRules.ts create mode 100644 frontend/src/views/knowledge/KnowledgeBaseFolderCounts.test.ts create mode 100644 frontend/src/views/knowledge/components/DocumentFolderEntries.test.ts diff --git a/frontend/src/i18n/index.ts b/frontend/src/i18n/index.ts index 1bfbb866..1f3561c9 100755 --- a/frontend/src/i18n/index.ts +++ b/frontend/src/i18n/index.ts @@ -6,6 +6,7 @@ import koKR from './locales/ko-KR.ts' import jaJP from './locales/ja-JP.ts' import zhTW from './locales/zh-TW.ts' import { BUILT_IN_DEFAULT, resolveDefaultLocale } from './resolveDefaultLocale.ts' +import { pluralRules } from './pluralizationRules.ts' const messages = { 'zh-CN': zhCN, @@ -27,6 +28,7 @@ const i18n = createI18n({ locale: savedLocale, fallbackLocale: BUILT_IN_DEFAULT, globalInjection: true, + pluralRules, // Some translations intentionally embed `` markup (e.g. agent step summaries). // We render them via v-html with our own sanitization, so silence vue-i18n's HTML warning // to avoid flooding the console and slowing renders during history loads. diff --git a/frontend/src/i18n/locales/en-US.ts b/frontend/src/i18n/locales/en-US.ts index 32c483ec..5be33b96 100755 --- a/frontend/src/i18n/locales/en-US.ts +++ b/frontend/src/i18n/locales/en-US.ts @@ -654,7 +654,7 @@ export default { }, knowledgeBase: { tagAddAction: 'Add tags', - documentCount: '{count} documents', + documentCount: '{count} document | {count} documents', filters: 'Filters', clearFilters: 'Clear filters', @@ -720,9 +720,11 @@ export default { title: 'Folders', rootRow: 'Root', rootRowTip: 'Knowledge base root; documents not in a subfolder live here', - folderCardCount: '{count} documents', + folderCardCount: '{count} document | {count} documents', searchingSubtree: '(including sub-folders)', emptyFolder: 'This folder has no documents yet', + emptyFolderWithSubfolders: 'This folder has no documents of its own, but {count} in sub-folders', + folderContentsCount: '{documents} documents / {folders} folder | {documents} documents / {folders} folders', emptySearch: 'No matching documents', collapse: 'Collapse folders', expand: 'Expand folders', diff --git a/frontend/src/i18n/locales/ja-JP.ts b/frontend/src/i18n/locales/ja-JP.ts index 90b3c2d8..dcd179a3 100644 --- a/frontend/src/i18n/locales/ja-JP.ts +++ b/frontend/src/i18n/locales/ja-JP.ts @@ -723,6 +723,8 @@ export default { folderCardCount: '{count}件のドキュメント', searchingSubtree: '(サブフォルダを含む)', emptyFolder: 'このフォルダにはまだドキュメントがありません', + emptyFolderWithSubfolders: 'このフォルダに直接のドキュメントはありませんが、サブフォルダに {count} 件あります', + folderContentsCount: '{documents} 件のドキュメント / {folders} 個のフォルダ', emptySearch: '該当するドキュメントがありません', collapse: 'フォルダを折りたたむ', expand: 'フォルダを展開', diff --git a/frontend/src/i18n/locales/ko-KR.ts b/frontend/src/i18n/locales/ko-KR.ts index c54f1a91..69b77e18 100755 --- a/frontend/src/i18n/locales/ko-KR.ts +++ b/frontend/src/i18n/locales/ko-KR.ts @@ -7670,6 +7670,8 @@ export default { folderCardCount: '문서 {count}개', searchingSubtree: '(하위 폴더 포함)', emptyFolder: '이 폴더에는 아직 문서가 없습니다', + emptyFolderWithSubfolders: '이 폴더에는 직접 문서가 없지만 하위 폴더에 {count}개가 있습니다', + folderContentsCount: '문서 {documents}개 / 폴더 {folders}개', emptySearch: '일치하는 문서가 없습니다', collapse: '폴더 접기', expand: '폴더 펼치기', diff --git a/frontend/src/i18n/locales/ru-RU.ts b/frontend/src/i18n/locales/ru-RU.ts index 1fb85461..85ac97fe 100755 --- a/frontend/src/i18n/locales/ru-RU.ts +++ b/frontend/src/i18n/locales/ru-RU.ts @@ -7670,6 +7670,8 @@ export default { folderCardCount: 'Документов: {count}', searchingSubtree: '(с вложенными папками)', emptyFolder: 'В этой папке пока нет документов', + emptyFolderWithSubfolders: 'В этой папке нет собственных документов, но в подпапках есть {count}', + folderContentsCount: 'Документов: {documents} / {folders} папка | Документов: {documents} / {folders} папки | Документов: {documents} / {folders} папок', emptySearch: 'Подходящих документов нет', collapse: 'Свернуть папки', expand: 'Развернуть папки', diff --git a/frontend/src/i18n/locales/zh-CN.ts b/frontend/src/i18n/locales/zh-CN.ts index 05d3412d..610127ee 100755 --- a/frontend/src/i18n/locales/zh-CN.ts +++ b/frontend/src/i18n/locales/zh-CN.ts @@ -7671,6 +7671,8 @@ export default { folderCardCount: '{count} 个文档', searchingSubtree: '(含子目录)', emptyFolder: '这个文件夹里还没有文档', + emptyFolderWithSubfolders: '这个目录里没有直接文档,子目录里有 {count} 个', + folderContentsCount: '{documents} 个文档 / {folders} 个文件夹', emptySearch: '没有匹配的文档', collapse: '收起目录', expand: '展开目录', diff --git a/frontend/src/i18n/locales/zh-TW.ts b/frontend/src/i18n/locales/zh-TW.ts index 8b2184d2..5216d02c 100644 --- a/frontend/src/i18n/locales/zh-TW.ts +++ b/frontend/src/i18n/locales/zh-TW.ts @@ -7671,6 +7671,8 @@ export default { folderCardCount: '{count} 個文件', searchingSubtree: '(含子目錄)', emptyFolder: '這個資料夾裡還沒有文件', + emptyFolderWithSubfolders: '這個目錄裡沒有直接文件,子目錄裡有 {count} 個', + folderContentsCount: '{documents} 個文件 / {folders} 個資料夾', emptySearch: '沒有比對的文件', collapse: '收起目錄', expand: '展開目錄', diff --git a/frontend/src/i18n/pluralizationRules.ts b/frontend/src/i18n/pluralizationRules.ts new file mode 100644 index 00000000..b23e6f24 --- /dev/null +++ b/frontend/src/i18n/pluralizationRules.ts @@ -0,0 +1,18 @@ +/** + * vue-i18n's built-in plural rule only distinguishes "one" and "other". Russian + * has three forms (one / few / many), so messages written with three pipes need + * a selector that follows the CLDR rules. Only locales listed here are affected; + * everything else keeps the default rule. + */ +export const pluralRules: Record number> = { + ru: russianPluralRule, + 'ru-RU': russianPluralRule, +} + +function russianPluralRule(choice: number, choicesLength: number): number { + if (choicesLength < 3) return Math.abs(choice) === 1 ? 0 : 1 + const value = Math.abs(choice) + if (value % 10 === 1 && value % 100 !== 11) return 0 + if (value % 10 >= 2 && value % 10 <= 4 && (value % 100 < 10 || value % 100 >= 20)) return 1 + return 2 +} diff --git a/frontend/src/views/knowledge/KnowledgeBase.vue b/frontend/src/views/knowledge/KnowledgeBase.vue index 212902b7..50a6e5f6 100644 --- a/frontend/src/views/knowledge/KnowledgeBase.vue +++ b/frontend/src/views/knowledge/KnowledgeBase.vue @@ -68,7 +68,9 @@ import { resolveKnowledgeDownloadFileName } from './knowledgeDownloadFileName'; import { buildUploadFileName, canMoveFolderTo, + childFolders, folderBreadcrumbs as buildFolderBreadcrumbs, + folderDocumentCounts, folderPathExists as folderExistsInTree, isFilteringDocuments, ROOT_FOLDER_PATH, @@ -817,7 +819,50 @@ const isFiltering = computed(() => ); // A row's folder is worth showing only when the list can span folders. const showDocumentFolderPath = computed(() => hasFolders.value && isFiltering.value); +// Browsing a folder lists its direct sub-folders as entries, the way a file +// manager does. Filtering returns matching documents from the whole subtree, +// so folder entries would be noise there. +const visibleSubFolders = computed(() => + isFiltering.value ? [] : childFolders(folderTree.value, selectedFolderPath.value), +); const folderBreadcrumbs = computed(() => buildFolderBreadcrumbs(selectedFolderPath.value)); +// What the breadcrumb reports is the folder's own contents the way a file +// manager counts them: the documents this list can show plus its direct +// sub-folders, which the sidebar tree lists as rows. A recursive document total +// here would not match what the page shows, so that number stays on the tree row +// and in the empty state below. Filtering searches the subtree instead and +// reports only the flat result set, so it adds no folder number. +const folderContentsCount = computed<{ documents: number; folders: number }>(() => ({ + documents: total.value, + folders: isFiltering.value ? 0 : childFolders(folderTree.value, selectedFolderPath.value).length, +})); +// A folder with no sub-folders would otherwise end the breadcrumb with +// "/ 0 folders"; the document-only message is the whole truth there. +const showFolderContentsCount = computed( + () => !isFiltering.value && folderContentsCount.value.folders > 0, +); +const folderContentsMessage = computed(() => ({ + documents: folderContentsCount.value.documents, + folders: folderContentsCount.value.folders, + // vue-i18n selects the plural form from `count`; folders are the noun that + // changes with the number. + count: folderContentsCount.value.folders, +})); +// Documents below the selected folder rather than directly inside it; this is +// what tells "documents live in the sub-folders" apart from "nothing here yet". +const folderSubfolderDocumentCount = computed(() => { + const counts = folderDocumentCounts(folderTree.value, selectedFolderPath.value); + if (!counts) return 0; + return Math.max(0, counts.total - counts.direct); +}); +// Which empty state the document list needs: a search without matches, a folder +// whose documents are all below it, a plain empty folder, or the onboarding +// panel for a knowledge base that has no folders at all. +const folderEmptyState = computed<'search' | 'subfolders' | 'folder' | 'none'>(() => { + if (isFiltering.value) return 'search'; + if (folderSubfolderDocumentCount.value > 0) return 'subfolders'; + return hasFolders.value || selectedFolderPath.value ? 'folder' : 'none'; +}); const filterParams = computed(() => { const [start, end] = updatedTimeRange.value || []; @@ -2457,7 +2502,11 @@ const handleKBEditorSuccess = (kbIdValue: string) => { {{ crumb.name }} - {{ $t(isFiltering ? 'knowledgeBase.folderTree.filteredCount' : 'knowledgeBase.documentCount', { count: total }) }} + + + + + @@ -2590,7 +2639,7 @@ const handleKBEditorSuccess = (kbIdValue: string) => {
@@ -2618,10 +2667,11 @@ const handleKBEditorSuccess = (kbIdValue: string) => {
-