fix(knowledge): give individually uploaded documents a visible home in the tree
A folder-only tree cannot show a node for a document that is not in any folder, so single-file uploads were unreachable from the sidebar: a base with 5 documents and one 3-document folder just left two of them unaccounted for. Rather than add a second pseudo-folder row for them (the ambiguity the previous commit removed), the one existing mechanism is made visible: the scope switch is now a labeled segmented control instead of an icon behind a tooltip, and the root row is named after whatever the current scope makes it list - the whole base, or exactly the unfiled documents. The breadcrumb's leading crumb follows the same rule.main
parent
d6083c6c98
commit
b3e31a24d9
|
|
@ -373,9 +373,13 @@ export default {
|
|||
title: 'Folders',
|
||||
rootRow: 'All documents',
|
||||
rootRowTip: 'The top level of the knowledge base; every folder sits below it',
|
||||
rootRowDirect: 'Unfiled documents',
|
||||
rootRowDirectTip: 'Documents uploaded on their own, not inside any folder',
|
||||
scopeToggle: 'Change list scope',
|
||||
scopeSubtreeTip: 'Including sub-folders — click to list only this level',
|
||||
scopeDirectTip: 'Listing only this level — click to include sub-folders',
|
||||
scopeSubtree: 'With sub-folders',
|
||||
scopeDirect: 'This level',
|
||||
scopeSubtreeTip: 'List every document in the selected folder and its sub-folders',
|
||||
scopeDirectTip: 'List only the selected folder\'s own documents; on the top level these are the unfiled ones',
|
||||
collapse: 'Collapse folders',
|
||||
expand: 'Expand folders',
|
||||
collapseFolder: 'Collapse this folder',
|
||||
|
|
|
|||
|
|
@ -5132,9 +5132,13 @@ export default {
|
|||
title: '폴더',
|
||||
rootRow: '전체 문서',
|
||||
rootRowTip: '지식 베이스의 최상위이며 모든 폴더가 그 아래에 있습니다',
|
||||
rootRowDirect: '미분류 문서',
|
||||
rootRowDirectTip: '단독으로 업로드되어 어떤 폴더에도 속하지 않은 문서',
|
||||
scopeToggle: '목록 범위 변경',
|
||||
scopeSubtreeTip: '하위 폴더 포함 중 — 클릭하면 이 단계만 표시합니다',
|
||||
scopeDirectTip: '이 단계만 표시 중 — 클릭하면 하위 폴더를 포함합니다',
|
||||
scopeSubtree: '하위 포함',
|
||||
scopeDirect: '현재 단계',
|
||||
scopeSubtreeTip: '선택한 폴더와 하위 폴더의 모든 문서를 표시합니다',
|
||||
scopeDirectTip: '선택한 폴더 자체의 문서만 표시합니다. 최상위에서는 미분류 문서입니다',
|
||||
collapse: '폴더 접기',
|
||||
expand: '폴더 펼치기',
|
||||
collapseFolder: '이 폴더 접기',
|
||||
|
|
|
|||
|
|
@ -5132,9 +5132,13 @@ export default {
|
|||
title: 'Папки',
|
||||
rootRow: 'Все документы',
|
||||
rootRowTip: 'Верхний уровень базы знаний — все папки находятся внутри него',
|
||||
rootRowDirect: 'Документы вне папок',
|
||||
rootRowDirectTip: 'Документы, загруженные по отдельности и не находящиеся ни в одной папке',
|
||||
scopeToggle: 'Изменить область списка',
|
||||
scopeSubtreeTip: 'Вложенные папки включены — нажмите, чтобы показать только этот уровень',
|
||||
scopeDirectTip: 'Показан только этот уровень — нажмите, чтобы включить вложенные папки',
|
||||
scopeSubtree: 'С вложенными',
|
||||
scopeDirect: 'Этот уровень',
|
||||
scopeSubtreeTip: 'Показать все документы выбранной папки и её вложенных папок',
|
||||
scopeDirectTip: 'Показать только документы самой выбранной папки; на верхнем уровне это документы вне папок',
|
||||
collapse: 'Свернуть папки',
|
||||
expand: 'Развернуть папки',
|
||||
collapseFolder: 'Свернуть эту папку',
|
||||
|
|
|
|||
|
|
@ -5132,9 +5132,13 @@ export default {
|
|||
title: '目录',
|
||||
rootRow: '全部文档',
|
||||
rootRowTip: '知识库顶层,所有文件夹都在它下面',
|
||||
rootRowDirect: '未归类文档',
|
||||
rootRowDirectTip: '直接上传、不在任何文件夹里的文档',
|
||||
scopeToggle: '切换列表范围',
|
||||
scopeSubtreeTip: '当前包含子目录,点击改为仅显示本层文档',
|
||||
scopeDirectTip: '当前仅显示本层文档,点击改为包含子目录',
|
||||
scopeSubtree: '含子目录',
|
||||
scopeDirect: '仅本层',
|
||||
scopeSubtreeTip: '列出所选目录及其子目录里的全部文档',
|
||||
scopeDirectTip: '只列出所选目录本层的文档;选中顶层即为未归类文档',
|
||||
collapse: '收起目录',
|
||||
expand: '展开目录',
|
||||
collapseFolder: '收起该文件夹',
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ import {
|
|||
folderBreadcrumbs as buildFolderBreadcrumbs,
|
||||
folderPathExists as folderExistsInTree,
|
||||
isFolderUpload,
|
||||
rootRowLabelKey,
|
||||
ROOT_FOLDER_PATH,
|
||||
} from './folderTree';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
|
@ -638,6 +639,8 @@ const showFolderTree = computed(() => !isFAQ.value && hasFolders.value);
|
|||
// Rows only need their folder shown when the current list can span folders.
|
||||
const showDocumentFolderPath = computed(() => hasFolders.value && folderRecursive.value);
|
||||
const folderBreadcrumbs = computed(() => buildFolderBreadcrumbs(selectedFolderPath.value));
|
||||
// Leading crumb mirrors the sidebar's root row, whose label depends on the scope.
|
||||
const folderRootLabel = computed(() => t(rootRowLabelKey(folderRecursive.value)));
|
||||
|
||||
const filterParams = computed(() => {
|
||||
const [start, end] = updatedTimeRange.value || [];
|
||||
|
|
@ -2269,7 +2272,7 @@ async function createNewSession(value: string): Promise<void> {
|
|||
<nav v-if="showFolderTree && folderBreadcrumbs.length" class="doc-folder-path"
|
||||
:aria-label="$t('knowledgeBase.folderTree.title')">
|
||||
<button type="button" class="doc-folder-path__crumb" @click="handleFolderSelect('')">
|
||||
{{ $t('knowledgeBase.folderTree.rootRow') }}
|
||||
{{ folderRootLabel }}
|
||||
</button>
|
||||
<template v-for="(crumb, index) in folderBreadcrumbs" :key="crumb.path">
|
||||
<t-icon name="chevron-right" class="doc-folder-path__sep" />
|
||||
|
|
|
|||
|
|
@ -3,35 +3,16 @@
|
|||
<div class="kb-folder-tree__header">
|
||||
<template v-if="!collapsed">
|
||||
<span class="kb-folder-tree__title">{{ t('knowledgeBase.folderTree.title') }}</span>
|
||||
<div class="kb-folder-tree__header-actions">
|
||||
<t-tooltip
|
||||
:content="recursive
|
||||
? t('knowledgeBase.folderTree.scopeSubtreeTip')
|
||||
: t('knowledgeBase.folderTree.scopeDirectTip')"
|
||||
placement="top"
|
||||
<t-tooltip :content="t('knowledgeBase.folderTree.collapse')" placement="top">
|
||||
<button
|
||||
type="button"
|
||||
class="kb-folder-tree__icon-btn"
|
||||
:aria-label="t('knowledgeBase.folderTree.collapse')"
|
||||
@click="emit('update:collapsed', true)"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="kb-folder-tree__icon-btn"
|
||||
:class="{ active: recursive }"
|
||||
:aria-pressed="recursive"
|
||||
:aria-label="t('knowledgeBase.folderTree.scopeToggle')"
|
||||
@click="emit('update:recursive', !recursive)"
|
||||
>
|
||||
<t-icon :name="recursive ? 'tree-round-dot-vertical' : 'file-1'" size="15px" />
|
||||
</button>
|
||||
</t-tooltip>
|
||||
<t-tooltip :content="t('knowledgeBase.folderTree.collapse')" placement="top">
|
||||
<button
|
||||
type="button"
|
||||
class="kb-folder-tree__icon-btn"
|
||||
:aria-label="t('knowledgeBase.folderTree.collapse')"
|
||||
@click="emit('update:collapsed', true)"
|
||||
>
|
||||
<t-icon name="chevron-left-double" size="15px" />
|
||||
</button>
|
||||
</t-tooltip>
|
||||
</div>
|
||||
<t-icon name="chevron-left-double" size="15px" />
|
||||
</button>
|
||||
</t-tooltip>
|
||||
</template>
|
||||
<t-tooltip v-else :content="t('knowledgeBase.folderTree.expand')" placement="right">
|
||||
<button
|
||||
|
|
@ -45,6 +26,25 @@
|
|||
</t-tooltip>
|
||||
</div>
|
||||
|
||||
<!-- Labeled rather than an icon toggle: this switch is what makes the
|
||||
documents outside every folder reachable, so it must be readable at a
|
||||
glance instead of hiding behind a tooltip. -->
|
||||
<div v-if="!collapsed" class="kb-folder-scope" role="group"
|
||||
:aria-label="t('knowledgeBase.folderTree.scopeToggle')">
|
||||
<t-tooltip :content="t('knowledgeBase.folderTree.scopeSubtreeTip')" placement="bottom">
|
||||
<button type="button" class="kb-folder-scope__btn" :class="{ active: recursive }"
|
||||
:aria-pressed="recursive" @click="emit('update:recursive', true)">
|
||||
{{ t('knowledgeBase.folderTree.scopeSubtree') }}
|
||||
</button>
|
||||
</t-tooltip>
|
||||
<t-tooltip :content="t('knowledgeBase.folderTree.scopeDirectTip')" placement="bottom">
|
||||
<button type="button" class="kb-folder-scope__btn" :class="{ active: !recursive }"
|
||||
:aria-pressed="!recursive" @click="emit('update:recursive', false)">
|
||||
{{ t('knowledgeBase.folderTree.scopeDirect') }}
|
||||
</button>
|
||||
</t-tooltip>
|
||||
</div>
|
||||
|
||||
<div v-if="!collapsed" class="kb-folder-tree__body">
|
||||
<template v-if="loading && !tree">
|
||||
<div v-for="n in 5" :key="'folder-skel-' + n" class="kb-folder-tree__skeleton">
|
||||
|
|
@ -91,6 +91,8 @@ import {
|
|||
buildFolderRows,
|
||||
folderAncestorPaths,
|
||||
folderRowCount,
|
||||
rootRowLabelKey,
|
||||
rootRowTitleKey,
|
||||
ROOT_FOLDER_PATH,
|
||||
type FolderRow,
|
||||
} from '../folderTree'
|
||||
|
|
@ -125,15 +127,17 @@ const rows = computed(() => buildFolderRows(props.tree, expanded.value))
|
|||
const isExpanded = (path: string) => expanded.value.has(path)
|
||||
|
||||
const rowLabel = (row: FolderRow) =>
|
||||
row.kind === 'root' ? t('knowledgeBase.folderTree.rootRow') : row.name
|
||||
row.kind === 'root' ? t(rootRowLabelKey(props.recursive)) : row.name
|
||||
|
||||
const rowIcon = (row: FolderRow) => {
|
||||
if (row.kind === 'root') return 'folder-open'
|
||||
// Direct scope on the root lists the loose documents rather than the whole
|
||||
// base, so the icon drops the "folder" metaphor it no longer stands for.
|
||||
if (row.kind === 'root') return props.recursive ? 'folder-open' : 'file-1'
|
||||
return row.hasChildren && isExpanded(row.path) ? 'folder-open' : 'folder'
|
||||
}
|
||||
|
||||
const rowTitle = (row: FolderRow) =>
|
||||
row.kind === 'root' ? t('knowledgeBase.folderTree.rootRowTip') : row.path
|
||||
row.kind === 'root' ? t(rootRowTitleKey(props.recursive)) : row.path
|
||||
|
||||
const toggle = (path: string) => {
|
||||
const next = new Set(expanded.value)
|
||||
|
|
@ -207,11 +211,43 @@ watch(
|
|||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.kb-folder-tree__header-actions {
|
||||
.kb-folder-scope {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 2px;
|
||||
flex-shrink: 0;
|
||||
gap: 2px;
|
||||
margin-top: 2px;
|
||||
padding: 2px;
|
||||
border-radius: 6px;
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
}
|
||||
|
||||
.kb-folder-scope__btn {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
height: 22px;
|
||||
padding: 0 6px;
|
||||
border: 0;
|
||||
border-radius: 4px;
|
||||
background: transparent;
|
||||
color: var(--td-text-color-secondary);
|
||||
font-family: var(--app-font-family);
|
||||
font-size: 12px;
|
||||
line-height: 22px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.15s ease, color 0.15s ease;
|
||||
|
||||
&:hover:not(.active) {
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
|
||||
&.active {
|
||||
color: var(--td-brand-color);
|
||||
background: var(--td-bg-color-container);
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
}
|
||||
|
||||
.kb-folder-tree__icon-btn {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ import {
|
|||
folderRowCount,
|
||||
isFolderUpload,
|
||||
ROOT_FOLDER_PATH,
|
||||
rootRowLabelKey,
|
||||
rootRowTitleKey,
|
||||
} from './folderTree.ts'
|
||||
|
||||
const folders = [
|
||||
|
|
@ -149,3 +151,12 @@ test('row counts follow the recursive scope', () => {
|
|||
assert.equal(folderRowCount(handbook, true), 4)
|
||||
assert.equal(folderRowCount(handbook, false), 1)
|
||||
})
|
||||
|
||||
// Single-file uploads sit outside every folder, so a folder-only tree can give
|
||||
// them no node of their own. The root row is named after what it actually lists
|
||||
// so they are still findable, without inventing a second pseudo-folder row.
|
||||
test('the root row is named after what the current scope makes it list', () => {
|
||||
assert.equal(rootRowLabelKey(true), 'knowledgeBase.folderTree.rootRow')
|
||||
assert.equal(rootRowLabelKey(false), 'knowledgeBase.folderTree.rootRowDirect')
|
||||
assert.notEqual(rootRowTitleKey(true), rootRowTitleKey(false))
|
||||
})
|
||||
|
|
|
|||
|
|
@ -147,3 +147,24 @@ export function buildFolderRows(
|
|||
export function folderRowCount(row: FolderRow, recursive: boolean): number {
|
||||
return recursive ? row.totalCount : row.documentCount
|
||||
}
|
||||
|
||||
/**
|
||||
* i18n key for the root row's label. The root is the only row whose contents
|
||||
* change meaning with the scope: recursively it is the whole knowledge base,
|
||||
* directly it is exactly the documents that are not inside any folder — which
|
||||
* single-file uploads are, and which would otherwise have no visible home in a
|
||||
* tree that can only show folders. Naming the row after what it currently lists
|
||||
* keeps one mechanism instead of adding a second pseudo-folder for them.
|
||||
*/
|
||||
export function rootRowLabelKey(recursive: boolean): string {
|
||||
return recursive
|
||||
? 'knowledgeBase.folderTree.rootRow'
|
||||
: 'knowledgeBase.folderTree.rootRowDirect'
|
||||
}
|
||||
|
||||
/** i18n key for the root row's tooltip, following the same rule as its label. */
|
||||
export function rootRowTitleKey(recursive: boolean): string {
|
||||
return recursive
|
||||
? 'knowledgeBase.folderTree.rootRowTip'
|
||||
: 'knowledgeBase.folderTree.rootRowDirectTip'
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue