Skip to content

armgit / dbx

Public Imported from GitHub
0

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。

fix(ui): update drop position on mousemove and enforce pinned grouping in tab reorder

dqnb028b0aea2b9
diff --git a/apps/desktop/src/components/layout/AppTabBar.vue b/apps/desktop/src/components/layout/AppTabBar.vue
index 74ccddcf13..b8f4e261d6 100644
--- a/apps/desktop/src/components/layout/AppTabBar.vue
+++ b/apps/desktop/src/components/layout/AppTabBar.vue
@@ -333,6 +333,7 @@ const tabOverflowControlClass = computed(() =>
@mousedown.middle.prevent="queryStore.closeTab(tab.id)"
@mousedown="tabDrag.startDrag($event, tab.id)"
@mouseenter="tabDrag.updateTarget($event, tab.id)"
+ @mousemove="tabDrag.updateTarget($event, tab.id)"
@mouseleave="tabDrag.clearTarget(tab.id)"
>
<span class="shrink-0" :class="tabIconClass(tab)">
diff --git a/apps/desktop/src/stores/queryStore.ts b/apps/desktop/src/stores/queryStore.ts
index 37a1b5d7fc..3ead2eff1e 100644
--- a/apps/desktop/src/stores/queryStore.ts
+++ b/apps/desktop/src/stores/queryStore.ts
@@ -477,6 +477,7 @@ export const useQueryStore = defineStore("query", () => {
const [tab] = tabs.value.splice(fromIdx, 1);
const newToIdx = tabs.value.findIndex((t) => t.id === targetId);
tabs.value.splice(newToIdx + (position === "after" ? 1 : 0), 0, tab);
+ tabs.value = orderPinnedFirst(tabs.value, (item) => !!item.pinned);
}
function updateDatabase(id: string, database: string) {
diff --git a/packages/app-tests/queryStore.test.ts b/packages/app-tests/queryStore.test.ts
index 32ef4e909c..b8e7bffa93 100644
--- a/packages/app-tests/queryStore.test.ts
+++ b/packages/app-tests/queryStore.test.ts
@@ -1135,3 +1135,109 @@ test("new table structure tabs can open multiple drafts while existing tables st
restoreStorage();
}
});
+
+test("reorderTab keeps pinned tabs before unpinned tabs after reorder", () => {
+ setActivePinia(createPinia());
+ const store = useQueryStore();
+
+ const tabA = store.createTab("conn-1", "db", "A", "query");
+ const tabB = store.createTab("conn-1", "db", "B", "query");
+ const tabC = store.createTab("conn-1", "db", "C", "query");
+ const tabD = store.createTab("conn-1", "db", "D", "query");
+
+ store.tabs[0].pinned = false;
+ store.tabs[1].pinned = true;
+ store.tabs[2].pinned = false;
+ store.tabs[3].pinned = true;
+
+ // Force store to apply pinned ordering
+ store.togglePinnedTab(tabB);
+ store.togglePinnedTab(tabB);
+ // Now tabs: D(b), B(b), A, C
+
+ // Try dragging unpinned tab A before pinned tab B
+ store.reorderTab(tabA, tabB, "before");
+ const idsAfter = store.tabs.map((t) => t.id);
+ const pinnedIndices = store.tabs.map((t, i) => ({ pinned: t.pinned, i })).filter((t) => t.pinned);
+ const unpinnedIndices = store.tabs.map((t, i) => ({ pinned: t.pinned, i })).filter((t) => !t.pinned);
+
+ // All pinned tabs should come before any unpinned tab
+ assert.equal(Math.max(...pinnedIndices.map((t) => t.i)) < Math.min(...unpinnedIndices.map((t) => t.i)), true);
+});
+
+test("reorderTab preserves relative order within pinned group", () => {
+ setActivePinia(createPinia());
+ const store = useQueryStore();
+
+ const tabA = store.createTab("conn-1", "db", "A", "query");
+ const tabB = store.createTab("conn-1", "db", "B", "query");
+ const tabC = store.createTab("conn-1", "db", "C", "query");
+ const tabD = store.createTab("conn-1", "db", "D", "query");
+ const tabE = store.createTab("conn-1", "db", "E", "query");
+
+ // Pin A, B, C — leave D, E unpinned
+ store.togglePinnedTab(tabA);
+ // toggle so orderPinnedFirst runs: [A, B, C, D, E]
+ store.togglePinnedTab(tabB);
+ // [A, B, C, D, E]
+ assert.equal(store.tabs.filter((t) => t.pinned).length, 2);
+
+ store.togglePinnedTab(tabC);
+ // pinned = [A, B, C], unpinned = [D, E]
+ assert.equal(store.tabs.filter((t) => t.pinned).length, 3);
+
+ // Now: A, B, C (pinned), D, E (unpinned)
+ // Drag C before A (within pinned group)
+ store.reorderTab(tabC, tabA, "before");
+ // After orderPinnedFirst: C, A, B, D, E
+ const ids = store.tabs.map((t) => t.id);
+ assert.equal(ids[0], tabC, "C should be first pinned tab");
+ assert.equal(ids[1], tabA, "A should be second pinned tab");
+ assert.equal(ids[2], tabB, "B should be third pinned tab");
+ assert.equal(ids[3], tabD, "D should be first unpinned");
+ assert.equal(ids[4], tabE, "E should be second unpinned");
+});
+
+test("reorderTab preserves relative order within unpinned group", () => {
+ setActivePinia(createPinia());
+ const store = useQueryStore();
+
+ const tabA = store.createTab("conn-1", "db", "A", "query");
+ const tabB = store.createTab("conn-1", "db", "B", "query");
+ const tabC = store.createTab("conn-1", "db", "C", "query");
+ const tabD = store.createTab("conn-1", "db", "D", "query");
+
+ store.tabs[0].pinned = true;
+ store.tabs[1].pinned = false;
+ store.tabs[2].pinned = false;
+ store.tabs[3].pinned = false;
+
+ store.togglePinnedTab(tabA);
+ store.togglePinnedTab(tabA);
+
+ // Now tabs: A(pinned), B, C, D(unpinned)
+ // Drag D before B
+ store.reorderTab(tabD, tabB, "before");
+ // After orderPinnedFirst: A, D, B, C
+ const ids = store.tabs.map((t) => t.id);
+ assert.equal(ids[0], tabA, "A should stay pinned");
+ assert.equal(ids[1], tabD, "D should be first unpinned");
+ assert.equal(ids[2], tabB, "B should be second unpinned");
+ assert.equal(ids[3], tabC, "C should be last unpinned");
+});
+
+test("reorderTab with after position places tab correctly", () => {
+ setActivePinia(createPinia());
+ const store = useQueryStore();
+
+ const tabA = store.createTab("conn-1", "db", "A", "query");
+ const tabB = store.createTab("conn-1", "db", "B", "query");
+ const tabC = store.createTab("conn-1", "db", "C", "query");
+
+ // Drag A after C
+ store.reorderTab(tabA, tabC, "after");
+ assert.deepEqual(
+ store.tabs.map((t) => t.id),
+ [tabB, tabC, tabA],
+ );
+});