Skip to content

Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.

feat(frontend): introduce KBSwitcherDropdown component for improved knowledge base selection

wizardchen91e4fe8b6b02
diff --git a/frontend/src/components/KBSwitcherDropdown.vue b/frontend/src/components/KBSwitcherDropdown.vue
new file mode 100644
index 000000000..f06ecd48d
--- /dev/null
+++ b/frontend/src/components/KBSwitcherDropdown.vue
@@ -0,0 +1,160 @@
+<template>
+ <t-popup
+ trigger="click"
+ placement="bottom-left"
+ :overlay-style="{ padding: 0 }"
+ :overlay-inner-style="{ padding: 0 }"
+ >
+ <template #content>
+ <div class="kb-switcher-card">
+ <div class="kb-switcher-list">
+ <button
+ v-for="item in sortedList"
+ :key="item.id"
+ type="button"
+ class="kb-switcher-row"
+ :class="{ active: item.id === currentKbId }"
+ @click="handleSelect(item.id)"
+ >
+ <t-icon
+ :name="iconFor(item.type)"
+ class="kb-switcher-row-icon"
+ size="16px"
+ />
+ <span class="kb-switcher-row-name" :title="item.name">{{ item.name }}</span>
+ <t-icon
+ v-if="item.id === currentKbId"
+ name="check"
+ class="kb-switcher-row-check"
+ size="14px"
+ />
+ </button>
+ <div v-if="!sortedList.length" class="kb-switcher-empty">
+ {{ t('common.noData') }}
+ </div>
+ </div>
+ </div>
+ </template>
+ <slot />
+ </t-popup>
+</template>
+
+<script setup lang="ts">
+import { computed } from 'vue'
+import { useI18n } from 'vue-i18n'
+
+interface KBEntry {
+ id: string
+ name: string
+ type?: string
+}
+
+const props = defineProps<{
+ kbList: KBEntry[]
+ currentKbId: string
+}>()
+
+const emit = defineEmits<{
+ (e: 'select', kbId: string): void
+}>()
+
+const { t } = useI18n()
+
+// Sort the list with the current KB pinned to the top so users always
+// see "where they are" without scrolling. The rest preserves the
+// caller's order (typically "mine first, then shared"); we don't
+// re-sort alphabetically because that loses the recency / share-source
+// signal embedded in the input order.
+const sortedList = computed<KBEntry[]>(() => {
+ const all = props.kbList || []
+ const current = all.find((kb) => kb.id === props.currentKbId)
+ if (!current) return all
+ return [current, ...all.filter((kb) => kb.id !== props.currentKbId)]
+})
+
+const iconFor = (type?: string): string => {
+ if (type === 'faq') return 'chat-bubble-help'
+ return 'folder'
+}
+
+const handleSelect = (id: string): void => {
+ if (id === props.currentKbId) return
+ emit('select', id)
+}
+</script>
+
+<style scoped lang="less">
+.kb-switcher-card {
+ min-width: 220px;
+ max-width: 320px;
+ /* Mirror the info popover's cap so both header surfaces stay inside
+ the viewport on shorter laptops. */
+ max-height: min(60vh, 420px);
+ display: flex;
+ flex-direction: column;
+ padding: 6px;
+ overflow: hidden;
+}
+
+.kb-switcher-list {
+ flex: 1 1 auto;
+ overflow-y: auto;
+ display: flex;
+ flex-direction: column;
+ gap: 1px;
+}
+
+.kb-switcher-row {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ padding: 6px 10px;
+ border: none;
+ border-radius: 6px;
+ background: transparent;
+ color: var(--td-text-color-primary);
+ font-size: 13px;
+ line-height: 1.4;
+ cursor: pointer;
+ transition: background 0.15s ease, color 0.15s ease;
+ text-align: left;
+
+ &:hover {
+ background: var(--td-bg-color-secondarycontainer);
+ }
+
+ &.active {
+ background: var(--td-brand-color-light, rgba(0, 82, 217, 0.08));
+ color: var(--td-brand-color);
+ font-weight: 500;
+ }
+}
+
+.kb-switcher-row-icon {
+ flex: 0 0 auto;
+ color: var(--td-text-color-placeholder);
+
+ .kb-switcher-row.active & {
+ color: var(--td-brand-color);
+ }
+}
+
+.kb-switcher-row-name {
+ flex: 1 1 auto;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+.kb-switcher-row-check {
+ flex: 0 0 auto;
+ color: var(--td-brand-color);
+}
+
+.kb-switcher-empty {
+ padding: 16px;
+ text-align: center;
+ font-size: 12px;
+ color: var(--td-text-color-placeholder);
+}
+</style>
diff --git a/frontend/src/views/knowledge/KnowledgeBase.vue b/frontend/src/views/knowledge/KnowledgeBase.vue
index dc30fd784..20ccede9b 100644
--- a/frontend/src/views/knowledge/KnowledgeBase.vue
+++ b/frontend/src/views/knowledge/KnowledgeBase.vue
@@ -6,6 +6,7 @@ import useKnowledgeBase from '@/hooks/useKnowledgeBase';
import { useRoute, useRouter } from 'vue-router';
import EmptyKnowledge from '@/components/empty-knowledge.vue';
import KBInfoPopover from '@/components/KBInfoPopover.vue';
+import KBSwitcherDropdown from '@/components/KBSwitcherDropdown.vue';
import { getSessionsList, createSessions, generateSessionsTitle } from "@/api/chat/index";
import { useMenuStore } from '@/stores/menu';
import { useUIStore } from '@/stores/ui';
@@ -1674,14 +1675,6 @@ const handleNavigateToCurrentKB = () => {
router.push(`/platform/knowledge-bases/${kbId.value}`);
};
-const knowledgeDropdownOptions = computed(() =>
- knowledgeList.value.map((item) => ({
- content: item.name,
- value: item.id,
- prefixIcon: () => h(TIcon, { name: item.type === 'faq' ? 'chat-bubble-help' : 'folder', size: '16px' }),
- }))
-);
-
const handleKnowledgeDropdownSelect = (data: { value: string }) => {
if (!data?.value) return;
if (data.value === kbId.value) return;
@@ -1979,10 +1972,13 @@ async function createNewSession(value: string): Promise<void> {
{{ $t('menu.knowledgeBase') }}
</button>
<t-icon name="chevron-right" class="breadcrumb-separator" />
- <t-dropdown v-if="knowledgeDropdownOptions.length" :options="knowledgeDropdownOptions" trigger="click"
- placement="bottom-left" @click="handleKnowledgeDropdownSelect">
- <button type="button" class="breadcrumb-link dropdown" :disabled="!kbId"
- @click.stop="handleNavigateToCurrentKB">
+ <KBSwitcherDropdown
+ v-if="knowledgeList.length"
+ :kb-list="knowledgeList"
+ :current-kb-id="kbId"
+ @select="(id) => handleKnowledgeDropdownSelect({ value: id })"
+ >
+ <button type="button" class="breadcrumb-link dropdown" :disabled="!kbId">
<template v-if="!kbInfo">
<t-skeleton animation="gradient" :row-col="[{ width: '120px', height: '20px' }]" />
</template>
@@ -1991,7 +1987,7 @@ async function createNewSession(value: string): Promise<void> {
<t-icon name="chevron-down" />
</template>
</button>
- </t-dropdown>
+ </KBSwitcherDropdown>
<button v-else type="button" class="breadcrumb-link" :disabled="!kbId" @click="handleNavigateToCurrentKB">
<template v-if="!kbInfo">
<t-skeleton animation="gradient" :row-col="[{ width: '120px', height: '20px' }]" />
diff --git a/frontend/src/views/knowledge/components/FAQEntryManager.vue b/frontend/src/views/knowledge/components/FAQEntryManager.vue
index 8e83707f8..bed74437f 100644
--- a/frontend/src/views/knowledge/components/FAQEntryManager.vue
+++ b/frontend/src/views/knowledge/components/FAQEntryManager.vue
@@ -10,10 +10,13 @@
{{ $t('menu.knowledgeBase') }}
</button>
<t-icon name="chevron-right" class="breadcrumb-separator" />
- <t-dropdown v-if="knowledgeDropdownOptions.length" :options="knowledgeDropdownOptions" trigger="click"
- placement="bottom-left" @click="handleKnowledgeDropdownSelect">
- <button type="button" class="breadcrumb-link dropdown" :disabled="!props.kbId"
- @click.stop="handleNavigateToCurrentKB">
+ <KBSwitcherDropdown
+ v-if="knowledgeList.length"
+ :kb-list="knowledgeList"
+ :current-kb-id="props.kbId"
+ @select="(id) => handleKnowledgeDropdownSelect({ value: id })"
+ >
+ <button type="button" class="breadcrumb-link dropdown" :disabled="!props.kbId">
<template v-if="!kbInfo">
<t-skeleton animation="gradient" :row-col="[{ width: '120px', height: '20px' }]" />
</template>
@@ -22,7 +25,7 @@
<t-icon name="chevron-down" />
</template>
</button>
- </t-dropdown>
+ </KBSwitcherDropdown>
<button v-else type="button" class="breadcrumb-link" :disabled="!props.kbId"
@click="handleNavigateToCurrentKB">
<template v-if="!kbInfo">
@@ -944,6 +947,7 @@ import * as XLSX from 'xlsx'
import Papa from 'papaparse'
import FAQTagTooltip from '@/components/FAQTagTooltip.vue'
import KBInfoPopover from '@/components/KBInfoPopover.vue'
+import KBSwitcherDropdown from '@/components/KBSwitcherDropdown.vue'
import { useUIStore } from '@/stores/ui'
interface FAQEntry {
@@ -1150,14 +1154,6 @@ const filteredTags = computed(() => {
const kbInfo = ref<any>(null)
const knowledgeList = ref<Array<{ id: string; name: string; type?: string }>>([])
-const knowledgeDropdownOptions = computed(() =>
- knowledgeList.value
- .map((item) => ({
- content: item.name,
- value: item.id,
- prefixIcon: () => h(TIcon, { name: item.type === 'document' ? 'folder' : 'chat-bubble-help', size: '16px' }),
- })),
-)
const loadKnowledgeInfo = async (kbId: string) => {
if (!kbId) {