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): preserve order on same-folder sorted drops
Melody Ruch7a707e77d8cc
diff --git a/apps/desktop/src/components/sidebar/ConnectionTree.vue b/apps/desktop/src/components/sidebar/ConnectionTree.vueindex 04f272a2c0..141c57faea 100644--- a/apps/desktop/src/components/sidebar/ConnectionTree.vue+++ b/apps/desktop/src/components/sidebar/ConnectionTree.vue@@ -2246,7 +2246,8 @@ defineExpose({ focusSearch, createNewGroup, collapseAllTreeNodes });<TreeItem:node="item.node":depth="item.depth"- :reorder-disabled="isRootListPartial || isConnectionListAlphabeticallySorted"+ :reorder-disabled="isRootListPartial"+ :move-to-group-only="isConnectionListAlphabeticallySorted":pending-rename="pendingRenameNodeId === item.node.id":highlighted="highlightedNodeId === item.node.id":comment-label-width="sidebarCommentLabelWidths.get(item.node.id)"@@ -2293,7 +2294,8 @@ defineExpose({ focusSearch, createNewGroup, collapseAllTreeNodes });:key="item.id":node="item.node":depth="item.depth"- :reorder-disabled="isRootListPartial || isConnectionListAlphabeticallySorted"+ :reorder-disabled="isRootListPartial"+ :move-to-group-only="isConnectionListAlphabeticallySorted":pending-rename="pendingRenameNodeId === item.node.id":highlighted="highlightedNodeId === item.id":comment-label-width="sidebarCommentLabelWidths.get(item.node.id)"diff --git a/apps/desktop/src/components/sidebar/TreeItem.vue b/apps/desktop/src/components/sidebar/TreeItem.vueindex 331039e0fd..8bbd9a78cc 100644--- a/apps/desktop/src/components/sidebar/TreeItem.vue+++ b/apps/desktop/src/components/sidebar/TreeItem.vue@@ -167,6 +167,7 @@ const props = defineProps<{node: TreeNode;depth: number;reorderDisabled?: boolean;+ moveToGroupOnly?: boolean;referenceDragDisabled?: boolean;pendingRename?: boolean;highlighted?: boolean;@@ -1023,7 +1024,7 @@ const {// together; otherwise just the grabbed one (issue #681).const selected = connectionStore.selectedTreeNodeIds;const draggedIds = selected.length > 1 && selected.includes(draggedId) ? [...selected] : [draggedId];- connectionStore.reorderSidebarEntries(draggedIds, targetId, position);+ connectionStore.reorderSidebarEntries(draggedIds, targetId, position, { preserveSameGroupOrder: props.moveToGroupOnly });});const canReorderTreeNode = computed(() => {@@ -1066,6 +1067,12 @@ function updateTreeDragTarget(event: MouseEvent) {return;}updateTarget(event, activeNode.value.id, activeNode.value.type);+ // While the list is display-sorted, the underlying manual order used for+ // before/after positioning is invisible, so only moving into a different+ // group (a display-order-independent operation) is a coherent drop.+ if (props.moveToGroupOnly && dragState.dropPosition !== "inside") {+ clearTarget(activeNode.value.id);+ }}function clearTreeDragTarget() {diff --git a/apps/desktop/src/lib/__tests__/sidebar/sidebarFilterGuards.spec.ts b/apps/desktop/src/lib/__tests__/sidebar/sidebarFilterGuards.spec.tsindex db67d10cb1..d9b048c29f 100644--- a/apps/desktop/src/lib/__tests__/sidebar/sidebarFilterGuards.spec.ts+++ b/apps/desktop/src/lib/__tests__/sidebar/sidebarFilterGuards.spec.ts@@ -25,7 +25,11 @@ describe("sidebar filter guards", () => {expect(source).toContain("sidebarTableSearchEnabled && !isTreeSearchFiltering.value");expect(source).toContain("!useVirtualTree.value || isTreeSearchFiltering.value");expect(source.match(/if \(isRootListPartial\.value\)/g)).toHaveLength(2);- expect(source.match(/:reorder-disabled="isRootListPartial \|\| isConnectionListAlphabeticallySorted"/g)).toHaveLength(2);+ // Alphabetical sort only suppresses before/after position reordering (the manual+ // order it would act on is invisible while sorted); moving a connection into a+ // different group stays available so drag stays usable while sorted (#6669).+ expect(source.match(/:reorder-disabled="isRootListPartial"/g)).toHaveLength(2);+ expect(source.match(/:move-to-group-only="isConnectionListAlphabeticallySorted"/g)).toHaveLength(2);expect(source).not.toContain("isFiltering");});});diff --git a/apps/desktop/src/lib/__tests__/sidebar/sidebarLayout.spec.ts b/apps/desktop/src/lib/__tests__/sidebar/sidebarLayout.spec.tsindex f4af733e72..be0c6f9abf 100644--- a/apps/desktop/src/lib/__tests__/sidebar/sidebarLayout.spec.ts+++ b/apps/desktop/src/lib/__tests__/sidebar/sidebarLayout.spec.ts@@ -1,5 +1,5 @@import { describe, expect, it } from "vitest";-import { connectionIdsInGroups, deleteGroups, findConnectionGroupPath } from "@/lib/sidebar/sidebarLayout";+import { connectionIdsInGroups, deleteGroups, findConnectionGroupPath, reorderEntries } from "@/lib/sidebar/sidebarLayout";import type { SidebarLayout } from "@/types/database";const layout: SidebarLayout = {@@ -24,6 +24,34 @@ const layout: SidebarLayout = {],};+const dragLayout: SidebarLayout = {+ groups: [+ { id: "alpha", name: "Alpha", collapsed: false },+ { id: "beta", name: "Beta", collapsed: false },+ { id: "nested", name: "Nested", collapsed: false },+ ],+ order: [+ {+ type: "group",+ id: "alpha",+ children: [+ { type: "connection", id: "alpha-first" },+ {+ type: "group",+ id: "nested",+ children: [{ type: "connection", id: "nested-connection" }],+ },+ { type: "connection", id: "alpha-second" },+ ],+ },+ {+ type: "group",+ id: "beta",+ children: [{ type: "connection", id: "beta-connection" }],+ },+ ],+};+describe("findConnectionGroupPath", () => {it("returns every containing group from root to leaf", () => {expect(findConnectionGroupPath(layout, "nested")).toEqual(["Project", "Staging"]);@@ -82,3 +110,96 @@ describe("connection group deletion", () => {});});});++describe("sorted sidebar move-only drops", () => {+ const preserveSameGroupOrder = { preserveSameGroupOrder: true };++ it("keeps a same-folder connection drop from rewriting hidden manual order", () => {+ expect(reorderEntries(dragLayout, ["alpha-first"], "alpha", "inside", preserveSameGroupOrder)).toBe(dragLayout);+ });++ it("keeps a same-folder multi-selection drop from rewriting hidden manual order", () => {+ expect(reorderEntries(dragLayout, ["alpha-first", "alpha-second"], "alpha", "inside", preserveSameGroupOrder)).toBe(dragLayout);+ });++ it("keeps a same-folder group drop from rewriting hidden manual order", () => {+ expect(reorderEntries(dragLayout, ["nested"], "alpha", "inside", preserveSameGroupOrder)).toBe(dragLayout);+ });++ it("moves cross-folder entries while preserving selected entries already in the target folder", () => {+ expect(reorderEntries(dragLayout, ["alpha-first", "beta-connection"], "alpha", "inside", preserveSameGroupOrder)).toEqual({+ ...dragLayout,+ order: [+ {+ type: "group",+ id: "alpha",+ children: [+ { type: "connection", id: "alpha-first" },+ {+ type: "group",+ id: "nested",+ children: [{ type: "connection", id: "nested-connection" }],+ },+ { type: "connection", id: "alpha-second" },+ { type: "connection", id: "beta-connection" },+ ],+ },+ { type: "group", id: "beta", children: [] },+ ],+ });+ });++ it("preserves ordinary same-folder inside reordering outside move-only mode", () => {+ expect(reorderEntries(dragLayout, ["alpha-first"], "alpha", "inside")).toEqual({+ ...dragLayout,+ order: [+ {+ type: "group",+ id: "alpha",+ children: [+ {+ type: "group",+ id: "nested",+ children: [{ type: "connection", id: "nested-connection" }],+ },+ { type: "connection", id: "alpha-second" },+ { type: "connection", id: "alpha-first" },+ ],+ },+ {+ type: "group",+ id: "beta",+ children: [{ type: "connection", id: "beta-connection" }],+ },+ ],+ });+ });++ it("still moves a group across folders in move-only mode", () => {+ expect(reorderEntries(dragLayout, ["nested"], "beta", "inside", preserveSameGroupOrder)).toEqual({+ ...dragLayout,+ order: [+ {+ type: "group",+ id: "alpha",+ children: [+ { type: "connection", id: "alpha-first" },+ { type: "connection", id: "alpha-second" },+ ],+ },+ {+ type: "group",+ id: "beta",+ children: [+ { type: "connection", id: "beta-connection" },+ {+ type: "group",+ id: "nested",+ children: [{ type: "connection", id: "nested-connection" }],+ },+ ],+ },+ ],+ });+ });+});diff --git a/apps/desktop/src/lib/sidebar/sidebarLayout.ts b/apps/desktop/src/lib/sidebar/sidebarLayout.tsindex 0a10b03ff0..1217ac8b47 100644--- a/apps/desktop/src/lib/sidebar/sidebarLayout.ts+++ b/apps/desktop/src/lib/sidebar/sidebarLayout.ts@@ -354,6 +354,20 @@ export function moveConnectionToGroup(layout: SidebarLayout, connectionId: strinexport type DropPosition = "before" | "after" | "inside";+export interface ReorderEntriesOptions {+ preserveSameGroupOrder?: boolean;+}++function findEntryParentGroupId(entries: SidebarOrderEntry[], entryId: string, parentGroupId: string | null = null): string | null | undefined {+ for (const entry of entries) {+ if (entry.id === entryId) return parentGroupId;+ if (entry.type !== "group") continue;+ const found = findEntryParentGroupId(entryChildren(entry), entryId, entry.id);+ if (found !== undefined) return found;+ }+ return undefined;+}+export function reorderEntry(layout: SidebarLayout, draggedId: string, targetId: string, position: DropPosition): SidebarLayout {if (draggedId === targetId) return layout;@@ -387,6 +401,16 @@ export function reorderEntry(layout: SidebarLayout, draggedId: string, targetId:return { ...layout, order };}+export function reorderEntries(layout: SidebarLayout, draggedIds: string[], targetId: string, position: DropPosition, options: ReorderEntriesOptions = {}): SidebarLayout {+ let nextLayout = layout;+ for (const draggedId of draggedIds) {+ if (draggedId === targetId) continue;+ if (position === "inside" && options.preserveSameGroupOrder && findEntryParentGroupId(nextLayout.order, draggedId) === targetId) continue;+ nextLayout = reorderEntry(nextLayout, draggedId, targetId, position);+ }+ return nextLayout;+}+export function createGroup(layout: SidebarLayout, name: string, parentGroupId?: string | null): { layout: SidebarLayout; groupId: string } {const groupId = uuid();const group: ConnectionGroup = { id: groupId, name, collapsed: false };diff --git a/apps/desktop/src/stores/connectionStore.ts b/apps/desktop/src/stores/connectionStore.tsindex 7100acb859..dc18c4038d 100644--- a/apps/desktop/src/stores/connectionStore.ts+++ b/apps/desktop/src/stores/connectionStore.ts@@ -57,9 +57,11 @@ import {remapSidebarLayoutConnectionIds,mergeSidebarLayout,reorderEntry as reorderEntryOp,+ reorderEntries as reorderEntriesOp,buildConnectionGroupPathMap,connectionSidebarSearchAliases,type DropPosition,+ type ReorderEntriesOptions,} from "@/lib/sidebar/sidebarLayout";import type { SqlCompletionColumn, SqlCompletionForeignKey, SqlCompletionObject, SqlCompletionTable } from "@/lib/sql/sqlCompletion";import { mergeSqlObjectNavigationType, sqlObjectNavigationTypeFromTableType } from "@/lib/sql/sqlNavigation";@@ -8293,17 +8295,9 @@ export const useConnectionStore = defineStore("connection", () => {reorderSidebarEntry(draggedId: string, targetId: string, position: DropPosition) {updateLayoutAndRebuild(reorderEntryOp(sidebarLayout.value, draggedId, targetId, position));},- reorderSidebarEntries(draggedIds: string[], targetId: string, position: DropPosition) {- // Apply each dragged entry in turn so a multi-selection moves together,- // not just the single grabbed row (issue #681).- let layout = sidebarLayout.value;- let changed = false;- for (const id of draggedIds) {- if (id === targetId) continue;- layout = reorderEntryOp(layout, id, targetId, position);- changed = true;- }- if (changed) updateLayoutAndRebuild(layout);+ reorderSidebarEntries(draggedIds: string[], targetId: string, position: DropPosition, options?: ReorderEntriesOptions) {+ const layout = reorderEntriesOp(sidebarLayout.value, draggedIds, targetId, position, options);+ if (layout !== sidebarLayout.value) updateLayoutAndRebuild(layout);},};});