feat(frontend): introduce KBSwitcherDropdown component for improved knowledge base selection
Added a new KBSwitcherDropdown component to enhance the user experience when selecting knowledge bases. This component displays a list of knowledge bases with the current selection highlighted, allowing users to easily switch between them. Integrated the dropdown into both KnowledgeBase.vue and FAQEntryManager.vue, replacing the previous dropdown implementation for a more streamlined and consistent UI. The new component supports dynamic updates and maintains the order of knowledge bases while ensuring the current selection is always visible at the top.
This commit is contained in:
@@ -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' }]" />
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user