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(tabs): restore close-right tab action

guoyongchangeed0a26b6f39
diff --git a/apps/desktop/src/components/layout/AppTabBar.vue b/apps/desktop/src/components/layout/AppTabBar.vue
index 8c8a9f2f03..851c41e293 100644
--- a/apps/desktop/src/components/layout/AppTabBar.vue
+++ b/apps/desktop/src/components/layout/AppTabBar.vue
@@ -184,6 +184,36 @@ function closeOtherRegularTabsFromTab(tab: QueryTab) {
closeSpecialRegularSurfaces();
}
+function tabsToRightInGroup(tab: QueryTab) {
+ const groupedTabs = tab.pinned ? fixedTabs.value : regularTabs.value;
+ const targetIndex = groupedTabs.findIndex((item) => item.id === tab.id);
+ return targetIndex < 0 ? [] : groupedTabs.slice(targetIndex + 1);
+}
+
+function hasTabsToRight(tab: QueryTab) {
+ return tabsToRightInGroup(tab).length > 0 || (!tab.pinned && (!!props.settingsPageOpen || !!props.driverStoreOpen));
+}
+
+function closeTabsToRightFromTab(tab: QueryTab) {
+ const shouldActivateTarget = !tab.pinned && (!!props.settingsPageActive || !!props.driverStoreActive);
+ queryStore.closeRightTabs(tab.id, () => {
+ if (tab.pinned) return;
+ closeSpecialRegularSurfaces();
+ if (shouldActivateTarget) activateTab(tab.id);
+ });
+}
+
+function hasSpecialRegularSurfaceToRight(surface: SpecialRegularSurface) {
+ return surface === "settings" && !!props.driverStoreOpen;
+}
+
+function closeSpecialRegularSurfacesToRight(surface: SpecialRegularSurface) {
+ if (surface !== "settings" || !props.driverStoreOpen) return;
+ const shouldActivateSettings = !!props.driverStoreActive;
+ emit("close-driver-store");
+ if (shouldActivateSettings) emit("activate-settings-page");
+}
+
function closeAllRegularSurfaces() {
queryStore.closeRegularTabs();
closeSpecialRegularSurfaces();
@@ -234,6 +264,12 @@ function getSpecialRegularTabMenuItems(surface: SpecialRegularSurface): ContextM
icon: X,
shortcut: settingsStore.editorSettings.shortcuts.closeOtherTabs,
},
+ {
+ label: t("contextMenu.closeRightTabs"),
+ action: () => closeSpecialRegularSurfacesToRight(surface),
+ disabled: !hasSpecialRegularSurfaceToRight(surface),
+ icon: X,
+ },
{
label: closeAllLabel,
action: closeAllRegularSurfaces,
@@ -297,6 +333,12 @@ function getTabMenuItems(tab: QueryTab): ContextMenuItem[] {
icon: X,
shortcut: settingsStore.editorSettings.shortcuts.closeOtherTabs,
},
+ {
+ label: t("contextMenu.closeRightTabs"),
+ action: () => closeTabsToRightFromTab(tab),
+ disabled: !hasTabsToRight(tab),
+ icon: X,
+ },
{
label: closeAllLabel,
action: closeAllAction,
diff --git a/apps/desktop/src/components/layout/__tests__/AppTabBar.spec.ts b/apps/desktop/src/components/layout/__tests__/AppTabBar.spec.ts
index 5f99757700..163b764e8d 100644
--- a/apps/desktop/src/components/layout/__tests__/AppTabBar.spec.ts
+++ b/apps/desktop/src/components/layout/__tests__/AppTabBar.spec.ts
@@ -35,3 +35,32 @@ describe("AppTabBar objects presentation", () => {
expect(tabBarSource.match(/tabMenuIcon\(tab\).*tabIconClass\(tab\)/g)).toHaveLength(2);
});
});
+
+describe("AppTabBar right-side close action", () => {
+ it("places the action after close-other and disables it when the target has no tabs to its right", () => {
+ expect(tabBarSource).toContain('label: t("contextMenu.closeRightTabs")');
+ expect(tabBarSource).toContain("action: () => closeTabsToRightFromTab(tab)");
+ expect(tabBarSource).toContain("disabled: !hasTabsToRight(tab)");
+
+ const closeOtherPositions = [...tabBarSource.matchAll(/label: closeOtherLabel,/g)].map((match) => match.index);
+ const closeRightPositions = [...tabBarSource.matchAll(/label: t\("contextMenu\.closeRightTabs"\),/g)].map((match) => match.index);
+ const closeAllPositions = [...tabBarSource.matchAll(/label: closeAllLabel,/g)].map((match) => match.index);
+ expect(closeOtherPositions).toHaveLength(2);
+ expect(closeRightPositions).toHaveLength(2);
+ expect(closeAllPositions).toHaveLength(2);
+ closeRightPositions.forEach((position, index) => {
+ expect(position).toBeGreaterThan(closeOtherPositions[index]);
+ expect(position).toBeLessThan(closeAllPositions[index]);
+ });
+ });
+
+ it("waits for query tab confirmation before closing special surfaces", () => {
+ expect(tabBarSource).toMatch(/queryStore\.closeRightTabs\(tab\.id, \(\) => \{[\s\S]*closeSpecialRegularSurfaces\(\);/);
+ expect(tabBarSource).toContain("if (shouldActivateTarget) activateTab(tab.id)");
+ });
+
+ it("reactivates settings after closing an active driver store to its right", () => {
+ expect(tabBarSource).toContain("const shouldActivateSettings = !!props.driverStoreActive");
+ expect(tabBarSource).toMatch(/emit\("close-driver-store"\);\s*if \(shouldActivateSettings\) emit\("activate-settings-page"\);/);
+ });
+});
diff --git a/apps/desktop/src/i18n/locales/en.ts b/apps/desktop/src/i18n/locales/en.ts
index 7ee60e07c5..0ac394159d 100644
--- a/apps/desktop/src/i18n/locales/en.ts
+++ b/apps/desktop/src/i18n/locales/en.ts
@@ -2175,6 +2175,7 @@ export default {
fullTabTitle: "Show Full Tab Titles",
closeTab: "Close Tab",
closeFixedTab: "Close Fixed Tab",
+ closeRightTabs: "Close Tabs to the Right",
closeOtherTabs: "Close Other Tabs",
closeOtherRegularTabs: "Close Other Regular Tabs",
closeOtherFixedTabs: "Close Other Fixed Tabs",
diff --git a/apps/desktop/src/i18n/locales/es.ts b/apps/desktop/src/i18n/locales/es.ts
index a0233677de..2676cad432 100644
--- a/apps/desktop/src/i18n/locales/es.ts
+++ b/apps/desktop/src/i18n/locales/es.ts
@@ -2357,6 +2357,7 @@ export default withEnglishFallback({
createFunction: "Nueva función",
createTrigger: "Nuevo disparador",
changeOpenMode: "Modificar modo de apertura",
+ closeRightTabs: "Cerrar pestañas a la derecha",
},
visibleDatabases: {
title: "Bases de datos visibles",
diff --git a/apps/desktop/src/i18n/locales/it.ts b/apps/desktop/src/i18n/locales/it.ts
index 5dd97b894c..7aa83c9276 100644
--- a/apps/desktop/src/i18n/locales/it.ts
+++ b/apps/desktop/src/i18n/locales/it.ts
@@ -2355,6 +2355,7 @@ export default withEnglishFallback({
createFunction: "Nuova funzione",
createTrigger: "Nuovo trigger",
changeOpenMode: "Modifica modalità apertura",
+ closeRightTabs: "Chiudi le schede a destra",
},
visibleDatabases: {
title: "Database Visibili",
diff --git a/apps/desktop/src/i18n/locales/ja.ts b/apps/desktop/src/i18n/locales/ja.ts
index 84c8a6143b..c01cf461f4 100644
--- a/apps/desktop/src/i18n/locales/ja.ts
+++ b/apps/desktop/src/i18n/locales/ja.ts
@@ -2382,6 +2382,7 @@ export default withEnglishFallback({
createFunction: "新規関数",
createTrigger: "新規トリガー",
changeOpenMode: "開き方を変更",
+ closeRightTabs: "右側のタブを閉じる",
},
visibleDatabases: {
title: "表示するデータベース",
diff --git a/apps/desktop/src/i18n/locales/pt-BR.ts b/apps/desktop/src/i18n/locales/pt-BR.ts
index 10a9853107..1be4ad1f86 100644
--- a/apps/desktop/src/i18n/locales/pt-BR.ts
+++ b/apps/desktop/src/i18n/locales/pt-BR.ts
@@ -2357,6 +2357,7 @@ export default withEnglishFallback({
createFunction: "Nova função",
createTrigger: "Novo gatilho",
changeOpenMode: "Alterar modo de abertura",
+ closeRightTabs: "Fechar abas à direita",
},
visibleDatabases: {
title: "Bancos de dados visíveis",
diff --git a/apps/desktop/src/i18n/locales/zh-CN.ts b/apps/desktop/src/i18n/locales/zh-CN.ts
index de46eda968..f91f149d18 100644
--- a/apps/desktop/src/i18n/locales/zh-CN.ts
+++ b/apps/desktop/src/i18n/locales/zh-CN.ts
@@ -2176,6 +2176,7 @@ export default withEnglishFallback({
fullTabTitle: "完整标签标题",
closeTab: "关闭标签页",
closeFixedTab: "关闭固定标签页",
+ closeRightTabs: "关闭右侧标签页",
closeOtherTabs: "关闭其他标签页",
closeOtherRegularTabs: "关闭其他普通标签页",
closeOtherFixedTabs: "关闭其他固定标签页",
diff --git a/apps/desktop/src/i18n/locales/zh-TW.ts b/apps/desktop/src/i18n/locales/zh-TW.ts
index dc1309cad7..3f21998f8c 100644
--- a/apps/desktop/src/i18n/locales/zh-TW.ts
+++ b/apps/desktop/src/i18n/locales/zh-TW.ts
@@ -2356,6 +2356,7 @@ export default withEnglishFallback({
createFunction: "新增函數",
createTrigger: "新增觸發器",
changeOpenMode: "修改開啟方式",
+ closeRightTabs: "關閉右側標籤頁",
},
visibleDatabases: {
title: "顯示資料庫",
diff --git a/apps/desktop/src/stores/queryStore.ts b/apps/desktop/src/stores/queryStore.ts
index 6e2f07f6c1..8798cf199f 100644
--- a/apps/desktop/src/stores/queryStore.ts
+++ b/apps/desktop/src/stores/queryStore.ts
@@ -649,6 +649,7 @@ export const useQueryStore = defineStore("query", () => {
const pendingCloseTabId = ref<string | null>(null);
const pendingBatchCloseTabIds = ref<string[] | null>(null);
const pendingBatchCloseFinalActiveTabId = ref<string | null | undefined>(undefined);
+ let pendingBatchCloseComplete: (() => void) | null = null;
const isConfirmingAppClose = ref(false);
const closeConfirmContext = ref<CloseConfirmContext>("tab");
const tableStructureRefreshVersions = ref<Record<string, number>>({});
@@ -1903,11 +1904,14 @@ export const useQueryStore = defineStore("query", () => {
function finishPendingBatchClose() {
const finalActiveTabId = pendingBatchCloseFinalActiveTabId.value;
+ const onComplete = pendingBatchCloseComplete;
pendingBatchCloseTabIds.value = null;
pendingBatchCloseFinalActiveTabId.value = undefined;
+ pendingBatchCloseComplete = null;
if (finalActiveTabId !== undefined) {
activeTabId.value = finalActiveTabId && tabs.value.some((tab) => tab.id === finalActiveTabId) ? finalActiveTabId : null;
}
+ return onComplete;
}
function continuePendingBatchClose() {
@@ -1917,7 +1921,7 @@ export const useQueryStore = defineStore("query", () => {
const remainingIds = pendingIds.filter((id) => tabs.value.some((tab) => tab.id === id));
pendingBatchCloseTabIds.value = remainingIds;
if (remainingIds.length === 0) {
- finishPendingBatchClose();
+ finishPendingBatchClose()?.();
return;
}
@@ -1928,15 +1932,20 @@ export const useQueryStore = defineStore("query", () => {
return;
}
- finishPendingBatchClose();
+ const onComplete = finishPendingBatchClose();
for (const id of remainingIds) closeTab(id, { force: true });
+ onComplete?.();
}
- function beginBatchClose(ids: string[], finalActiveTabId?: string | null) {
+ function beginBatchClose(ids: string[], finalActiveTabId?: string | null, onComplete?: () => void) {
const uniqueIds = [...new Set(ids)].filter((id) => tabs.value.some((tab) => tab.id === id));
- if (uniqueIds.length === 0) return;
+ if (uniqueIds.length === 0) {
+ onComplete?.();
+ return;
+ }
pendingBatchCloseTabIds.value = uniqueIds;
pendingBatchCloseFinalActiveTabId.value = finalActiveTabId;
+ pendingBatchCloseComplete = onComplete ?? null;
continuePendingBatchClose();
}
@@ -1998,12 +2007,14 @@ export const useQueryStore = defineStore("query", () => {
const pendingId = pendingCloseTabId.value;
const batchIds = pendingBatchCloseTabIds.value?.filter((id) => tabs.value.some((tab) => tab.id === id)) ?? null;
const finalActiveTabId = pendingBatchCloseFinalActiveTabId.value;
+ const onBatchComplete = pendingBatchCloseComplete;
const confirmingAppClose = isConfirmingAppClose.value;
pendingCloseTabId.value = null;
showCloseConfirm.value = false;
pendingBatchCloseTabIds.value = null;
pendingBatchCloseFinalActiveTabId.value = undefined;
+ pendingBatchCloseComplete = null;
isConfirmingAppClose.value = false;
closeConfirmContext.value = "tab";
@@ -2015,6 +2026,7 @@ export const useQueryStore = defineStore("query", () => {
if (finalActiveTabId !== undefined) {
activeTabId.value = finalActiveTabId && tabs.value.some((tab) => tab.id === finalActiveTabId) ? finalActiveTabId : null;
}
+ if (batchIds) onBatchComplete?.();
}
function cancelClosePendingTab() {
@@ -2022,6 +2034,7 @@ export const useQueryStore = defineStore("query", () => {
showCloseConfirm.value = false;
pendingBatchCloseTabIds.value = null;
pendingBatchCloseFinalActiveTabId.value = undefined;
+ pendingBatchCloseComplete = null;
isConfirmingAppClose.value = false;
closeConfirmContext.value = "tab";
}
@@ -2054,12 +2067,14 @@ export const useQueryStore = defineStore("query", () => {
const pendingId = pendingCloseTabId.value;
const batchIds = pendingBatchCloseTabIds.value?.filter((id) => tabs.value.some((tab) => tab.id === id)) ?? null;
const finalActiveTabId = pendingBatchCloseFinalActiveTabId.value;
+ const onBatchComplete = pendingBatchCloseComplete;
const confirmingAppClose = isConfirmingAppClose.value;
pendingCloseTabId.value = null;
showCloseConfirm.value = false;
pendingBatchCloseTabIds.value = null;
pendingBatchCloseFinalActiveTabId.value = undefined;
+ pendingBatchCloseComplete = null;
isConfirmingAppClose.value = false;
closeConfirmContext.value = "tab";
@@ -2070,6 +2085,7 @@ export const useQueryStore = defineStore("query", () => {
if (finalActiveTabId !== undefined) {
activeTabId.value = finalActiveTabId && tabs.value.some((tab) => tab.id === finalActiveTabId) ? finalActiveTabId : null;
}
+ if (batchIds) onBatchComplete?.();
return "tabs" as const;
}
@@ -2081,6 +2097,22 @@ export const useQueryStore = defineStore("query", () => {
);
}
+ function closeRightTabs(id: string, onComplete?: () => void) {
+ const target = tabs.value.find((tab) => tab.id === id);
+ if (!target) return;
+
+ const groupedTabs = tabs.value.filter((tab) => Boolean(tab.pinned) === Boolean(target.pinned));
+ const targetIndex = groupedTabs.findIndex((tab) => tab.id === id);
+ const ids = groupedTabs.slice(targetIndex + 1).map((tab) => tab.id);
+ if (ids.length === 0) {
+ onComplete?.();
+ return;
+ }
+
+ const finalActiveTabId = activeTabId.value && !ids.includes(activeTabId.value) ? activeTabId.value : id;
+ beginBatchClose(ids, finalActiveTabId, onComplete);
+ }
+
function finalActiveTabAfterClosing(ids: string[]) {
const closingIds = new Set(ids);
const activeTab = activeTabId.value ? tabs.value.find((tab) => tab.id === activeTabId.value) : undefined;
@@ -5302,6 +5334,7 @@ export const useQueryStore = defineStore("query", () => {
discardTabChanges,
requestAppCloseConfirmation,
closeOtherTabs,
+ closeRightTabs,
closeOtherRegularTabs,
closeRegularTabs,
closeOtherFixedTabs,
diff --git a/packages/app-tests/queryStore.test.ts b/packages/app-tests/queryStore.test.ts
index 0a34cec697..af5dca3b21 100644
--- a/packages/app-tests/queryStore.test.ts
+++ b/packages/app-tests/queryStore.test.ts
@@ -746,6 +746,119 @@ test("close other fixed tabs does not close regular tabs", () => {
);
});
+test("close right tabs only closes tabs to the right in the same group", () => {
+ setActivePinia(createPinia());
+ const store = useQueryStore();
+ const fixedId = store.createTab("conn-1", "db", "fixed");
+ const targetId = store.createTab("conn-1", "db", "target");
+ const rightA = store.createTab("conn-1", "db", "right a");
+ const rightB = store.createTab("conn-1", "db", "right b");
+ store.togglePinnedTab(fixedId);
+ store.activeTabId = rightB;
+
+ store.closeRightTabs(targetId);
+
+ assert.deepEqual(
+ store.tabs.map((tab) => tab.id),
+ [fixedId, targetId],
+ );
+ assert.equal(store.activeTabId, targetId);
+ assert.equal(
+ store.tabs.some((tab) => tab.id === rightA || tab.id === rightB),
+ false,
+ );
+
+ let completions = 0;
+ store.closeRightTabs(targetId, () => {
+ completions += 1;
+ });
+
+ assert.deepEqual(
+ store.tabs.map((tab) => tab.id),
+ [fixedId, targetId],
+ );
+ assert.equal(store.activeTabId, targetId);
+ assert.equal(completions, 1);
+});
+
+test("close right fixed tabs keeps regular tabs and a retained active tab", () => {
+ setActivePinia(createPinia());
+ const store = useQueryStore();
+ const targetId = store.createTab("conn-1", "db", "fixed target");
+ const rightFixedId = store.createTab("conn-1", "db", "fixed right");
+ const regularId = store.createTab("conn-1", "db", "regular");
+ store.togglePinnedTab(targetId);
+ store.togglePinnedTab(rightFixedId);
+ store.activeTabId = regularId;
+
+ store.closeRightTabs(targetId);
+
+ assert.deepEqual(
+ store.tabs.map((tab) => tab.id),
+ [targetId, regularId],
+ );
+ assert.equal(store.activeTabId, regularId);
+});
+
+test("close right tabs pauses before closing an unsaved query", () => {
+ setActivePinia(createPinia());
+ const store = useQueryStore();
+ const targetId = store.createTab("conn-1", "db", "target");
+ const dirtyId = store.createTab("conn-1", "db", "dirty");
+ store.updateSql(dirtyId, "select 1;");
+
+ store.closeRightTabs(targetId);
+
+ assert.equal(store.showCloseConfirm, true);
+ assert.equal(store.pendingCloseTabId, dirtyId);
+ assert.equal(store.closeConfirmContext, "batch");
+ assert.deepEqual(
+ store.tabs.map((tab) => tab.id),
+ [targetId, dirtyId],
+ );
+
+ store.forceClosePendingTab();
+
+ assert.equal(store.showCloseConfirm, false);
+ assert.deepEqual(
+ store.tabs.map((tab) => tab.id),
+ [targetId],
+ );
+ assert.equal(store.activeTabId, targetId);
+});
+
+test("close right tabs only runs completion after the pending batch succeeds", () => {
+ setActivePinia(createPinia());
+ const store = useQueryStore();
+ const targetId = store.createTab("conn-1", "db", "target");
+ const dirtyId = store.createTab("conn-1", "db", "dirty");
+ store.updateSql(dirtyId, "select 1;");
+ let completions = 0;
+
+ store.closeRightTabs(targetId, () => {
+ completions += 1;
+ });
+ assert.equal(completions, 0);
+
+ store.cancelClosePendingTab();
+ assert.equal(completions, 0);
+ assert.deepEqual(
+ store.tabs.map((tab) => tab.id),
+ [targetId, dirtyId],
+ );
+
+ store.closeRightTabs(targetId, () => {
+ completions += 1;
+ });
+ store.forceClosePendingTab();
+
+ assert.equal(completions, 1);
+ assert.deepEqual(
+ store.tabs.map((tab) => tab.id),
+ [targetId],
+ );
+});
+
test("close other tabs pauses on restored unsaved query tabs", async () => {
const restoreStorage = installMemoryStorage();
try {