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.
main
lyingbug 2026-08-04 10:28:39 +00:00 committed by lyingbug
parent 5fea7a1695
commit 192a721061
13 changed files with 421 additions and 387 deletions

View File

@ -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',

View File

@ -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: '문서를 이동할 수 없습니다',
},

View File

@ -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: 'Не удалось переместить документы',
},

View File

@ -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: '移动失败',
},

View File

@ -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<string[]>([]);
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<void> {
<template v-else-if="(cardList.length || currentChildFolders.length) && viewMode === 'grid'">
<DocumentCardView
:items="cardList"
:folders="currentChildFolders"
:folders="currentChildFolders" :folder-options="folderOptions"
:selected-ids="selectedIds"
:batch-mode="batchMode"
:can-edit="canEdit"
@ -2561,6 +2557,7 @@ async function createNewSession(value: string): Promise<void> {
:show-folder-path="showDocumentFolderPath"
@open="(item: any) => openKnowledgeItem(item)"
@open-folder="handleFolderSelect"
@move-to-folder="(item: any, path: string) => moveKnowledgeIntoFolder([item.id], path)"
@toggle-checkbox="onCardGridCheckboxChange"
@menu-visible-change="(visible: boolean, item: any) => onCardMoreVisibleChange(visible, item)"
@action="(action: any, item: any) => handleCardAction(action, item)"
@ -2572,7 +2569,8 @@ async function createNewSession(value: string): Promise<void> {
/>
</template>
<template v-else-if="(cardList.length || currentChildFolders.length) && viewMode === 'list'">
<DocumentListView :items="cardList" :folders="currentChildFolders" :selected-ids="selectedIds" :tag-list="tagList"
<DocumentListView :items="cardList" :folders="currentChildFolders" :folder-options="folderOptions"
:selected-ids="selectedIds" :tag-list="tagList"
:can-edit="canEdit" :can-mutate-knowledge="canMutateKnowledge"
:trace-visible-ids="traceAvailableById"
:move-menu-mode="moveMenuMode"
@ -2583,6 +2581,7 @@ async function createNewSession(value: string): Promise<void> {
:move-submitting="moveSubmitting"
:show-folder-path="showDocumentFolderPath"
@open-folder="handleFolderSelect"
@move-to-folder="(item: any, path: string) => moveKnowledgeIntoFolder([item.id], path)"
@open="(item: any) => openKnowledgeItem(item)" @toggle-row="toggleSelectRow"
@toggle-all="toggleSelectAll" @action="(action: any, item: any) => handleListAction(action, item)"
@probe-trace="(item: any) => probeTraceAvailable(item)"
@ -2607,10 +2606,10 @@ async function createNewSession(value: string): Promise<void> {
<div class="doc-batch-bar-anchor" v-show="batchMode || selectedIds.size > 0">
<DocumentBatchBar :count="selectedIds.size" :delete-loading="batchDeleting"
:reparse-loading="batchReparsing" :tag-loading="batchTagging" :visible="batchMode || selectedIds.size > 0"
:show-move-to-folder="canEdit"
:show-move-to-folder="canEdit" :folder-options="folderOptions"
@cancel="handleBatchCancel" @delete="confirmBatchDelete" @reparse="confirmBatchReparse"
@batch-tag="handleBatchTag"
@move-to-folder="openMoveToFolderDialog(Array.from(selectedIds))" />
@move-to-folder="(path: string) => moveKnowledgeIntoFolder(Array.from(selectedIds), path)" />
</div>
</div>
</div>
@ -2652,15 +2651,6 @@ async function createNewSession(value: string): Promise<void> {
@update:visible="batchTagDialogVisible = $event" @confirm="onBatchTagConfirm"
@tag-created="loadTags(kbId, true)" @open-manage="openTagManageFromBatchDialog" />
<MoveToFolderDialog
v-model:visible="moveFolderDialogVisible"
:tree="folderTree"
:count="moveFolderTargets.length"
:submitting="moveFolderSubmitting"
:current-path="selectedFolderPath"
@confirm="handleMoveToFolderConfirm"
/>
<KbTagManageDrawer
v-if="!isFAQ"
v-model:visible="tagManageDrawerVisible"

View File

@ -1,5 +1,7 @@
<script setup lang="ts">
import { ref } from 'vue';
import { useI18n } from 'vue-i18n';
import FolderPickerMenu, { type FolderOption } from './FolderPickerMenu.vue';
defineProps<{
count: number;
@ -11,6 +13,7 @@ defineProps<{
visible?: boolean;
/** Hidden when the knowledge base has no folder structure to file into. */
showMoveToFolder?: boolean;
folderOptions?: FolderOption[];
}>();
const emit = defineEmits<{
@ -18,10 +21,12 @@ const emit = defineEmits<{
(e: 'delete'): void;
(e: 'reparse'): void;
(e: 'batchTag'): void;
(e: 'moveToFolder'): void;
(e: 'moveToFolder', folderPath: string): void;
}>();
const { t } = useI18n();
const folderPickerVisible = ref(false);
</script>
<template>
@ -53,12 +58,20 @@ const { t } = useI18n();
{{ t('knowledgeBase.batchTag') }}
</t-button>
<t-button v-if="showMoveToFolder" theme="default" variant="outline" size="small"
:disabled="count === 0 || deleteLoading || reparseLoading || tagLoading"
@click="emit('moveToFolder')">
<template #icon><t-icon name="folder" size="14px" /></template>
{{ t('knowledgeBase.moveToFolder.action') }}
</t-button>
<t-popup v-if="showMoveToFolder" v-model:visible="folderPickerVisible" trigger="click"
placement="top" overlay-class-name="card-more" destroy-on-close>
<t-button theme="default" variant="outline" size="small"
:disabled="count === 0 || deleteLoading || reparseLoading || tagLoading">
<template #icon><t-icon name="folder" size="14px" /></template>
{{ t('knowledgeBase.moveToFolder.action') }}
</t-button>
<template #content>
<div class="card-menu">
<FolderPickerMenu :options="folderOptions || []"
@confirm="(path: string) => { folderPickerVisible = false; emit('moveToFolder', path) }" />
</div>
</template>
</t-popup>
<t-popconfirm theme="warning" :content="t('knowledgeBase.confirmBatchDeleteDocument', { count })"
:confirm-btn="{ content: t('knowledgeBase.confirmDelete'), theme: 'danger' }"

View File

@ -4,6 +4,7 @@ import { useI18n } from 'vue-i18n';
import { formatFileSize } from '@/utils/files';
import { useTagChipsOverflow } from '@/composables/useTagChipsOverflow';
import DocumentActionMenu from './DocumentActionMenu.vue';
import FolderPickerMenu, { type FolderOption } from './FolderPickerMenu.vue';
import KnowledgeProcessingTimeline from '@/components/knowledge-processing-timeline.vue';
interface Tag {
@ -46,6 +47,8 @@ const props = defineProps<{
tagList: Tag[];
/** Sub-folders of the folder currently being browsed. */
folders?: Array<{ path: string; name: string; total_count: number }>;
/** Every folder of the knowledge base, for the "move to folder" picker. */
folderOptions?: FolderOption[];
/**
* Replace the updated-at line with the card's folder. Only meaningful when
* the grid spans several folders, i.e. while filtering.
@ -67,6 +70,7 @@ const emit = defineEmits<{
(e: 'action', action: 'edit' | 'view-trace' | 'reparse' | 'cancel-parse' | 'move' | 'move-folder' | 'batch-manage' | 'delete', item: KnowledgeCard): void;
(e: 'tag-edit', item: KnowledgeCard): void;
(e: 'open-folder', path: string): void;
(e: 'move-to-folder', item: KnowledgeCard, folderPath: string): void;
// Move sub-flow emits
(e: 'move-select-target', kb: any): void;
(e: 'move-back'): void;
@ -83,6 +87,11 @@ const {
getOverflowCount,
} = useTagChipsOverflow('tagItemId');
// Which row's action popup is currently showing the folder picker. Kept local so
// picking a folder stays inside the menu the user already opened, exactly like
// the "move to knowledge base" sub-menu next to it.
const folderPickerItemId = ref<string | null>(null);
// --- Menu index tracking ---
const activeMenuIndex = ref(-1);
const openMenu = (index: number) => {
@ -258,8 +267,20 @@ const onCardMouseLeave = () => {
cardPopoverElement = null;
};
const onFolderPicked = (item: KnowledgeCard, path: string) => {
folderPickerItemId.value = null;
if (item.isMore !== undefined) item.isMore = false;
activeMenuIndex.value = -1;
emit('move-to-folder', item, path);
};
// --- Action handlers ---
const handleAction = (action: 'edit' | 'view-trace' | 'reparse' | 'cancel-parse' | 'move' | 'move-folder' | 'batch-manage' | 'delete', item: KnowledgeCard) => {
// The folder picker opens inside this same popup, so keep the menu open.
if (action === 'move-folder') {
folderPickerItemId.value = item.id;
return;
}
// Don't close menu for move — it triggers the sub-flow
if (action !== 'move') {
if (item.isMore !== undefined) item.isMore = false;
@ -348,6 +369,17 @@ const handleAction = (action: 'edit' | 'view-trace' | 'reparse' | 'cancel-parse'
/>
</div>
<!-- Move: folder picker -->
<div v-else-if="folderPickerItemId === item.id" class="card-menu move-menu">
<FolderPickerMenu
:options="folderOptions || []"
:current-path="item.folder_path || ''"
show-back
@back="folderPickerItemId = null"
@confirm="(path: string) => onFolderPicked(item, path)"
/>
</div>
<!-- Move: target KB list -->
<div v-else-if="moveMenuMode === 'targets'" class="card-menu move-menu">
<div class="move-menu-header" @click.stop="emit('move-back')">

View File

@ -4,6 +4,7 @@ import { useI18n } from 'vue-i18n';
import { formatFileSize, getFileIcon } from '@/utils/files';
import { useTagChipsOverflow } from '@/composables/useTagChipsOverflow';
import DocumentActionMenu from './DocumentActionMenu.vue';
import FolderPickerMenu, { type FolderOption } from './FolderPickerMenu.vue';
interface Tag {
id: string;
@ -38,6 +39,8 @@ const props = defineProps<{
loading?: boolean;
/** Sub-folders of the folder currently being browsed. */
folders?: Array<{ path: string; name: string; total_count: number }>;
/** Every folder of the knowledge base, for the "move to folder" picker. */
folderOptions?: FolderOption[];
/**
* Show each row's folder under its name. Only useful when the list spans
* several folders, i.e. while filtering; inside one folder the path would be
@ -61,6 +64,7 @@ const emit = defineEmits<{
(e: 'probe-trace', item: KnowledgeItem): void;
(e: 'tag-edit', item: KnowledgeItem): void;
(e: 'open-folder', path: string): void;
(e: 'move-to-folder', item: KnowledgeItem, folderPath: string): void;
// Move sub-flow emits
(e: 'move-select-target', kb: any): void;
(e: 'move-back'): void;
@ -214,7 +218,24 @@ onBeforeUnmount(() => {
stickyObserver = null;
});
// Which row's action popup is currently showing the folder picker. Kept local so
// picking a folder stays inside the menu the user already opened, exactly like
// the "move to knowledge base" sub-menu next to it.
const folderPickerItemId = ref<string | null>(null);
const onFolderPicked = (item: KnowledgeItem, path: string) => {
folderPickerItemId.value = null;
moreOpen.value = null;
item.isMore = false;
emit('move-to-folder', item, path);
};
const handleAction = (action: 'edit' | 'reparse' | 'cancel-parse' | 'move' | 'move-folder' | 'delete' | 'view-trace' | 'batch-manage', item: KnowledgeItem) => {
// The folder picker opens inside this same popup, so keep the menu open.
if (action === 'move-folder') {
folderPickerItemId.value = item.id;
return;
}
// Don't close popup for move — it triggers the move sub-flow
if (action !== 'move') {
moreOpen.value = null;
@ -372,6 +393,17 @@ const handleAction = (action: 'edit' | 'reparse' | 'cancel-parse' | 'move' | 'mo
/>
</div>
<!-- Move: folder picker -->
<div v-else-if="folderPickerItemId === item.id" class="card-menu move-menu">
<FolderPickerMenu
:options="folderOptions || []"
:current-path="item.folder_path || ''"
show-back
@back="folderPickerItemId = null"
@confirm="(path: string) => onFolderPicked(item, path)"
/>
</div>
<!-- Move: target KB list -->
<div v-else-if="moveMenuMode === 'targets'" class="card-menu move-menu">
<div class="move-menu-header" @click.stop="emit('move-back')">

View File

@ -0,0 +1,226 @@
<template>
<div class="folder-picker">
<div v-if="showBack" class="folder-picker__header" @click.stop="emit('back')">
<t-icon name="chevron-left" size="16px" />
<span>{{ t('knowledgeBase.moveToFolder.action') }}</span>
</div>
<div class="folder-picker__list">
<div
class="folder-picker__item"
:class="{ current: currentPath === '' }"
@click.stop="choose('')"
>
<t-icon name="folder-open" class="folder-picker__icon" />
<span class="folder-picker__name">{{ t('knowledgeBase.folderTree.rootRow') }}</span>
<t-icon v-if="currentPath === ''" name="check" class="folder-picker__current" />
</div>
<div
v-for="option in options"
:key="option.path"
class="folder-picker__item"
:class="{ current: currentPath === option.path }"
:style="{ '--folder-picker-depth': option.depth }"
:title="option.path"
@click.stop="choose(option.path)"
>
<t-icon name="folder" class="folder-picker__icon" />
<span class="folder-picker__name">{{ option.name }}</span>
<t-icon v-if="currentPath === option.path" name="check" class="folder-picker__current" />
</div>
</div>
<div class="folder-picker__create" @click.stop>
<div v-if="!creating" class="folder-picker__item" @click.stop="startCreating">
<t-icon name="folder-add" class="folder-picker__icon is-action" />
<span class="folder-picker__name is-action">{{ t('knowledgeBase.moveToFolder.newFolder') }}</span>
</div>
<template v-else>
<input
ref="newFolderInputRef"
v-model.trim="newFolderName"
class="folder-picker__input"
:placeholder="t('knowledgeBase.moveToFolder.newFolderPlaceholder')"
@keydown.enter.stop="commitNewFolder"
@keydown.esc.stop="creating = false"
/>
<p class="folder-picker__hint">{{ t('knowledgeBase.moveToFolder.newFolderHint') }}</p>
</template>
</div>
</div>
</template>
<script setup lang="ts">
import { nextTick, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import { normalizeFolderPath } from '../folderTree'
export type FolderOption = { path: string; name: string; depth: number }
const props = withDefaults(defineProps<{
options: FolderOption[]
/** Folder the documents are in today, marked so the current place is obvious. */
currentPath?: string
/** Show a back row when embedded in a menu that has a parent level. */
showBack?: boolean
}>(), {
currentPath: '',
showBack: false,
})
const emit = defineEmits<{
back: []
confirm: [folderPath: string]
}>()
const { t } = useI18n()
const creating = ref(false)
const newFolderName = ref('')
const newFolderInputRef = ref<HTMLInputElement | null>(null)
// Picking a folder is the whole action — there is nothing else to configure, so
// there is no confirm step to sit through.
const choose = (path: string) => {
if (path === props.currentPath) return
emit('confirm', path)
}
const startCreating = async () => {
creating.value = true
newFolderName.value = ''
await nextTick()
newFolderInputRef.value?.focus()
}
const commitNewFolder = () => {
const path = normalizeFolderPath(newFolderName.value)
if (!path) return
creating.value = false
newFolderName.value = ''
emit('confirm', path)
}
</script>
<style scoped lang="less">
.folder-picker {
--folder-picker-indent: 12px;
min-width: 208px;
max-width: 280px;
}
.folder-picker__header {
display: flex;
align-items: center;
gap: 6px;
padding: 6px 10px;
margin-bottom: 2px;
border-bottom: 1px solid var(--td-component-stroke);
color: var(--td-text-color-secondary);
font-size: 13px;
cursor: pointer;
&:hover {
color: var(--td-brand-color);
}
}
.folder-picker__list {
max-height: 220px;
overflow-y: auto;
scrollbar-width: thin;
&::-webkit-scrollbar {
width: 4px;
}
&::-webkit-scrollbar-thumb {
border-radius: 2px;
background: var(--td-scrollbar-color);
}
}
.folder-picker__item {
display: flex;
align-items: center;
gap: 8px;
height: 30px;
box-sizing: border-box;
padding: 0 10px 0 calc(var(--folder-picker-depth, 0) * var(--folder-picker-indent) + 10px);
border-radius: 6px;
color: var(--td-text-color-primary);
font-size: 13px;
cursor: pointer;
transition: background 0.15s ease;
&:hover {
background: var(--td-bg-color-container-hover);
}
&.current {
color: var(--td-text-color-placeholder);
cursor: default;
&:hover {
background: transparent;
}
}
}
.folder-picker__icon {
flex: 0 0 auto;
font-size: 15px;
color: var(--td-text-color-placeholder);
&.is-action {
color: var(--td-brand-color);
}
}
.folder-picker__name {
flex: 1;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
&.is-action {
color: var(--td-brand-color);
}
}
.folder-picker__current {
flex: 0 0 auto;
font-size: 14px;
color: var(--td-text-color-placeholder);
}
.folder-picker__create {
margin-top: 2px;
padding-top: 2px;
border-top: 1px solid var(--td-component-stroke);
}
.folder-picker__input {
box-sizing: border-box;
width: calc(100% - 20px);
height: 28px;
margin: 4px 10px 0;
padding: 0 8px;
border: 1px solid var(--td-brand-color);
border-radius: 4px;
background: var(--td-bg-color-container);
color: var(--td-text-color-primary);
font-family: var(--app-font-family);
font-size: 13px;
outline: none;
}
.folder-picker__hint {
margin: 4px 10px 6px;
font-size: 11px;
line-height: 1.5;
color: var(--td-text-color-placeholder);
}
</style>

View File

@ -0,0 +1,33 @@
import assert from 'node:assert/strict'
import test from 'node:test'
import { readFileSync } from 'node:fs'
const tree = readFileSync(new URL('./KbFolderTree.vue', import.meta.url), 'utf8')
const batchBar = readFileSync(new URL('./DocumentBatchBar.vue', import.meta.url), 'utf8')
const cardView = readFileSync(new URL('./DocumentCardView.vue', import.meta.url), 'utf8')
const listView = readFileSync(new URL('./DocumentListView.vue', import.meta.url), 'utf8')
// The root folder's own path IS the empty string, so a falsy "nothing is being
// renamed" sentinel matches it and leaves a stray rename input on the root row.
// Two independent guards keep that from coming back.
test('the rename sentinel cannot collide with the root folder path', () => {
assert.match(tree, /const renamingPath = ref<string \| null>\(null\)/)
assert.doesNotMatch(tree, /const renamingPath = ref\(''\)/)
assert.match(tree, /row\.kind === 'folder' && renamingPath\.value === row\.path/)
})
test('only real folders expose a rename affordance', () => {
assert.match(tree, /v-if="canEdit && row\.kind === 'folder'"/)
})
// Picking a folder is a small, reversible action, so it stays a popup: in the row
// menu it is another level of the menu that is already open, and in the batch bar
// it hangs off the button. Neither should escalate to a modal dialog.
test('the folder picker is a popup rather than a modal', () => {
assert.match(cardView, /folderPickerItemId === item\.id/)
assert.match(listView, /folderPickerItemId === item\.id/)
assert.match(batchBar, /<t-popup[^>]*v-model:visible="folderPickerVisible"/)
for (const source of [cardView, listView, batchBar]) {
assert.doesNotMatch(source, /MoveToFolderDialog/)
}
})

View File

@ -64,7 +64,7 @@
/>
<input
v-if="renamingPath === row.path"
v-if="isRenaming(row)"
ref="renameInputRef"
v-model="renameValue"
class="kb-folder-row__rename"
@ -128,7 +128,9 @@ const { t } = useI18n()
// The root starts expanded so the uploaded structure is visible without a click.
const expanded = ref(new Set<string>([ROOT_FOLDER_PATH]))
const renamingPath = ref('')
// null, not '', because '' is the root's own path: a falsy sentinel would put
// the root row into rename mode permanently.
const renamingPath = ref<string | null>(null)
const renameValue = ref('')
const renameInputRef = ref<HTMLInputElement | HTMLInputElement[] | null>(null)
@ -136,6 +138,10 @@ const rows = computed(() => buildFolderRows(props.tree, expanded.value))
const isExpanded = (path: string) => expanded.value.has(path)
// The root has no name of its own to edit, and excluding it here means no
// sentinel value can ever put it into rename mode.
const isRenaming = (row: FolderRow) => row.kind === 'folder' && renamingPath.value === row.path
const toggle = (path: string) => {
const next = new Set(expanded.value)
if (next.has(path)) next.delete(path)
@ -153,12 +159,12 @@ const startRename = async (row: FolderRow) => {
}
const cancelRename = () => {
renamingPath.value = ''
renamingPath.value = null
renameValue.value = ''
}
const commitRename = (row: FolderRow) => {
if (renamingPath.value !== row.path) return
if (!isRenaming(row)) return
const name = renameValue.value.trim()
cancelRename()
// Only the last segment is edited here; the folder keeps its place in the tree.

View File

@ -1,256 +0,0 @@
<template>
<t-dialog
:visible="visible"
:header="t('knowledgeBase.moveToFolder.title', { count })"
:confirm-btn="{ content: t('knowledgeBase.moveToFolder.confirm'), theme: 'primary', loading: submitting, disabled: !canSubmit }"
:cancel-btn="{ content: t('common.cancel') }"
width="480px"
@confirm="handleConfirm"
@close="close"
@cancel="close"
>
<div class="move-folder-body">
<p class="move-folder-hint">{{ t('knowledgeBase.moveToFolder.hint') }}</p>
<div class="move-folder-list">
<button
type="button"
class="move-folder-option"
:class="{ active: selected === '' && !creating }"
@click="pick('')"
>
<t-icon name="folder-open" class="move-folder-option__icon" />
<span class="move-folder-option__label">{{ t('knowledgeBase.folderTree.rootRow') }}</span>
<t-icon v-if="selected === '' && !creating" name="check" class="move-folder-option__check" />
</button>
<button
v-for="option in options"
:key="option.path"
type="button"
class="move-folder-option"
:class="{ active: selected === option.path && !creating }"
:style="{ '--move-folder-depth': option.depth }"
:title="option.path"
@click="pick(option.path)"
>
<t-icon name="folder" class="move-folder-option__icon" />
<span class="move-folder-option__label">{{ option.name }}</span>
<t-icon v-if="selected === option.path && !creating" name="check" class="move-folder-option__check" />
</button>
</div>
<div class="move-folder-create">
<button v-if="!creating" type="button" class="move-folder-create__trigger" @click="startCreating">
<t-icon name="folder-add" />
<span>{{ t('knowledgeBase.moveToFolder.newFolder') }}</span>
</button>
<template v-else>
<t-input
v-model.trim="newFolderName"
:placeholder="t('knowledgeBase.moveToFolder.newFolderPlaceholder')"
autofocus
clearable
@enter="handleConfirm"
/>
<p class="move-folder-create__preview">
{{ newFolderPath
? t('knowledgeBase.moveToFolder.newFolderPreview', { path: newFolderPath })
: t('knowledgeBase.moveToFolder.newFolderUnderRoot') }}
</p>
</template>
</div>
</div>
</t-dialog>
</template>
<script setup lang="ts">
import { computed, ref, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import type { KnowledgeFolderNode, KnowledgeFolderTree } from '@/api/knowledge-base/index'
import { joinFolderPath } from '../folderTree'
const props = withDefaults(defineProps<{
visible: boolean
tree: KnowledgeFolderTree | null
count: number
submitting?: boolean
/** Folder the documents are currently in, pre-selected as the starting point. */
currentPath?: string
}>(), {
submitting: false,
currentPath: '',
})
const emit = defineEmits<{
'update:visible': [value: boolean]
confirm: [folderPath: string]
}>()
const { t } = useI18n()
const selected = ref('')
const creating = ref(false)
const newFolderName = ref('')
type FolderOption = { path: string; name: string; depth: number }
const options = computed<FolderOption[]>(() => {
const result: FolderOption[] = []
const walk = (nodes: KnowledgeFolderNode[], depth: number) => {
nodes.forEach((node) => {
result.push({ path: node.path, name: node.name, depth })
walk(node.children || [], depth + 1)
})
}
walk(props.tree?.folders ?? [], 0)
return result
})
// A new folder is created under whichever folder is currently highlighted, so
// the picker doubles as "where to put it".
const newFolderPath = computed(() => joinFolderPath(selected.value, newFolderName.value))
const canSubmit = computed(() => (creating.value ? !!newFolderPath.value : true))
const pick = (path: string) => {
selected.value = path
creating.value = false
newFolderName.value = ''
}
const startCreating = () => {
creating.value = true
newFolderName.value = ''
}
const close = () => {
emit('update:visible', false)
}
const handleConfirm = () => {
if (!canSubmit.value) return
emit('confirm', creating.value ? newFolderPath.value : selected.value)
}
watch(
() => props.visible,
(visible) => {
if (!visible) return
selected.value = props.currentPath || ''
creating.value = false
newFolderName.value = ''
},
{ immediate: true },
)
</script>
<style scoped lang="less">
.move-folder-body {
display: flex;
flex-direction: column;
gap: 10px;
}
.move-folder-hint {
margin: 0;
font-size: 12px;
line-height: 1.6;
color: var(--td-text-color-placeholder);
}
.move-folder-list {
--move-folder-indent: 16px;
max-height: 260px;
overflow-y: auto;
padding: 4px;
border: 1px solid var(--td-component-stroke);
border-radius: 6px;
scrollbar-width: thin;
&::-webkit-scrollbar {
width: 4px;
}
&::-webkit-scrollbar-thumb {
border-radius: 2px;
background: var(--td-scrollbar-color);
}
}
.move-folder-option {
display: flex;
align-items: center;
gap: 6px;
box-sizing: border-box;
width: 100%;
height: 30px;
padding: 0 8px 0 calc(var(--move-folder-depth, 0) * var(--move-folder-indent) + 8px);
border: 0;
border-radius: 4px;
background: transparent;
color: var(--td-text-color-primary);
font-family: var(--app-font-family);
font-size: 13px;
text-align: left;
cursor: pointer;
transition: background 0.15s ease, color 0.15s ease;
&:hover {
background: var(--td-bg-color-container-hover);
}
&.active {
background: color-mix(in srgb, var(--td-brand-color) 8%, transparent);
color: var(--td-brand-color);
.move-folder-option__icon {
color: var(--td-brand-color);
}
}
}
.move-folder-option__icon {
flex: 0 0 auto;
font-size: 15px;
color: var(--td-text-color-placeholder);
}
.move-folder-option__label {
flex: 1;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.move-folder-option__check {
flex: 0 0 auto;
font-size: 14px;
}
.move-folder-create__trigger {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 0;
border: 0;
background: transparent;
color: var(--td-brand-color);
font-family: var(--app-font-family);
font-size: 13px;
cursor: pointer;
.t-icon {
font-size: 15px;
}
}
.move-folder-create__preview {
margin: 6px 0 0;
font-size: 12px;
line-height: 1.6;
color: var(--td-text-color-placeholder);
word-break: break-all;
}
</style>

View File

@ -28,22 +28,18 @@
</div>
</div>
<!-- Where the batch lands. Shown for every file upload so browsing
a folder never silently decides the destination. -->
<div v-if="mode === 'file'" class="destination-row">
<t-icon :name="localTargetFolder ? 'folder' : 'folder-open'" class="destination-icon" />
<span class="destination-label">{{ t('uploadConfirm.destinationLabel') }}</span>
<span class="destination-path" :title="destinationTitle">{{ destinationText }}</span>
<t-tooltip v-if="localTargetFolder" :content="t('uploadConfirm.destinationToRoot')" placement="top">
<button
type="button"
class="destination-clear"
:aria-label="t('uploadConfirm.destinationToRoot')"
@click="localTargetFolder = ''"
>
<t-icon name="close-circle-filled" />
</button>
</t-tooltip>
<!-- Where the batch lands. Only shown when it is somewhere other
than the top level, i.e. when browsing a folder made the
destination non-obvious. -->
<div v-if="mode === 'file' && localTargetFolder" class="destination-row">
<t-icon name="folder" class="destination-icon" />
<span class="destination-text">
{{ t('uploadConfirm.destinationLabel') }}
<strong class="destination-path" :title="localTargetFolder">{{ destinationLeaf }}</strong>
</span>
<button type="button" class="destination-reset" @click="localTargetFolder = ''">
{{ t('uploadConfirm.destinationToRoot') }}
</button>
</div>
<div class="files-list-wrap">
@ -650,15 +646,13 @@ const dialogVisible = computed({
set: (value: boolean) => emit('update:visible', value),
})
const destinationText = computed(() =>
localTargetFolder.value || t('uploadConfirm.destinationRoot'),
)
const destinationTitle = computed(() =>
localTargetFolder.value
? t('uploadConfirm.destinationTip', { folder: localTargetFolder.value })
: t('uploadConfirm.destinationRootTip'),
)
// Deep paths are shown by their last segment; the full path stays in the title.
// Truncating from the left with `direction: rtl` mangled CJK folder names.
const destinationLeaf = computed(() => {
const path = localTargetFolder.value
const idx = path.lastIndexOf('/')
return idx >= 0 ? path.slice(idx + 1) : path
})
/**
* Directory a folder-upload file came from, shown under its name so a batch of
@ -1503,62 +1497,54 @@ const handleConfirm = () => {
color: var(--td-text-color-secondary);
}
// A quiet line rather than a banner: it is a fact about the batch, not a control
// that should compete with the file list.
.destination-row {
display: flex;
align-items: center;
align-items: baseline;
gap: 6px;
flex-shrink: 0;
margin: 0 8px;
padding: 6px 8px;
border-radius: 6px;
background: var(--td-bg-color-secondarycontainer);
margin: 0 10px;
font-size: 12px;
line-height: 18px;
color: var(--td-text-color-placeholder);
}
.destination-icon {
flex-shrink: 0;
font-size: 14px;
color: var(--td-text-color-placeholder);
align-self: center;
font-size: 13px;
}
.destination-label {
flex-shrink: 0;
color: var(--td-text-color-placeholder);
}
.destination-path {
.destination-text {
flex: 1;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
direction: rtl;
text-align: left;
color: var(--td-text-color-primary);
}
.destination-clear {
display: flex;
.destination-path {
color: var(--td-text-color-primary);
font-weight: 500;
}
.destination-reset {
flex-shrink: 0;
align-items: center;
justify-content: center;
width: 18px;
height: 18px;
padding: 0;
border: 0;
border-radius: 50%;
background: transparent;
color: var(--td-text-color-placeholder);
font-family: var(--app-font-family);
font-size: 12px;
text-decoration: underline;
text-decoration-color: transparent;
cursor: pointer;
transition: color 0.15s ease;
transition: color 0.15s ease, text-decoration-color 0.15s ease;
&:hover {
color: var(--td-text-color-secondary);
}
.t-icon {
font-size: 14px;
color: var(--td-brand-color);
text-decoration-color: currentColor;
}
}