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(sidebar): keep the close-database action first in grouped menus (#12875)

zipg3e583c40406d
diff --git a/apps/desktop/src/lib/__tests__/sidebar/sidebarMenuLayout.spec.ts b/apps/desktop/src/lib/__tests__/sidebar/sidebarMenuLayout.spec.ts
index 334465bc74..af5046e6f4 100644
--- a/apps/desktop/src/lib/__tests__/sidebar/sidebarMenuLayout.spec.ts
+++ b/apps/desktop/src/lib/__tests__/sidebar/sidebarMenuLayout.spec.ts
@@ -44,6 +44,20 @@ describe("sidebar menu layout", () => {
expect(menu.map((entry) => entry.sidebarActionId)).toEqual(["group.data"]);
expect(menu[0].children).toContainEqual(search);
});
+ it("leads database menus with closing the database and falls back to browsing objects", () => {
+ const close = item("contextMenu.closeDatabaseConnection");
+ const browse = item("contextMenu.openObjectBrowser");
+ const query = item("contextMenu.newQuery");
+ const defaults = buildSidebarMenuLayout([close, browse, query], "database", "grouped", [], t);
+ expect(defaults.filter((entry) => !entry.separator).map((entry) => entry.sidebarActionId)).toEqual(["contextMenu.closeDatabaseConnection", "contextMenu.openObjectBrowser", "contextMenu.newQuery"]);
+ expect(leaves(defaults).filter((entry) => entry.sidebarActionId === "contextMenu.closeDatabaseConnection")).toHaveLength(1);
+ // The close entry only exists for opened databases, so browsing objects becomes first once it is gone.
+ const alreadyClosed = buildSidebarMenuLayout([browse, query], "database", "grouped", [], t);
+ expect(alreadyClosed.filter((entry) => !entry.separator)[0].sidebarActionId).toBe("contextMenu.openObjectBrowser");
+ // Explicit user ordering still overrides the new default.
+ const customized = buildSidebarMenuLayout([close, browse], "database", "grouped", [], t, { order: ["contextMenu.openObjectBrowser", "contextMenu.closeDatabaseConnection"] });
+ expect(customized.filter((entry) => !entry.separator).map((entry) => entry.sidebarActionId)).toEqual(["contextMenu.openObjectBrowser", "contextMenu.closeDatabaseConnection"]);
+ });
it("shows database-specific management actions directly by default and allows opting out", () => {
const dashboard = item("contextMenu.serverDashboard");
const processes = item("contextMenu.processList");
diff --git a/apps/desktop/src/lib/sidebar/sidebarMenuLayout.ts b/apps/desktop/src/lib/sidebar/sidebarMenuLayout.ts
index 7f2d2bc7e2..3854e0d56e 100644
--- a/apps/desktop/src/lib/sidebar/sidebarMenuLayout.ts
+++ b/apps/desktop/src/lib/sidebar/sidebarMenuLayout.ts
@@ -22,7 +22,9 @@ export function sidebarMenuScope(type: SidebarMenuTargetType): SidebarMenuScope
const primaryActions: Record<SidebarMenuScope, readonly string[]> = {
connection: ["connection.cancelConnecting", "contextMenu.openConnection", "contextMenu.disconnectConnection", "contextMenu.newQuery", "savedSql.openDefaultQuery", "contextMenu.openDatabaseBrowser", "contextMenu.editConnection", "contextMenu.refreshChildren"],
- database: ["contextMenu.openObjectBrowser", "contextMenu.newQuery", "savedSql.openDefaultQuery", "contextMenu.createTable", "contextMenu.refreshChildren"],
+ // Closing a database hides itself once the database is already closed, so it leads the database menu
+ // and "browse objects" stays first for databases that cannot be closed.
+ database: ["contextMenu.closeDatabaseConnection", "contextMenu.openObjectBrowser", "contextMenu.newQuery", "savedSql.openDefaultQuery", "contextMenu.createTable", "contextMenu.refreshChildren"],
schema: ["contextMenu.openObjectBrowser", "contextMenu.newQuery", "savedSql.openDefaultQuery", "contextMenu.createTable", "contextMenu.refreshChildren"],
table: ["contextMenu.viewData", "contextMenu.openInNewDataTab", "contextMenu.editStructure", "contextMenu.newQuery", "contextMenu.refreshChildren"],
view: ["contextMenu.viewData", "contextMenu.openInNewDataTab", "contextMenu.editView", "contextMenu.newQuery", "contextMenu.refreshChildren"],
@@ -89,7 +91,6 @@ const groupActions: Partial<Record<MenuGroup, readonly string[]>> = {
"connectionGroup.moveToNewGroup",
"contextMenu.duplicateConnection",
"connection.disconnectAndForgetPassword",
- "contextMenu.closeDatabaseConnection",
"contextMenu.revealDatabaseFile",
"contextMenu.changeOpenMode",
"tableVGroup.moveToGroup",