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): reorder pinned tree nodes
t8y290c46d5450de
diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vueindex 899d93576c..04e5ffde3b 100644--- a/apps/desktop/src/components/grid/DataGrid.vue+++ b/apps/desktop/src/components/grid/DataGrid.vue@@ -3956,12 +3956,6 @@ const canvasEditingCell = computed(() => {return { rowIndex, visibleColIdx, actualColIdx: editing.col, rect };});-const canvasEditingCellIsNumeric = computed(() => {- const cell = canvasEditingCell.value;- if (!cell) return false;- return typeof displayItemAt(cell.rowIndex)?.data[cell.actualColIdx] === "number";-});-const canvasSingleSelectedCell = computed(() => {const range = selectedRange.value;if (!range || range.startRow !== range.endRow || range.startCol !== range.endCol) return null;diff --git a/apps/desktop/src/lib/__tests__/pinnedItems.spec.ts b/apps/desktop/src/lib/__tests__/pinnedItems.spec.tsnew file mode 100644index 0000000000..7ce3b57510--- /dev/null+++ b/apps/desktop/src/lib/__tests__/pinnedItems.spec.ts@@ -0,0 +1,56 @@+import { describe, expect, it } from "vitest";+import { updatePinnedTreeNodeInPlace } from "@/lib/pinnedItems";+import { buildTreeNodesFromLayout } from "@/lib/sidebarLayout";+import type { ConnectionConfig, SidebarLayout, TreeNode } from "@/types/database";++describe("sidebar pinned tree nodes", () => {+ it("reorders the pinned node within its parent", () => {+ const tree: TreeNode[] = [+ {+ id: "conn",+ label: "Connection",+ type: "connection",+ children: [+ { id: "conn:db:a", label: "A", type: "database" },+ { id: "conn:db:b", label: "B", type: "database" },+ ],+ },+ ];++ expect(updatePinnedTreeNodeInPlace(tree, "conn:db:b", true)).toBe("siblings");++ expect(tree[0].children?.map((node) => node.id)).toEqual(["conn:db:b", "conn:db:a"]);+ expect(tree[0].children?.[0].pinned).toBe(true);+ });++ it("reorders pinned root nodes in place", () => {+ const tree: TreeNode[] = [+ { id: "group-a", label: "A", type: "connection-group" },+ { id: "group-b", label: "B", type: "connection-group" },+ ];++ expect(updatePinnedTreeNodeInPlace(tree, "group-b", true)).toBe("root");++ expect(tree.map((node) => node.id)).toEqual(["group-b", "group-a"]);+ expect(tree[0].pinned).toBe(true);+ });++ it("applies pinned state to connection groups when rebuilding from layout", () => {+ const layout: SidebarLayout = {+ groups: [+ { id: "group-a", name: "A", collapsed: false },+ { id: "group-b", name: "B", collapsed: false },+ ],+ order: [+ { type: "group", id: "group-a", children: [] },+ { type: "group", id: "group-b", children: [] },+ ],+ };+ const connections: ConnectionConfig[] = [];++ const nodes = buildTreeNodesFromLayout(layout, connections, new Set(["group-b"]));++ expect(nodes.map((node) => node.id)).toEqual(["group-b", "group-a"]);+ expect(nodes[0].pinned).toBe(true);+ });+});diff --git a/apps/desktop/src/lib/pinnedItems.ts b/apps/desktop/src/lib/pinnedItems.tsindex f5d687e682..2e6dc6ac57 100644--- a/apps/desktop/src/lib/pinnedItems.ts+++ b/apps/desktop/src/lib/pinnedItems.ts@@ -1,5 +1,7 @@import type { TreeNode } from "@/types/database";+export type PinnedTreeNodeUpdateScope = "missing" | "root" | "siblings";+export function orderPinnedFirst<T>(items: T[], isPinned: (item: T) => boolean): T[] {const pinned: T[] = [];const unpinned: T[] = [];@@ -12,6 +14,34 @@ export function orderPinnedFirst<T>(items: T[], isPinned: (item: T) => boolean):return [...pinned, ...unpinned];}+function findTreeNodeLocation(nodes: TreeNode[], id: string, parent: TreeNode | null = null): { node: TreeNode; parent: TreeNode | null } | null {+ for (const node of nodes) {+ if (node.id === id) return { node, parent };+ if (node.children) {+ const found = findTreeNodeLocation(node.children, id, node);+ if (found) return found;+ }+ }+ return null;+}++export function updatePinnedTreeNodeInPlace(nodes: TreeNode[], id: string, pinned: boolean): PinnedTreeNodeUpdateScope {+ const location = findTreeNodeLocation(nodes, id);+ if (!location) return "missing";++ location.node.pinned = pinned;+ const siblings = location.parent?.children ?? nodes;+ const ordered = orderPinnedFirst(siblings, (node) => !!node.pinned);++ if (location.parent) {+ location.parent.children = ordered;+ return "siblings";+ }++ nodes.splice(0, nodes.length, ...ordered);+ return "root";+}+export function applyPinnedTreeNodeState(nodes: TreeNode[], pinnedIds: Set<string>): TreeNode[] {return orderPinnedFirst(nodes.map((node) => ({diff --git a/apps/desktop/src/lib/sidebarLayout.ts b/apps/desktop/src/lib/sidebarLayout.tsindex cd181f2e66..7ff7fe5c61 100644--- a/apps/desktop/src/lib/sidebarLayout.ts+++ b/apps/desktop/src/lib/sidebarLayout.ts@@ -118,6 +118,7 @@ export function buildTreeNodesFromLayout(layout: SidebarLayout, connections: Conid: group.id,label: group.name,type: "connection-group",+ pinned: pinnedIds.has(group.id),isExpanded: !group.collapsed,children: orderPinnedFirst(build(entryChildren(entry))),});diff --git a/apps/desktop/src/stores/connectionStore.ts b/apps/desktop/src/stores/connectionStore.tsindex 33e4b5d5f8..01d8f7cc83 100644--- a/apps/desktop/src/stores/connectionStore.ts+++ b/apps/desktop/src/stores/connectionStore.ts@@ -2,7 +2,7 @@ import { defineStore } from "pinia";import { uuid } from "@/lib/utils";import { ref, computed, watch } from "vue";import type { ColumnInfo, ConnectionConfig, ForeignKeyInfo, ObjectInfo, SidebarLayout, TreeNode } from "@/types/database";-import { applyPinnedTreeNodeState, orderPinnedFirst } from "@/lib/pinnedItems";+import { applyPinnedTreeNodeState, updatePinnedTreeNodeInPlace } from "@/lib/pinnedItems";import {reconcileLayout,buildTreeNodesFromLayout,@@ -561,18 +561,8 @@ export const useConnectionStore = defineStore("connection", () => {pinnedTreeNodeIds.value = next;persistPinnedTreeNodeIds();- const node = findNode(treeNodes.value, id);- if (node) node.pinned = next.has(id);-- const isConnectionOrGroup = !!findNode(treeNodes.value, id);- if (isConnectionOrGroup) {- rebuildTreeNodes();- } else {- const parent = findParentNode(treeNodes.value, id);- if (parent?.children) {- parent.children = orderPinnedFirst(parent.children, (child) => !!child.pinned);- }- }+ const scope = updatePinnedTreeNodeInPlace(treeNodes.value, id, next.has(id));+ if (scope === "root") rebuildTreeNodes();}async function addConnection(config: ConnectionConfig) {