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): make opting out of a grouped menu action hide it (#12989)

李子凡98e507eed029
diff --git a/apps/desktop/src/components/editor/__tests__/QueryEditorContextMenu.integration.spec.ts b/apps/desktop/src/components/editor/__tests__/QueryEditorContextMenu.integration.spec.ts
index 7a6c316cc4..e77c6c7063 100644
--- a/apps/desktop/src/components/editor/__tests__/QueryEditorContextMenu.integration.spec.ts
+++ b/apps/desktop/src/components/editor/__tests__/QueryEditorContextMenu.integration.spec.ts
@@ -149,7 +149,8 @@ describe("QueryEditor extracted context menu", () => {
expect([...document.querySelectorAll("[data-dbx-context-menu] button")].some((entry) => entry.textContent === "editor.contextMenu.uppercaseSelection")).toBe(false);
button("sidebarMenu.groups.sqlEditor").click();
await nextTick();
- expect(button("editor.contextMenu.uppercaseSelection").disabled).toBe(false);
+ // Opting out hides the action for good; it must not reappear in its group (#12791).
+ expect([...document.querySelectorAll("[data-dbx-context-menu] button")].some((entry) => entry.textContent === "editor.contextMenu.uppercaseSelection")).toBe(false);
});
it("promotes saved editor actions without changing the preferences of table menus", async () => {
diff --git a/apps/desktop/src/components/sidebar/SidebarMenuPreferencesDialog.vue b/apps/desktop/src/components/sidebar/SidebarMenuPreferencesDialog.vue
index a8c00af202..85a1404d01 100644
--- a/apps/desktop/src/components/sidebar/SidebarMenuPreferencesDialog.vue
+++ b/apps/desktop/src/components/sidebar/SidebarMenuPreferencesDialog.vue
@@ -63,7 +63,9 @@ function isSelected(id: string) {
function toggle(id: string, checked: boolean) {
pinnedIds.value = checked ? [...new Set([...pinnedIds.value, id])] : pinnedIds.value.filter((entry) => entry !== id);
- if (recommendedIds.value.has(id)) hiddenIds.value = checked ? hiddenIds.value.filter((entry) => entry !== id) : [...new Set([...hiddenIds.value, id])];
+ // Unchecking any non-built-in action hides it outright; leaving it in its group
+ // made the checkbox look inert for grouped entries (#12791).
+ hiddenIds.value = checked ? hiddenIds.value.filter((entry) => entry !== id) : [...new Set([...hiddenIds.value, id])];
}
function sectionItems(section: Section) {
diff --git a/apps/desktop/src/components/sidebar/__tests__/SidebarTreeRuntimeHost.savedSqlContextMenu.spec.ts b/apps/desktop/src/components/sidebar/__tests__/SidebarTreeRuntimeHost.savedSqlContextMenu.spec.ts
index 9e4c435c71..86f4aadfcf 100644
--- a/apps/desktop/src/components/sidebar/__tests__/SidebarTreeRuntimeHost.savedSqlContextMenu.spec.ts
+++ b/apps/desktop/src/components/sidebar/__tests__/SidebarTreeRuntimeHost.savedSqlContextMenu.spec.ts
@@ -89,7 +89,8 @@ describe("SidebarTreeRuntimeHost saved SQL context menu (#9127)", () => {
expect(grouped[0]).toBe(filter);
const hidden = buildSidebarMenuLayout(raw, "connection", "grouped", [], tr, { hiddenPrimaryIds: ["contextMenu.configureVisibleObjects"] });
expect(hidden).not.toContain(filter);
- expect(hidden.find((entry) => entry.sidebarActionId === "group.organize")?.children).toContainEqual(expect.objectContaining({ action: filter!.action }));
+ // Opting out removes the entry from the grouped layout entirely (#12791).
+ expect(menuLabels(hidden)).not.toContain(tr(dbType === "oracle" ? "visibleSchemas.title" : "contextMenu.configureVisibleObjects"));
});
it.each(["mysql", "postgres", "oracle", "sqlserver"])("puts database search in data tools and pinning directly in %s database and table menus", async (dbType) => {
diff --git a/apps/desktop/src/lib/__tests__/sidebar/sidebarMenuLayout.spec.ts b/apps/desktop/src/lib/__tests__/sidebar/sidebarMenuLayout.spec.ts
index af5046e6f4..9347d431a2 100644
--- a/apps/desktop/src/lib/__tests__/sidebar/sidebarMenuLayout.spec.ts
+++ b/apps/desktop/src/lib/__tests__/sidebar/sidebarMenuLayout.spec.ts
@@ -14,7 +14,7 @@ describe("sidebar menu layout", () => {
["table", "tableSettings"],
["view", "viewSettings"],
] as const)("names settings for the current %s scope", (scope, key) => {
- const menu = buildSidebarMenuLayout([item("contextMenu.configureVisibleObjects")], scope, "grouped", [], t, { hiddenPrimaryIds: ["contextMenu.configureVisibleObjects"] });
+ const menu = buildSidebarMenuLayout([item("contextMenu.editSchemaComment")], scope, "grouped", [], t);
expect(menu[0].label).toBe(`sidebarMenu.groups.${key}`);
expect(menu[0].sidebarActionId).toBe("group.organize");
});
@@ -24,8 +24,7 @@ describe("sidebar menu layout", () => {
const raw = [query, pin];
expect(buildSidebarMenuLayout(raw, scope, "grouped", [], t, { order: [pin.sidebarActionId!, query.sidebarActionId!] }).filter((entry) => !entry.separator)).toEqual([pin, query]);
const hidden = buildSidebarMenuLayout(raw, scope, "grouped", [], t, { hiddenPrimaryIds: [pin.sidebarActionId!] });
- expect(hidden).not.toContain(pin);
- expect(hidden.find((entry) => entry.sidebarActionId === "group.organize")?.children).toContainEqual(pin);
+ expect(leaves(hidden)).not.toContainEqual(pin);
expect(buildSidebarMenuLayout(raw, scope, "full", [], t, { hiddenPrimaryIds: [pin.sidebarActionId!] })).toEqual(raw);
});
@@ -33,9 +32,11 @@ describe("sidebar menu layout", () => {
const filters = [item("contextMenu.configureVisibleObjects"), item("visibleSchemas.title")];
const defaults = buildSidebarMenuLayout(filters, "connection", "grouped", [], t, { order: ["visibleSchemas.title", "contextMenu.configureVisibleObjects"] });
expect(defaults).toEqual([filters[1], filters[0]]);
+ // #12791: an unchecked action must disappear from the grouped menu too, not
+ // just from the primary area, or the checkbox reads as a no-op.
const hidden = buildSidebarMenuLayout(filters, "connection", "grouped", [], t, { hiddenPrimaryIds: filters.map((entry) => entry.sidebarActionId!) });
- expect(hidden[0].sidebarActionId).toBe("group.organize");
- expect(hidden[0].children).toEqual(filters);
+ expect(leaves(hidden)).toEqual([]);
+ expect(hidden.filter((entry) => entry.sidebarActionId?.startsWith("group."))).toEqual([]);
});
it("groups database-wide search with data tools without an extra management submenu", () => {
@@ -65,15 +66,31 @@ describe("sidebar menu layout", () => {
const input = [dashboard, processes, trace, item("contextMenu.newQuery")];
const defaults = buildSidebarMenuLayout(input, "connection", "grouped", [], t);
for (const action of [dashboard, processes, trace]) expect(defaults).toContain(action);
+ // #12791: opting out removes the action from the grouped layout entirely.
const customized = buildSidebarMenuLayout(input, "connection", "grouped", [], t, { hiddenPrimaryIds: ["contextMenu.serverDashboard", "contextMenu.sqlServerTrace"] });
expect(customized).not.toContain(dashboard);
expect(customized).not.toContain(trace);
expect(customized).toContain(processes);
- expect(customized.find((entry) => entry.sidebarActionId === "group.manage")?.children).toEqual(expect.arrayContaining([dashboard, trace]));
- expect(leaves(customized)).toHaveLength(input.length);
+ expect(customized.find((entry) => entry.sidebarActionId === "group.manage")).toBeUndefined();
+ expect(leaves(customized)).toHaveLength(input.length - 2);
expect(buildSidebarMenuLayout(input, "connection", "full", [], t, { hiddenPrimaryIds: [dashboard.sidebarActionId!], order: [processes.sidebarActionId!] })).toEqual(input);
});
+ it("hides an unchecked grouped action instead of leaving it in its group", () => {
+ // contextMenu.userAdmin is not a recommended primary action: it only ever
+ // renders inside the connection tools group, so unchecking it used to look
+ // like a no-op (#12791).
+ const userAdmin = item("contextMenu.userAdmin");
+ const processes = item("contextMenu.processList");
+ const visible = buildSidebarMenuLayout([userAdmin, processes], "connection", "grouped", [], t);
+ expect(leaves(visible).map((entry) => entry.sidebarActionId)).toContain("contextMenu.userAdmin");
+ expect(visible.find((entry) => entry.sidebarActionId === "group.manage")?.children).toContainEqual(expect.objectContaining({ sidebarActionId: "contextMenu.userAdmin" }));
+
+ const hidden = buildSidebarMenuLayout([userAdmin, processes], "connection", "grouped", [], t, { hiddenPrimaryIds: ["contextMenu.userAdmin"] });
+ expect(leaves(hidden).map((entry) => entry.sidebarActionId)).not.toContain("contextMenu.userAdmin");
+ expect(hidden.find((entry) => entry.sidebarActionId === "group.manage")).toBeUndefined();
+ });
+
it("sorts primary actions and groups independently while leaving dangerous actions last", () => {
const input = [item("contextMenu.refreshChildren"), item("contextMenu.viewData"), item("contextMenu.copyName"), item("contextMenu.importData"), item("contextMenu.viewDdl"), item("contextMenu.dropTable", { variant: "destructive" })];
const grouped = buildSidebarMenuLayout(input, "table", "grouped", [], t, { order: ["group.danger", "group.data", "group.copy", "contextMenu.refreshChildren", "contextMenu.viewData", "group.structure"] });
diff --git a/apps/desktop/src/lib/sidebar/sidebarMenuLayout.ts b/apps/desktop/src/lib/sidebar/sidebarMenuLayout.ts
index 6484c6d64a..5734ca934c 100644
--- a/apps/desktop/src/lib/sidebar/sidebarMenuLayout.ts
+++ b/apps/desktop/src/lib/sidebar/sidebarMenuLayout.ts
@@ -189,6 +189,9 @@ export function buildSidebarMenuLayout(items: readonly ContextMenuItem[], scope:
}
const actionGroup = sidebarMenuActionGroup(item);
const group: MenuGroup = scope === "connection" && ["data", "sql", "structure"].includes(actionGroup) ? "manage" : (scope === "table" || scope === "view") && actionGroup === "manage" ? "structure" : actionGroup;
+ // Unchecking an action in the customize dialog has to hide it, not just drop
+ // it back into its group (#12791). Built-in actions cannot be unchecked.
+ if (group !== "danger" && !builtInIds.has(item.sidebarActionId) && hiddenIds.has(item.sidebarActionId)) continue;
if (group !== "danger" && (builtInIds.has(item.sidebarActionId) || pinned.has(item.sidebarActionId) || (recommendedIds.has(item.sidebarActionId) && !hiddenIds.has(item.sidebarActionId)))) {
primary.push(item);
continue;