From 192a7210614dab668c18de671e2b5b2f317cb5af Mon Sep 17 00:00:00 2001 From: lyingbug <[email> Date: Tue, 4 Aug 2026 10:28:39 +0000 Subject: [PATCH] fix(knowledge): stop the root row rendering a rename input, and demote the folder picker to a popup Two things the folder UI got wrong. The rename state used the empty string to mean "nothing is being renamed", but the empty string is also the root folder's own path, so the root row matched and permanently rendered a stray rename input. The sentinel is now null, and rename is additionally gated on the row being a real folder, so no sentinel value can reach the root again. Moving documents also did not deserve a modal dialog: it is one small, reversible choice. In a row's menu the picker is now another level of the menu that is already open, mirroring the "move to knowledge base" sub-menu right next to it; in the batch bar it hangs off the button. Picking a folder performs the move, since there is nothing else to confirm. The upload destination line was also mangling folder names: truncating from the left with direction: rtl reorders CJK text. It now shows the destination's last segment with the full path in the title, reads as a quiet line instead of a grey banner, and only appears when the destination is not the top level. --- frontend/src/i18n/locales/en-US.ts | 11 +- frontend/src/i18n/locales/ko-KR.ts | 11 +- frontend/src/i18n/locales/ru-RU.ts | 11 +- frontend/src/i18n/locales/zh-CN.ts | 11 +- .../src/views/knowledge/KnowledgeBase.vue | 50 ++-- .../knowledge/components/DocumentBatchBar.vue | 27 +- .../knowledge/components/DocumentCardView.vue | 32 +++ .../knowledge/components/DocumentListView.vue | 32 +++ .../knowledge/components/FolderPickerMenu.vue | 226 ++++++++++++++++ .../knowledge/components/KbFolderTree.test.ts | 33 +++ .../knowledge/components/KbFolderTree.vue | 14 +- .../components/MoveToFolderDialog.vue | 256 ------------------ .../components/UploadConfirmDialog.vue | 94 +++---- 13 files changed, 421 insertions(+), 387 deletions(-) create mode 100644 frontend/src/views/knowledge/components/FolderPickerMenu.vue create mode 100644 frontend/src/views/knowledge/components/KbFolderTree.test.ts delete mode 100644 frontend/src/views/knowledge/components/MoveToFolderDialog.vue diff --git a/frontend/src/i18n/locales/en-US.ts b/frontend/src/i18n/locales/en-US.ts index 0aaa47b9..80879bef 100755 --- a/frontend/src/i18n/locales/en-US.ts +++ b/frontend/src/i18n/locales/en-US.ts @@ -389,13 +389,9 @@ export default { }, moveToFolder: { action: 'Move to folder', - title: 'Move {count} documents', - hint: 'Pick a destination. Folders are derived from document paths, so this only changes grouping — nothing is re-parsed.', - confirm: 'Move', newFolder: 'New sub-folder', newFolderPlaceholder: 'New folder name', - newFolderPreview: 'Will create and move to "{path}"', - newFolderUnderRoot: 'Enter a folder name', + newFolderHint: 'Press Enter to create and move', success: 'Moved {count} documents', failed: 'Could not move the documents', }, @@ -688,10 +684,7 @@ export default { }, continueAdd: 'Add more', destinationLabel: 'Upload to', - destinationRoot: 'Knowledge base top level', - destinationRootTip: 'Files go to the top level of the knowledge base, not into any folder', - destinationTip: 'Files go into the folder "{folder}"', - destinationToRoot: 'Upload to the top level instead', + destinationToRoot: 'Use top level', 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 acc86cbc..ffae1adf 100755 --- a/frontend/src/i18n/locales/ko-KR.ts +++ b/frontend/src/i18n/locales/ko-KR.ts @@ -5098,10 +5098,7 @@ export default { asrModelSelectRequired: '음성 인식이 활성화되었습니다. ASR 모델을 선택하세요', continueAdd: '계속 추가', destinationLabel: '업로드 위치', - destinationRoot: '지식 베이스 최상위', - destinationRootTip: '파일이 폴더가 아닌 지식 베이스 최상위에 업로드됩니다', - destinationTip: '파일이 「{folder}」 폴더에 업로드됩니다', - destinationToRoot: '최상위에 업로드하도록 변경', + destinationToRoot: '최상위로 변경', filesAdded: '{count}개 파일이 추가되었습니다', filesAllDuplicate: '선택한 파일이 이미 목록에 있습니다', titleManual: '온라인 편집 게시 확인', @@ -5148,13 +5145,9 @@ export default { }, moveToFolder: { action: '폴더로 이동', - title: '문서 {count}개 이동', - hint: '대상 폴더를 선택하세요. 폴더는 문서 경로에서 파생되므로 분류만 바뀌고 다시 처리되지 않습니다.', - confirm: '이동', newFolder: '새 하위 폴더', newFolderPlaceholder: '새 폴더 이름', - newFolderPreview: '「{path}」을(를) 만들어 이동합니다', - newFolderUnderRoot: '폴더 이름을 입력하세요', + newFolderHint: 'Enter로 만들고 이동', success: '문서 {count}개를 이동했습니다', failed: '문서를 이동할 수 없습니다', }, diff --git a/frontend/src/i18n/locales/ru-RU.ts b/frontend/src/i18n/locales/ru-RU.ts index 7cdc12e7..ceb6ac02 100755 --- a/frontend/src/i18n/locales/ru-RU.ts +++ b/frontend/src/i18n/locales/ru-RU.ts @@ -5098,10 +5098,7 @@ export default { asrModelSelectRequired: 'Распознавание речи включено. Выберите модель ASR.', continueAdd: 'Добавить ещё', destinationLabel: 'Загрузить в', - destinationRoot: 'Верхний уровень базы знаний', - destinationRootTip: 'Файлы попадут на верхний уровень базы знаний, вне папок', - destinationTip: 'Файлы попадут в папку «{folder}»', - destinationToRoot: 'Загрузить на верхний уровень', + destinationToRoot: 'На верхний уровень', filesAdded: 'Добавлено файлов: {count}', filesAllDuplicate: 'Выбранные файлы уже в списке', titleManual: 'Подтверждение публикации', @@ -5148,13 +5145,9 @@ export default { }, moveToFolder: { action: 'Переместить в папку', - title: 'Переместить документов: {count}', - hint: 'Выберите папку. Папки выводятся из путей документов, поэтому меняется только группировка — повторная обработка не выполняется.', - confirm: 'Переместить', newFolder: 'Новая вложенная папка', newFolderPlaceholder: 'Название новой папки', - newFolderPreview: 'Будет создана папка «{path}»', - newFolderUnderRoot: 'Введите название папки', + newFolderHint: 'Enter — создать и переместить', success: 'Перемещено документов: {count}', failed: 'Не удалось переместить документы', }, diff --git a/frontend/src/i18n/locales/zh-CN.ts b/frontend/src/i18n/locales/zh-CN.ts index 721c6729..35f37c23 100755 --- a/frontend/src/i18n/locales/zh-CN.ts +++ b/frontend/src/i18n/locales/zh-CN.ts @@ -5098,10 +5098,7 @@ export default { asrModelSelectRequired: '已启用语音识别,请选择 ASR 模型', continueAdd: '继续添加', destinationLabel: '上传到', - destinationRoot: '知识库顶层', - destinationRootTip: '文件将上传到知识库顶层,不放入任何文件夹', - destinationTip: '文件将上传到文件夹「{folder}」', - destinationToRoot: '改为上传到顶层', + destinationToRoot: '改到顶层', filesAdded: '已添加 {count} 个文件', filesAllDuplicate: '所选文件已在列表中', titleManual: '在线编辑发布确认', @@ -5148,13 +5145,9 @@ export default { }, moveToFolder: { action: '移动到目录', - title: '移动 {count} 个文档', - hint: '选择目标目录。目录由文档路径推导而来,只调整归类,不会重新解析文档。', - confirm: '移动', newFolder: '新建子目录', newFolderPlaceholder: '输入新目录名称', - newFolderPreview: '将创建并移动到「{path}」', - newFolderUnderRoot: '请输入目录名称', + newFolderHint: '回车创建并移动', success: '已移动 {count} 个文档', failed: '移动失败', }, diff --git a/frontend/src/views/knowledge/KnowledgeBase.vue b/frontend/src/views/knowledge/KnowledgeBase.vue index 71e23b2c..82fca332 100644 --- a/frontend/src/views/knowledge/KnowledgeBase.vue +++ b/frontend/src/views/knowledge/KnowledgeBase.vue @@ -47,7 +47,6 @@ import DocumentCardView from './components/DocumentCardView.vue'; import DocumentBatchBar from './components/DocumentBatchBar.vue'; import KbUploadSourceDropdown from './components/KbUploadSourceDropdown.vue'; import KbFolderTree from './components/KbFolderTree.vue'; -import MoveToFolderDialog from './components/MoveToFolderDialog.vue'; import TagEditDialog from './components/TagEditDialog.vue'; import BatchTagDialog from './components/BatchTagDialog.vue'; import KbTagManageDrawer from './components/KbTagManageDrawer.vue'; @@ -804,23 +803,24 @@ const handleFolderSelect = (path: string) => { // ── Re-filing documents and renaming folders ── // folder_path is display-only, so both operations are a plain column update: // nothing is re-parsed, re-chunked or re-embedded. -const moveFolderDialogVisible = ref(false); -const moveFolderSubmitting = ref(false); -const moveFolderTargets = ref([]); -const openMoveToFolderDialog = (ids: string[]) => { - if (!ids.length) return; - moveFolderTargets.value = [...ids]; - moveFolderDialogVisible.value = true; -}; +// Flat folder list shared by every "move to folder" picker. +const folderOptions = computed(() => { + const result: Array<{ path: string; name: string; depth: number }> = []; + const walk = (nodes: KnowledgeFolderTree['folders'], depth: number) => { + nodes.forEach((node) => { + result.push({ path: node.path, name: node.name, depth }); + walk(node.children || [], depth + 1); + }); + }; + walk(folderTree.value?.folders || [], 0); + return result; +}); -const handleMoveToFolderConfirm = async (folderPath: string) => { - const ids = moveFolderTargets.value; +const moveKnowledgeIntoFolder = async (ids: string[], folderPath: string) => { if (!kbId.value || ids.length === 0) return; - moveFolderSubmitting.value = true; try { await moveKnowledgeToFolder(kbId.value, ids, folderPath); - moveFolderDialogVisible.value = false; MessagePlugin.success(t('knowledgeBase.moveToFolder.success', { count: ids.length })); clearSelection(); batchMode.value = false; @@ -829,8 +829,6 @@ const handleMoveToFolderConfirm = async (folderPath: string) => { await loadFolderTree(kbId.value); } catch (error: any) { MessagePlugin.error(error?.message || t('knowledgeBase.moveToFolder.failed')); - } finally { - moveFolderSubmitting.value = false; } }; @@ -2149,7 +2147,6 @@ const handleCardAction = ( } if (action === 'cancel-parse') return confirmCancelParseKnowledge(item); if (action === 'move') return handleMoveKnowledge(item); - if (action === 'move-folder') return openMoveToFolderDialog([item.id]); if (action === 'delete') return confirmDeleteKnowledge(idx, item); if (action === 'view-trace') return handleViewTrace(idx, item); if (action === 'batch-manage') return handleEnterBatchFromCard(item); @@ -2165,7 +2162,6 @@ const handleListAction = ( if (action === 'reparse') return confirmRebuildKnowledge(idx, item); if (action === 'cancel-parse') return confirmCancelParseKnowledge(item); if (action === 'move') return handleMoveKnowledge(item); - if (action === 'move-folder') return openMoveToFolderDialog([item.id]); if (action === 'delete') return confirmDeleteKnowledge(idx, item); if (action === 'view-trace') return handleViewTrace(idx, item); if (action === 'batch-manage') return handleEnterBatchFromCard(item); @@ -2545,7 +2541,7 @@ async function createNewSession(value: string): Promise {