25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(sidebar): rank pinned tables first in sidebar search
高桥凉介a3fed878ca4e
diff --git a/apps/desktop/src/lib/__tests__/sidebar/sidebarSearchTree.pinned.spec.ts b/apps/desktop/src/lib/__tests__/sidebar/sidebarSearchTree.pinned.spec.tsnew file mode 100644index 0000000000..57b9ed0d89--- /dev/null+++ b/apps/desktop/src/lib/__tests__/sidebar/sidebarSearchTree.pinned.spec.ts@@ -0,0 +1,43 @@+import { describe, expect, it } from "vitest";+import { filterSidebarTree } from "@/lib/sidebar/sidebarSearchTree";+import type { TreeNode } from "@/types/database";++// 复现 issue #11386:「job」搜索命中多张表时,置顶表(sys_job_log)被按匹配+// 得分的重排压到了匹配度更高的兄弟节点(job_queue,前缀匹配)之后。+// store 已把置顶节点排在兄弟列表最前,搜索投影必须保持这一优先级。++/** 构造一张搜索结果里的表节点;pinned 为 true 时表示用户已置顶。 */+function table(id: string, label: string, pinned?: boolean): TreeNode {+ return { id, label, type: "table", connectionId: "conn", database: "app", schema: "public", ...(pinned ? { pinned: true } : {}) };+}++/** 构造承载表节点的 schema 节点(其 label 不参与「job」匹配,仅作为祖先路径保留)。 */+function schema(children: TreeNode[]): TreeNode {+ return { id: "conn:app:public", label: "public", type: "schema", connectionId: "conn", database: "app", isExpanded: true, children };+}++function childLabels(nodes: TreeNode[]): string[] {+ return (nodes[0]?.children ?? []).map((node) => node.label);+}++describe("sidebar search pinned ordering", () => {+ it("keeps a pinned table above a better-scoring unpinned sibling", () => {+ // job_queue 是前缀匹配(得分 90),sys_job_log 仅为词首匹配(80)但已置顶。+ const tree = [schema([table("t1", "job_queue"), table("t2", "sys_job_log", true), table("t3", "qrtz_job_details")])];++ expect(childLabels(filterSidebarTree(tree, "job", new Set()))).toEqual(["sys_job_log", "job_queue", "qrtz_job_details"]);+ });++ it("preserves the custom order of pinned siblings instead of re-ranking them by score", () => {+ // 两张置顶表即便得分不同,也必须保持 store 里用户拖拽出的置顶顺序。+ const tree = [schema([table("t2", "sys_job_log", true), table("t1", "job_queue", true), table("t3", "qrtz_job_details")])];++ expect(childLabels(filterSidebarTree(tree, "job", new Set()))).toEqual(["sys_job_log", "job_queue", "qrtz_job_details"]);+ });++ it("still ranks unpinned matches by match score", () => {+ const tree = [schema([table("t3", "qrtz_job_details"), table("t1", "job_queue")])];++ expect(childLabels(filterSidebarTree(tree, "job", new Set()))).toEqual(["job_queue", "qrtz_job_details"]);+ });+});diff --git a/apps/desktop/src/lib/sidebar/sidebarSearchTree.ts b/apps/desktop/src/lib/sidebar/sidebarSearchTree.tsindex 7be3588124..9fd2bea70c 100644--- a/apps/desktop/src/lib/sidebar/sidebarSearchTree.ts+++ b/apps/desktop/src/lib/sidebar/sidebarSearchTree.ts@@ -415,7 +415,16 @@ function filterSidebarTreeWithMatcher(nodes: TreeNode[], matchLabel: SidebarLabe}}- filteredNodes.sort((a, b) => b.score - a.score);+ // 置顶优先(issue #11386):store 已把置顶节点排在兄弟列表最前,但这里按匹配得分+ // 重排会把置顶节点压到匹配度更高的兄弟之后。改为置顶节点恒在前,且置顶节点之间+ // 保持 store 里用户自定义的置顶顺序(相等即稳定,不参与得分重排);未置顶节点仍+ // 按得分从高到低排序。+ filteredNodes.sort((a, b) => {+ const pinnedDiff = Number(b.node.pinned === true) - Number(a.node.pinned === true);+ if (pinnedDiff !== 0) return pinnedDiff;+ if (a.node.pinned === true) return 0;+ return b.score - a.score;+ });return filteredNodes.map((match) => match.node);}