From 7316d95f56b296a19a793be7fdfad5444baafd86 Mon Sep 17 00:00:00 2001 From: wizardchen Date: Tue, 4 Aug 2026 20:19:57 +0800 Subject: [PATCH] feat(knowledge): enhance folder management and upload confirmation dialog - Added folder options to the upload confirmation dialog, allowing users to select from existing folders as upload destinations. - Updated folder tree UI to improve folder browsing experience, displaying sub-folders and documents more intuitively. - Enhanced folder picker functionality to support creating new sub-folders directly from the picker. - Improved localization for folder-related strings across multiple languages. - Refactored related components and tests to accommodate new features and ensure proper functionality. This commit streamlines the user experience for managing folders and uploading documents, making it easier to navigate and organize content. --- frontend/src/components/UploadConfirmHost.vue | 1 + frontend/src/i18n/locales/en-US.ts | 16 +- frontend/src/i18n/locales/ko-KR.ts | 14 +- frontend/src/i18n/locales/ru-RU.ts | 16 +- frontend/src/i18n/locales/zh-CN.ts | 16 +- frontend/src/stores/uploadConfirm.ts | 5 + .../src/views/knowledge/KnowledgeBase.vue | 62 +++- .../knowledge/components/DocumentCardView.vue | 138 ++++---- .../knowledge/components/DocumentListView.vue | 45 +-- .../knowledge/components/FolderPickerMenu.vue | 312 +++++++++++++----- .../knowledge/components/KbFolderTree.test.ts | 14 + .../knowledge/components/KbFolderTree.vue | 118 +++++-- .../components/UploadConfirmDialog.test.ts | 26 +- .../components/UploadConfirmDialog.vue | 205 +++++++++--- .../src/views/knowledge/folderTree.test.ts | 18 + frontend/src/views/knowledge/folderTree.ts | 28 ++ 16 files changed, 756 insertions(+), 278 deletions(-) diff --git a/frontend/src/components/UploadConfirmHost.vue b/frontend/src/components/UploadConfirmHost.vue index b7aa343f..63814f2d 100644 --- a/frontend/src/components/UploadConfirmHost.vue +++ b/frontend/src/components/UploadConfirmHost.vue @@ -26,6 +26,7 @@ const handleCancel = () => { :accept-file-types="uploadConfirmStore.acceptFileTypes" :supported-file-types="uploadConfirmStore.supportedFileTypes" :target-folder="uploadConfirmStore.targetFolder" + :folder-options="uploadConfirmStore.folderOptions" @confirm="handleConfirm" @cancel="handleCancel" /> diff --git a/frontend/src/i18n/locales/en-US.ts b/frontend/src/i18n/locales/en-US.ts index 80879bef..087407c8 100755 --- a/frontend/src/i18n/locales/en-US.ts +++ b/frontend/src/i18n/locales/en-US.ts @@ -371,8 +371,8 @@ export default { tagEditNoSelected: 'None selected', folderTree: { title: 'Folders', - rootRow: 'All documents', - rootRowTip: 'The top level of the knowledge base; every folder sits below it', + rootRow: 'Root', + rootRowTip: 'Knowledge base root; documents not in a subfolder live here', folderCardCount: '{count} documents', searchingSubtree: '(including sub-folders)', emptyFolder: 'This folder has no documents yet', @@ -391,7 +391,12 @@ export default { action: 'Move to folder', newFolder: 'New sub-folder', newFolderPlaceholder: 'New folder name', + newFolderCreate: 'Create', + newFolderAddRoot: 'New sub-folder under root', + newFolderAddUnder: 'New sub-folder under “{folder}”', newFolderHint: 'Press Enter to create and move', + newFolderHintRoot: 'Will be created under root', + newFolderHintUnder: 'Will be created under “{folder}”', success: 'Moved {count} documents', failed: 'Could not move the documents', }, @@ -683,8 +688,11 @@ export default { description: 'Useful for web-print, scanned, or image-heavy PDFs. Every page will be rendered as an image and processed via OCR/VLM. May increase processing time and model costs.' }, continueAdd: 'Add more', - destinationLabel: 'Upload to', - destinationToRoot: 'Use top level', + destinationLabel: 'Upload location', + destinationChange: 'Change upload location', + destinationToRoot: 'Use root', + folderUploadTitle: 'Folder “{name}”', + folderUploadHint: '{count} files; the local folder structure will be kept', filesAdded: 'Added {count} file(s)', filesAllDuplicate: 'Selected files are already in the list', titleManual: 'Confirm online publish', diff --git a/frontend/src/i18n/locales/ko-KR.ts b/frontend/src/i18n/locales/ko-KR.ts index ffae1adf..73344617 100755 --- a/frontend/src/i18n/locales/ko-KR.ts +++ b/frontend/src/i18n/locales/ko-KR.ts @@ -5098,7 +5098,10 @@ export default { asrModelSelectRequired: '음성 인식이 활성화되었습니다. ASR 모델을 선택하세요', continueAdd: '계속 추가', destinationLabel: '업로드 위치', - destinationToRoot: '최상위로 변경', + destinationChange: '업로드 위치 변경', + destinationToRoot: '루트로 변경', + folderUploadTitle: '폴더 「{name}」', + folderUploadHint: '파일 {count}개, 로컬 폴더 구조를 유지합니다', filesAdded: '{count}개 파일이 추가되었습니다', filesAllDuplicate: '선택한 파일이 이미 목록에 있습니다', titleManual: '온라인 편집 게시 확인', @@ -5127,8 +5130,8 @@ export default { tagEditNoSelected: '선택 없음', folderTree: { title: '폴더', - rootRow: '전체 문서', - rootRowTip: '지식 베이스의 최상위이며 모든 폴더가 그 아래에 있습니다', + rootRow: '루트', + rootRowTip: '지식 베이스 루트 디렉터리, 하위 폴더에 없는 문서가 여기에 있습니다', folderCardCount: '문서 {count}개', searchingSubtree: '(하위 폴더 포함)', emptyFolder: '이 폴더에는 아직 문서가 없습니다', @@ -5148,6 +5151,11 @@ export default { newFolder: '새 하위 폴더', newFolderPlaceholder: '새 폴더 이름', newFolderHint: 'Enter로 만들고 이동', + newFolderCreate: '생성', + newFolderAddRoot: '루트 아래에 하위 디렉터리 만들기', + newFolderAddUnder: '「{folder}」 아래에 하위 디렉터리 만들기', + newFolderHintRoot: '루트 아래에 생성됩니다', + newFolderHintUnder: '「{folder}」 아래에 생성됩니다', success: '문서 {count}개를 이동했습니다', failed: '문서를 이동할 수 없습니다', }, diff --git a/frontend/src/i18n/locales/ru-RU.ts b/frontend/src/i18n/locales/ru-RU.ts index ceb6ac02..94d4a740 100755 --- a/frontend/src/i18n/locales/ru-RU.ts +++ b/frontend/src/i18n/locales/ru-RU.ts @@ -5097,8 +5097,11 @@ export default { vlmModelSelectRequired: 'Мультимодальность включена. Выберите модель VLM.', asrModelSelectRequired: 'Распознавание речи включено. Выберите модель ASR.', continueAdd: 'Добавить ещё', - destinationLabel: 'Загрузить в', - destinationToRoot: 'На верхний уровень', + destinationLabel: 'Куда загрузить', + destinationChange: 'Изменить папку загрузки', + destinationToRoot: 'В корень', + folderUploadTitle: 'Папка «{name}»', + folderUploadHint: '{count} файлов; структура локальной папки сохранится', filesAdded: 'Добавлено файлов: {count}', filesAllDuplicate: 'Выбранные файлы уже в списке', titleManual: 'Подтверждение публикации', @@ -5127,8 +5130,8 @@ export default { tagEditNoSelected: 'Ничего не выбрано', folderTree: { title: 'Папки', - rootRow: 'Все документы', - rootRowTip: 'Верхний уровень базы знаний — все папки находятся внутри него', + rootRow: 'Корень', + rootRowTip: 'Корневая папка базы знаний; документы без подпапки находятся здесь', folderCardCount: 'Документов: {count}', searchingSubtree: '(с вложенными папками)', emptyFolder: 'В этой папке пока нет документов', @@ -5148,6 +5151,11 @@ export default { newFolder: 'Новая вложенная папка', newFolderPlaceholder: 'Название новой папки', newFolderHint: 'Enter — создать и переместить', + newFolderCreate: 'Создать', + newFolderAddRoot: 'Создать подкаталог в корне', + newFolderAddUnder: 'Создать подкаталог в «{folder}»', + newFolderHintRoot: 'Будет создана в корне', + newFolderHintUnder: 'Будет создана внутри «{folder}»', success: 'Перемещено документов: {count}', failed: 'Не удалось переместить документы', }, diff --git a/frontend/src/i18n/locales/zh-CN.ts b/frontend/src/i18n/locales/zh-CN.ts index 35f37c23..2723e224 100755 --- a/frontend/src/i18n/locales/zh-CN.ts +++ b/frontend/src/i18n/locales/zh-CN.ts @@ -5097,8 +5097,11 @@ export default { vlmModelSelectRequired: '已启用多模态,请选择 VLM 模型', asrModelSelectRequired: '已启用语音识别,请选择 ASR 模型', continueAdd: '继续添加', - destinationLabel: '上传到', - destinationToRoot: '改到顶层', + destinationLabel: '上传位置', + destinationChange: '更改上传位置', + destinationToRoot: '改到根目录', + folderUploadTitle: '文件夹「{name}」', + folderUploadHint: '共 {count} 个文件,将保留本地目录结构', filesAdded: '已添加 {count} 个文件', filesAllDuplicate: '所选文件已在列表中', titleManual: '在线编辑发布确认', @@ -5127,8 +5130,8 @@ export default { tagEditNoSelected: '暂未选择', folderTree: { title: '目录', - rootRow: '全部文档', - rootRowTip: '知识库顶层,所有文件夹都在它下面', + rootRow: '根目录', + rootRowTip: '知识库根目录,未归入子文件夹的文档在此', folderCardCount: '{count} 个文档', searchingSubtree: '(含子目录)', emptyFolder: '这个文件夹里还没有文档', @@ -5147,7 +5150,12 @@ export default { action: '移动到目录', newFolder: '新建子目录', newFolderPlaceholder: '输入新目录名称', + newFolderCreate: '创建', + newFolderAddRoot: '在根目录下新建子目录', + newFolderAddUnder: '在「{folder}」下新建子目录', newFolderHint: '回车创建并移动', + newFolderHintRoot: '将在根目录下创建', + newFolderHintUnder: '将在「{folder}」下创建', success: '已移动 {count} 个文档', failed: '移动失败', }, diff --git a/frontend/src/stores/uploadConfirm.ts b/frontend/src/stores/uploadConfirm.ts index 7ba3223f..3dfc2abd 100644 --- a/frontend/src/stores/uploadConfirm.ts +++ b/frontend/src/stores/uploadConfirm.ts @@ -47,6 +47,8 @@ export interface OpenUploadConfirmOptions { supportedFileTypes?: string[] /** Folder pre-selected from the sidebar tree; '' means the root. */ targetFolder?: string + /** Existing folders the dialog can offer as upload destinations. */ + folderOptions?: Array<{ path: string; name: string; depth: number }> } export const useUploadConfirmStore = defineStore('uploadConfirm', { @@ -62,6 +64,7 @@ export const useUploadConfirmStore = defineStore('uploadConfirm', { acceptFileTypes: '', supportedFileTypes: [] as string[], targetFolder: '', + folderOptions: [] as Array<{ path: string; name: string; depth: number }>, pendingResolve: null as ((value: UploadConfirmResult) => void) | null, pendingReject: null as (() => void) | null, }), @@ -82,6 +85,7 @@ export const useUploadConfirmStore = defineStore('uploadConfirm', { this.acceptFileTypes = options.acceptFileTypes || '' this.supportedFileTypes = options.supportedFileTypes ? [...options.supportedFileTypes] : [] this.targetFolder = options.targetFolder || '' + this.folderOptions = options.folderOptions ? [...options.folderOptions] : [] this.pendingResolve = resolve this.pendingReject = reject }) @@ -109,6 +113,7 @@ export const useUploadConfirmStore = defineStore('uploadConfirm', { this.acceptFileTypes = '' this.supportedFileTypes = [] this.targetFolder = '' + this.folderOptions = [] this.pendingResolve = null this.pendingReject = null }, diff --git a/frontend/src/views/knowledge/KnowledgeBase.vue b/frontend/src/views/knowledge/KnowledgeBase.vue index 82fca332..d806c8d5 100644 --- a/frontend/src/views/knowledge/KnowledgeBase.vue +++ b/frontend/src/views/knowledge/KnowledgeBase.vue @@ -647,10 +647,13 @@ const isFiltering = computed(() => }), ); // Sub-folder entries shown at the top of the list while browsing. Search results -// are flat, so they are dropped as soon as a filter is active. -const currentChildFolders = computed(() => - isFiltering.value ? [] : childFolders(folderTree.value, selectedFolderPath.value), -); +// are flat, so they are dropped as soon as a filter is active. When the sidebar +// tree is open it already lists the same folders, so skip the duplicate rows. +const currentChildFolders = computed(() => { + if (isFiltering.value) return []; + if (showFolderTree.value && !folderTreeCollapsed.value) return []; + return childFolders(folderTree.value, selectedFolderPath.value); +}); // A row's folder is worth showing only when the list can span folders. const showDocumentFolderPath = computed(() => hasFolders.value && isFiltering.value); const folderBreadcrumbs = computed(() => buildFolderBreadcrumbs(selectedFolderPath.value)); @@ -1775,8 +1778,9 @@ const openUploadConfirmDialog = async (files: File[], urls: string[] = []) => { acceptFileTypes: acceptFileTypes.value, supportedFileTypes: [...supportedFileTypes.value], // Pre-fill the destination with the folder being browsed; the dialog shows - // it and lets the user send the batch to the root instead. + // it and lets the user pick another folder (or the root) before confirming. targetFolder: selectedFolderPath.value, + folderOptions: folderOptions.value, }); await handleUploadConfirmResult(result); } catch { @@ -2327,15 +2331,25 @@ async function createNewSession(value: string): Promise {