feat(frontend): replace standalone search page with global command palette
Reworks search from a siloed /platform/knowledge-search page into a universal ⌘K palette plus natural, in-context entry points. Why the old page felt out of place: - "Search" was an action pinned next to entity routes (knowledge base, agent, organization), mixing noun- and verb-level navigation items. - Its two tabs (knowledge vs. chat messages) forced users to pick a mental model before they knew what they wanted. - It was also the only way to search at all — no global shortcut, no context-aware entry. What this replaces it with: - A new ⌘K/Ctrl+K command palette (GlobalCommandPalette.vue) mounted once in views/platform/index.vue. Results are grouped by type (files, messages, knowledge bases, agents, chat titles, commands) so users never need to pre-filter. Debounced, identity-keyed selection survives async arrivals (slow KB results no longer yank the highlight off the user's current row). ⌘1-9 jump shortcuts are rendered inline on each row for discoverability. - Sidebar gets a visible "Search" entry at the top — clicking it opens the palette (no route change), with a platform-aware kbd hint (⌘K on Mac, Ctrl K elsewhere). - KB detail page: opening ⌘K there auto-scopes the search to the current KB via a removable chip (Backspace in empty input also clears it); no separate embedded search bar needed. - The legacy route /platform/knowledge-search now redirects to the KB list with ?cmdk= set, so existing bookmarks still work. - KnowledgeBase.vue now handles both route-query changes and a window event (weknora:open-knowledge) for intra-KB navigation, fixing the silent-no-op when the palette jumps to a chunk in the already-open KB. Dropped: - frontend/src/views/knowledge/KnowledgeSearch.vue (1163 lines). - The exploratory SessionSearchBar mode-switching widget in the chat submenu; ⌘K covers its use cases without a two-mode UI. i18n: zh-CN / en-US / ko-KR / ru-RU updated together — new commandPalette.*, kb.*, and menu.search keys; obsolete session.search.* and menu.knowledgeSearch removed.
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
|
||||
const RECENT_KEY = 'weknora_cmdk_recent'
|
||||
const RECENT_LIMIT = 4
|
||||
|
||||
/**
|
||||
* Pinia store for the global command palette (⌘K / Ctrl+K).
|
||||
* The palette itself is rendered once in platform/index.vue.
|
||||
* Any code (router redirect, deep link, programmatic trigger) can open it
|
||||
* by calling openPalette(q).
|
||||
*/
|
||||
export const useCommandPaletteStore = defineStore('commandPalette', () => {
|
||||
const open = ref(false)
|
||||
const initialQuery = ref('')
|
||||
const recentQueries = ref<string[]>([])
|
||||
|
||||
const loadRecent = () => {
|
||||
try {
|
||||
const raw = localStorage.getItem(RECENT_KEY)
|
||||
recentQueries.value = raw ? JSON.parse(raw) : []
|
||||
} catch {
|
||||
recentQueries.value = []
|
||||
}
|
||||
}
|
||||
|
||||
const openPalette = (query = '') => {
|
||||
initialQuery.value = query
|
||||
open.value = true
|
||||
}
|
||||
|
||||
const closePalette = () => {
|
||||
open.value = false
|
||||
initialQuery.value = ''
|
||||
}
|
||||
|
||||
const pushRecent = (q: string) => {
|
||||
const trimmed = q.trim()
|
||||
if (!trimmed) return
|
||||
recentQueries.value = [
|
||||
trimmed,
|
||||
...recentQueries.value.filter(x => x !== trimmed),
|
||||
].slice(0, RECENT_LIMIT)
|
||||
try {
|
||||
localStorage.setItem(RECENT_KEY, JSON.stringify(recentQueries.value))
|
||||
} catch {
|
||||
/* ignore quota errors */
|
||||
}
|
||||
}
|
||||
|
||||
const clearRecent = () => {
|
||||
recentQueries.value = []
|
||||
try {
|
||||
localStorage.removeItem(RECENT_KEY)
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
}
|
||||
|
||||
// Load recent queries immediately on store creation.
|
||||
loadRecent()
|
||||
|
||||
return {
|
||||
open,
|
||||
initialQuery,
|
||||
recentQueries,
|
||||
openPalette,
|
||||
closePalette,
|
||||
pushRecent,
|
||||
clearRecent,
|
||||
loadRecent,
|
||||
}
|
||||
})
|
||||
@@ -19,7 +19,6 @@ const createMenuChildren = () => reactive<MenuChild[]>([])
|
||||
export const useMenuStore = defineStore('menuStore', () => {
|
||||
const menuArr = reactive<MenuItem[]>([
|
||||
{ title: '', titleKey: 'menu.knowledgeBase', icon: 'zhishiku', path: 'knowledge-bases' },
|
||||
{ title: '', titleKey: 'menu.knowledgeSearch', icon: 'search', path: 'knowledge-search' },
|
||||
{ title: '', titleKey: 'menu.agents', icon: 'agent', path: 'agents' },
|
||||
{ title: '', titleKey: 'menu.organizations', icon: 'organization', path: 'organizations' },
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user