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): prevent duplicate table virtual groups under database node

lxk95554e13504214d
diff --git a/apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue b/apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue
index 6d7798e69e..9f945c0e91 100644
--- a/apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue
+++ b/apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue
@@ -7592,7 +7592,8 @@ function buildDatabaseSidebarMenu(context: SidebarMenuFactoryContext): boolean {
if (canCreateTable.value) {
items.push({ sidebarActionId: "contextMenu.createTable", label: t("contextMenu.createTable"), action: createTable, icon: Plus });
}
- if (canCreateTable.value && isTableVGroupContainerNode(node) && !node.children?.some(isGroupLabel)) {
+ const isSimpleDisplay = settingsStore.editorSettings.sidebarObjectDisplay === "simple";
+ if (canCreateTable.value && isSimpleDisplay && isTableVGroupContainerNode(node) && !node.children?.some(isGroupLabel)) {
items.push({
sidebarActionId: "contextMenu.createGroup",
label: t("connectionGroup.createGroup"),
diff --git a/apps/desktop/src/components/sidebar/__tests__/SidebarTreeRuntimeHost.tableVGroupContextMenu.spec.ts b/apps/desktop/src/components/sidebar/__tests__/SidebarTreeRuntimeHost.tableVGroupContextMenu.spec.ts
index 4c4c801933..7d42f2df73 100644
--- a/apps/desktop/src/components/sidebar/__tests__/SidebarTreeRuntimeHost.tableVGroupContextMenu.spec.ts
+++ b/apps/desktop/src/components/sidebar/__tests__/SidebarTreeRuntimeHost.tableVGroupContextMenu.spec.ts
@@ -18,6 +18,7 @@ vi.mock("@/lib/backend/api", async (importOriginal) => {
import SidebarTreeRuntimeHost from "@/components/sidebar/SidebarTreeRuntimeHost.vue";
import SidebarTableVGroupDialog from "@/components/sidebar/SidebarTableVGroupDialog.vue";
import { useConnectionStore } from "@/stores/connectionStore";
+import { useSettingsStore } from "@/stores/settingsStore";
import { showTableVGroupDialog, tableVGroupName, tableVGroupDialogScope, tableVGroupDialogParentGroupId, tableVGroupDialogTableNames } from "@/components/sidebar/sidebarTreeDialogState";
const connection = { id: "pg-1", name: "PostgreSQL", db_type: "postgres", driver_profile: "postgresql", host: "localhost", port: 5432, username: "postgres", password: "" };
@@ -95,6 +96,38 @@ describe("table virtual group context menus and dialog", () => {
expect(tableVGroupDialogTableNames.value).toEqual([]);
});
+ it("does not provide 'New Group' on database container in grouped mode (issue #13030)", async () => {
+ const host = await mountHost();
+ const settingsStore = useSettingsStore();
+ settingsStore.editorSettings.sidebarObjectDisplay = "grouped";
+ const databaseNode: TreeNode = {
+ id: "pg-1:app",
+ type: "database",
+ label: "app",
+ connectionId: connection.id,
+ database: "app",
+ };
+ const items = host.buildContextMenu(databaseNode);
+ const createGroupItem = items.find((item) => item.label === tr("connectionGroup.createGroup"));
+ expect(createGroupItem).toBeUndefined();
+ });
+
+ it("provides 'New Group' on database container in simple mode", async () => {
+ const host = await mountHost();
+ const settingsStore = useSettingsStore();
+ settingsStore.editorSettings.sidebarObjectDisplay = "simple";
+ const databaseNode: TreeNode = {
+ id: "pg-1:app",
+ type: "database",
+ label: "app",
+ connectionId: connection.id,
+ database: "app",
+ };
+ const items = host.buildContextMenu(databaseNode);
+ const createGroupItem = items.find((item) => item.label === tr("connectionGroup.createGroup"));
+ expect(createGroupItem).toBeDefined();
+ });
+
it("provides 'New Group' on group-views container", async () => {
const host = await mountHost();
const viewsGroupNode: TreeNode = {
diff --git a/apps/desktop/src/lib/table/__tests__/tableVGroup.spec.ts b/apps/desktop/src/lib/table/__tests__/tableVGroup.spec.ts
index 0d63e5e545..7ddac3736f 100644
--- a/apps/desktop/src/lib/table/__tests__/tableVGroup.spec.ts
+++ b/apps/desktop/src/lib/table/__tests__/tableVGroup.spec.ts
@@ -544,12 +544,12 @@ describe("container-kind scoped groups (views/procedures/triggers)", () => {
expect(resolveTableVGroupScopeFromNode(tree, member)).toMatchObject({ connectionId: "conn-1", database: "db1", objectType: "views" });
});
- it("narrows reprojection candidates to the scope kind even without a member label", () => {
+ it("narrows reprojection candidates to the scope kind and prefers group-tables over database (issue #13030)", () => {
const database: TreeNode = { id: "db:conn-1:db1", label: "db1", type: "database", connectionId: "conn-1", database: "db1" };
const groupTables: TreeNode = { id: "gt:1", label: "Tables", type: "group-tables", connectionId: "conn-1", database: "db1" };
const groupFunctions: TreeNode = { id: "gf:1", label: "Functions", type: "group-functions", connectionId: "conn-1", database: "db1", children: [{ id: "fn:1", label: "vg_count", type: "function", connectionId: "conn-1", database: "db1" }] };
const tree: TreeNode[] = [{ ...database, children: [groupTables, groupFunctions] }];
- expect(findTableVGroupContainerNode(tree, { connectionId: "conn-1", database: "db1", objectType: "tables" })).toBe(tree[0]);
+ expect(findTableVGroupContainerNode(tree, { connectionId: "conn-1", database: "db1", objectType: "tables" })).toBe(groupTables);
});
it("collects member names per container kind", () => {
diff --git a/apps/desktop/src/lib/table/tableVGroup.ts b/apps/desktop/src/lib/table/tableVGroup.ts
index 5166f39950..fb779b5357 100644
--- a/apps/desktop/src/lib/table/tableVGroup.ts
+++ b/apps/desktop/src/lib/table/tableVGroup.ts
@@ -653,11 +653,26 @@ export function findTableVGroupContainerNode(nodes: TreeNode[], scope: TableVGro
walk(nodes);
if (!candidates.length) return null;
+ // 表容器优先级:同 scope 下若存在 group-tables(展开或折叠),绝不能回退给
+ // database/schema 泛容器挂载分组(issue #13030);且已包含 group-tables 子节点的
+ // 库/模式节点处于分组展示模式,自身绝不是表行的直接挂载点。
+ const hasSpecificTableContainer = candidates.some((node) => node.type === "group-tables");
+ const validCandidates = candidates.filter((node) => {
+ if (hasSpecificTableContainer && (node.type === "database" || node.type === "schema" || node.type === "linked-server-schema")) {
+ return false;
+ }
+ if ((node.children ?? []).some((child) => child.type === "group-tables")) {
+ return false;
+ }
+ return true;
+ });
+ const candidatePool = validCandidates.length > 0 ? validCandidates : candidates;
+
if (memberLabel) {
- const holder = candidates.find((node) => (node.children ?? []).some((child) => memberRowTypes[child.type] && child.label === memberLabel));
+ const holder = candidatePool.find((node) => (node.children ?? []).some((child) => memberRowTypes[child.type] && child.label === memberLabel));
if (holder) return holder;
}
- return candidates.find((node) => (node.children ?? []).some((child) => memberRowTypes[child.type] || child.type === "table-vgroup")) ?? candidates[0]!;
+ return candidatePool.find((node) => (node.children ?? []).some((child) => memberRowTypes[child.type] || child.type === "table-vgroup")) ?? candidatePool[0]!;
}
/**
diff --git a/apps/desktop/src/stores/__tests__/connectionStore.tableVGroups.spec.ts b/apps/desktop/src/stores/__tests__/connectionStore.tableVGroups.spec.ts
index ef4a777d2b..79e7a4e940 100644
--- a/apps/desktop/src/stores/__tests__/connectionStore.tableVGroups.spec.ts
+++ b/apps/desktop/src/stores/__tests__/connectionStore.tableVGroups.spec.ts
@@ -466,4 +466,138 @@ describe("connectionStore table virtual groups during disk reload", () => {
expect(columnsGroup!.children?.some((node) => node.type === "table-vgroup")).toBe(false);
expect(columnsGroup!.children?.map((node) => node.type)).toEqual(["column", "column"]);
});
+
+ it("does not mount table virtual groups under database node when group-tables is present (issue #13030)", async () => {
+ const api = await import("@/lib/backend/api");
+ const { tableVGroupScopeKey } = await import("@/lib/table/tableVGroup");
+ const { useConnectionStore } = await import("@/stores/connectionStore");
+ const config: ConnectionConfig = { id: "mysql-13030", name: "MySQL", db_type: "mysql", host: "127.0.0.1", port: 3306, username: "root", password: "", database: "gtis_cloud" };
+ const scope = { connectionId: config.id, database: "gtis_cloud" };
+ const layout = {
+ version: 1,
+ enabled: true,
+ groups: [
+ { id: "g1", name: "国际物流表", collapsed: false },
+ { id: "g2", name: "备件物流表", collapsed: false },
+ ],
+ order: [
+ {
+ type: "group" as const,
+ id: "g1",
+ children: [{ type: "table" as const, name: "t_shipping" }],
+ },
+ {
+ type: "group" as const,
+ id: "g2",
+ children: [{ type: "table" as const, name: "t_parts" }],
+ },
+ ],
+ };
+ vi.mocked(api.loadConnections).mockResolvedValue([config]);
+ vi.mocked(api.loadTableVGroups).mockResolvedValue({ [tableVGroupScopeKey(scope)!]: layout });
+ const store = useConnectionStore();
+ await store.initFromDisk();
+
+ const groupTables: TreeNode = {
+ id: `${config.id}:gtis_cloud:group-tables`,
+ label: "Tables",
+ type: "group-tables",
+ connectionId: config.id,
+ database: "gtis_cloud",
+ children: [
+ { id: `${config.id}:gtis_cloud:t_shipping`, label: "t_shipping", type: "table", connectionId: config.id, database: "gtis_cloud" },
+ { id: `${config.id}:gtis_cloud:t_parts`, label: "t_parts", type: "table", connectionId: config.id, database: "gtis_cloud" },
+ { id: `${config.id}:gtis_cloud:t_other`, label: "t_other", type: "table", connectionId: config.id, database: "gtis_cloud" },
+ ],
+ isExpanded: true,
+ };
+ const groupViews: TreeNode = {
+ id: `${config.id}:gtis_cloud:group-views`,
+ label: "Views",
+ type: "group-views",
+ connectionId: config.id,
+ database: "gtis_cloud",
+ children: [],
+ };
+ const database: TreeNode = {
+ id: `${config.id}:gtis_cloud`,
+ label: "gtis_cloud",
+ type: "database",
+ connectionId: config.id,
+ database: "gtis_cloud",
+ children: [groupTables, groupViews],
+ isExpanded: true,
+ };
+ store.connectedIds = new Set([config.id]);
+ store.treeNodes[0]!.isExpanded = true;
+ store.treeNodes[0]!.children!.push(database);
+
+ // Reproject layout or create a new group
+ store.createTableVGroup(groupTables, "新分组");
+
+ // Database children must NOT contain table-vgroup nodes
+ expect(database.children?.some((node) => node.type === "table-vgroup")).toBe(false);
+ expect(database.children?.map((node) => node.type)).toEqual(["group-tables", "group-views"]);
+
+ // Tables group node must contain the projected table-vgroups
+ expect(groupTables.children?.some((node) => node.type === "table-vgroup")).toBe(true);
+ const vgroupLabels = groupTables.children?.filter((node) => node.type === "table-vgroup").map((node) => node.label);
+ expect(vgroupLabels).toContain("国际物流表");
+ expect(vgroupLabels).toContain("备件物流表");
+ expect(vgroupLabels).toContain("新分组");
+ });
+
+ it("strips legacy or cached table virtual groups from database children when group-tables is loaded (issue #13030)", async () => {
+ const api = await import("@/lib/backend/api");
+ const { tableVGroupScopeKey } = await import("@/lib/table/tableVGroup");
+ const { useConnectionStore } = await import("@/stores/connectionStore");
+ const config: ConnectionConfig = { id: "mysql-13030-strip", name: "MySQL", db_type: "mysql", host: "127.0.0.1", port: 3306, username: "root", password: "", database: "gtis_cloud" };
+ const scope = { connectionId: config.id, database: "gtis_cloud" };
+ const layout = {
+ version: 1,
+ enabled: true,
+ groups: [{ id: "g1", name: "国际物流表", collapsed: false }],
+ order: [{ type: "group" as const, id: "g1", children: [] }],
+ };
+ vi.mocked(api.loadConnections).mockResolvedValue([config]);
+ vi.mocked(api.loadTableVGroups).mockResolvedValue({ [tableVGroupScopeKey(scope)!]: layout });
+ const store = useConnectionStore();
+ await store.initFromDisk();
+
+ const leakedVGroup: TreeNode = {
+ id: "table-vgroup:g1",
+ label: "国际物流表",
+ type: "table-vgroup",
+ connectionId: config.id,
+ database: "gtis_cloud",
+ vgroupId: "g1",
+ };
+ const groupTables: TreeNode = {
+ id: `${config.id}:gtis_cloud:group-tables`,
+ label: "Tables",
+ type: "group-tables",
+ connectionId: config.id,
+ database: "gtis_cloud",
+ children: [],
+ };
+ const database: TreeNode = {
+ id: `${config.id}:gtis_cloud`,
+ label: "gtis_cloud",
+ type: "database",
+ connectionId: config.id,
+ database: "gtis_cloud",
+ children: [leakedVGroup, groupTables],
+ isExpanded: true,
+ };
+ store.connectedIds = new Set([config.id]);
+ store.treeNodes[0]!.isExpanded = true;
+ store.treeNodes[0]!.children!.push(database);
+
+ // Call reproject
+ store.createTableVGroup(groupTables, "新分组2");
+
+ // Database children must have the leaked table-vgroup stripped
+ expect(database.children?.some((node) => node.type === "table-vgroup")).toBe(false);
+ expect(database.children?.map((node) => node.type)).toEqual(["group-tables"]);
+ });
});
diff --git a/apps/desktop/src/stores/connectionStore.ts b/apps/desktop/src/stores/connectionStore.ts
index de5073536b..7ccb4a6047 100644
--- a/apps/desktop/src/stores/connectionStore.ts
+++ b/apps/desktop/src/stores/connectionStore.ts
@@ -2184,6 +2184,8 @@ export const useConnectionStore = defineStore("connection", () => {
if (vgroupResolved) {
children = applyTableVGroupsToChildren(children, tableVGroupLayouts.value[vgroupResolved.scopeKey], vgroupResolved.scope);
}
+ } else if (children.some((child) => child.type === "group-tables" || isTreeGroupNodeType(child.type))) {
+ children = stripTableVGroupsFromChildren(children);
}
parent.children = markRawLeafTreeNodes(children);
loadedTreeNodeChildrenIds.value.add(parent.id);
@@ -10602,7 +10604,14 @@ export const useConnectionStore = defineStore("connection", () => {
function reprojectTableVGroupScope(scope: TableVGroupScope, scopeKey: string, tableName?: string, rowType?: string) {
const container = findTableVGroupContainerNode(treeNodes.value, scope, tableName, rowType);
if (!container?.children) return;
- if (container.children.some((child) => child.type === "group-tables" || isTreeGroupNodeType(child.type))) return;
+ if (container.children.some((child) => child.type === "group-tables" || isTreeGroupNodeType(child.type))) {
+ container.children = stripTableVGroupsFromChildren(container.children);
+ return;
+ }
+ const parent = findParentNode(treeNodes.value, container.id);
+ if (parent?.children && parent.children.some((child) => child.type === "group-tables" || isTreeGroupNodeType(child.type))) {
+ parent.children = stripTableVGroupsFromChildren(parent.children);
+ }
container.children = applyTableVGroupsToChildren(stripTableVGroupsFromChildren(container.children), tableVGroupLayouts.value[scopeKey], scope);
}