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): expand table metadata groups

t8y2637f75663c24
diff --git a/apps/desktop/src/components/sidebar/TreeItem.vue b/apps/desktop/src/components/sidebar/TreeItem.vue
index 4919ce3659..af30975aa2 100644
--- a/apps/desktop/src/components/sidebar/TreeItem.vue
+++ b/apps/desktop/src/components/sidebar/TreeItem.vue
@@ -322,13 +322,13 @@ async function toggle() {
} else if ((node.type === "table" || node.type === "view") && node.connectionId && node.database) {
await connectionStore.loadTableGroups(node.connectionId, node.database, node.label, node.schema, node.id);
} else if (node.type === "group-columns" && node.connectionId && node.database && node.tableName) {
- await connectionStore.loadColumns(node.connectionId, node.database, node.tableName, node.schema);
+ await connectionStore.loadColumns(node.connectionId, node.database, node.tableName, node.schema, node.id);
} else if (node.type === "group-indexes" && node.connectionId && node.database && node.tableName) {
- await connectionStore.loadIndexes(node.connectionId, node.database, node.tableName, node.schema);
+ await connectionStore.loadIndexes(node.connectionId, node.database, node.tableName, node.schema, node.id);
} else if (node.type === "group-fkeys" && node.connectionId && node.database && node.tableName) {
- await connectionStore.loadForeignKeys(node.connectionId, node.database, node.tableName, node.schema);
+ await connectionStore.loadForeignKeys(node.connectionId, node.database, node.tableName, node.schema, node.id);
} else if (node.type === "group-triggers" && node.connectionId && node.database && node.tableName) {
- await connectionStore.loadTriggers(node.connectionId, node.database, node.tableName, node.schema);
+ await connectionStore.loadTriggers(node.connectionId, node.database, node.tableName, node.schema, node.id);
}
emit("node-toggled", node, wasExpanded);
} catch (e: any) {
diff --git a/apps/desktop/src/stores/connectionStore.ts b/apps/desktop/src/stores/connectionStore.ts
index 635dbe6a46..3aaab2f473 100644
--- a/apps/desktop/src/stores/connectionStore.ts
+++ b/apps/desktop/src/stores/connectionStore.ts
@@ -998,10 +998,12 @@ export const useConnectionStore = defineStore("connection", () => {
node.isExpanded = true;
}
- async function loadColumns(connectionId: string, database: string, table: string, schema?: string) {
- const parentId = schema
- ? `${connectionId}:${database}:${schema}:${table}:__columns`
- : `${connectionId}:${database}:${table}:__columns`;
+ async function loadColumns(connectionId: string, database: string, table: string, schema?: string, nodeId?: string) {
+ const parentId =
+ nodeId ??
+ (schema
+ ? `${connectionId}:${database}:${schema}:${table}:__columns`
+ : `${connectionId}:${database}:${table}:__columns`);
const node = findNode(treeNodes.value, parentId);
if (!node) return;
@@ -1031,10 +1033,12 @@ export const useConnectionStore = defineStore("connection", () => {
}
}
- async function loadIndexes(connectionId: string, database: string, table: string, schema?: string) {
- const parentId = schema
- ? `${connectionId}:${database}:${schema}:${table}:__indexes`
- : `${connectionId}:${database}:${table}:__indexes`;
+ async function loadIndexes(connectionId: string, database: string, table: string, schema?: string, nodeId?: string) {
+ const parentId =
+ nodeId ??
+ (schema
+ ? `${connectionId}:${database}:${schema}:${table}:__indexes`
+ : `${connectionId}:${database}:${table}:__indexes`);
const node = findNode(treeNodes.value, parentId);
if (!node) return;
@@ -1063,10 +1067,18 @@ export const useConnectionStore = defineStore("connection", () => {
}
}
- async function loadForeignKeys(connectionId: string, database: string, table: string, schema?: string) {
- const parentId = schema
- ? `${connectionId}:${database}:${schema}:${table}:__fkeys`
- : `${connectionId}:${database}:${table}:__fkeys`;
+ async function loadForeignKeys(
+ connectionId: string,
+ database: string,
+ table: string,
+ schema?: string,
+ nodeId?: string,
+ ) {
+ const parentId =
+ nodeId ??
+ (schema
+ ? `${connectionId}:${database}:${schema}:${table}:__fkeys`
+ : `${connectionId}:${database}:${table}:__fkeys`);
const node = findNode(treeNodes.value, parentId);
if (!node) return;
@@ -1095,10 +1107,12 @@ export const useConnectionStore = defineStore("connection", () => {
}
}
- async function loadTriggers(connectionId: string, database: string, table: string, schema?: string) {
- const parentId = schema
- ? `${connectionId}:${database}:${schema}:${table}:__triggers`
- : `${connectionId}:${database}:${table}:__triggers`;
+ async function loadTriggers(connectionId: string, database: string, table: string, schema?: string, nodeId?: string) {
+ const parentId =
+ nodeId ??
+ (schema
+ ? `${connectionId}:${database}:${schema}:${table}:__triggers`
+ : `${connectionId}:${database}:${table}:__triggers`);
const node = findNode(treeNodes.value, parentId);
if (!node) return;
@@ -1161,13 +1175,13 @@ export const useConnectionStore = defineStore("connection", () => {
} else if ((node.type === "table" || node.type === "view") && node.connectionId && node.database) {
await loadTableGroups(node.connectionId, node.database, node.label, node.schema, node.id);
} else if (node.type === "group-columns" && node.connectionId && node.database && node.tableName) {
- await loadColumns(node.connectionId, node.database, node.tableName, node.schema);
+ await loadColumns(node.connectionId, node.database, node.tableName, node.schema, node.id);
} else if (node.type === "group-indexes" && node.connectionId && node.database && node.tableName) {
- await loadIndexes(node.connectionId, node.database, node.tableName, node.schema);
+ await loadIndexes(node.connectionId, node.database, node.tableName, node.schema, node.id);
} else if (node.type === "group-fkeys" && node.connectionId && node.database && node.tableName) {
- await loadForeignKeys(node.connectionId, node.database, node.tableName, node.schema);
+ await loadForeignKeys(node.connectionId, node.database, node.tableName, node.schema, node.id);
} else if (node.type === "group-triggers" && node.connectionId && node.database && node.tableName) {
- await loadTriggers(node.connectionId, node.database, node.tableName, node.schema);
+ await loadTriggers(node.connectionId, node.database, node.tableName, node.schema, node.id);
} else if (
node.type === "group-tables" ||
node.type === "group-views" ||
diff --git a/packages/app-tests/tableTree.test.ts b/packages/app-tests/tableTree.test.ts
index 1c36706317..c5afffd608 100644
--- a/packages/app-tests/tableTree.test.ts
+++ b/packages/app-tests/tableTree.test.ts
@@ -9,6 +9,7 @@ import {
import type { TableInfo } from "../../apps/desktop/src/types/database.ts";
const treeItemSource = readFileSync("apps/desktop/src/components/sidebar/TreeItem.vue", "utf8");
+const connectionStoreSource = readFileSync("apps/desktop/src/stores/connectionStore.ts", "utf8");
function table(name: string, tableType: "TABLE" | "VIEW" = "TABLE"): TableInfo {
return { name, table_type: tableType };
@@ -128,3 +129,25 @@ test("table expander loads groups by the actual tree node id", () => {
/loadTableGroups\(node\.connectionId,\s*node\.database,\s*node\.label,\s*node\.schema,\s*node\.id\)/,
);
});
+
+test("table metadata group expanders load by their actual tree node ids", () => {
+ for (const [type, loader] of [
+ ["group-columns", "loadColumns"],
+ ["group-indexes", "loadIndexes"],
+ ["group-fkeys", "loadForeignKeys"],
+ ["group-triggers", "loadTriggers"],
+ ]) {
+ assert.match(
+ treeItemSource,
+ new RegExp(
+ `node\\.type === "${type}"[\\s\\S]*connectionStore\\.${loader}\\(node\\.connectionId,\\s*node\\.database,\\s*node\\.tableName,\\s*node\\.schema,\\s*node\\.id\\)`,
+ ),
+ );
+ assert.match(
+ connectionStoreSource,
+ new RegExp(
+ `node\\.type === "${type}"[\\s\\S]*await ${loader}\\(node\\.connectionId,\\s*node\\.database,\\s*node\\.tableName,\\s*node\\.schema,\\s*node\\.id\\)`,
+ ),
+ );
+ }
+});