From 30a4131bb2aadc2ee1e2ffa935845ddda6f2daf5 Mon Sep 17 00:00:00 2001 From: lxk955 <164191365+lxk955@users.noreply.github.com> Date: Sat, 3 Oct 2026 13:44:40 +0800 Subject: [PATCH] feat(sidebar): copy display paths for all database types --- .../sidebar/SidebarTreeRuntimeHost.vue | 14 +-- apps/desktop/src/lib/sidebar/treeNodeClick.ts | 27 ++++- packages/app-tests/treeNodeClick.test.ts | 113 ++++++++++++++++++ 3 files changed, 142 insertions(+), 12 deletions(-) diff --git a/apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue b/apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue index 994c227ac1..91d502a8ca 100644 --- a/apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue +++ b/apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue @@ -2369,7 +2369,7 @@ async function copyDisplayPath() { function copyNameMenuItem(): ContextMenuItem { const node = activeNode.value; const connectionName = node.connectionId ? connectionStore.getConfig(node.connectionId)?.name || "" : ""; - if (currentDatabaseType() === "mysql" && copyDisplayPathForTreeNode(node, connectionName)) { + if (copyDisplayPathForTreeNode(node, connectionName)) { return { label: t("contextMenu.copyName"), icon: Copy, @@ -6521,9 +6521,7 @@ function buildObjectSidebarMenu(context: SidebarMenuFactoryContext): boolean { if (!isPackageMember && canViewDatabaseObjectDependencies(currentDatabaseType(), node)) { items.push({ label: t("contextMenu.viewDependencies"), action: openDatabaseObjectDependencies, icon: Network }); } - if (currentDatabaseType() === "mysql") { - items.push(copyNameMenuItem()); - } + items.push(copyNameMenuItem()); if (!isPackageMember && canRenameObject.value) { items.push({ label: t("contextMenu.renameObject"), @@ -6569,7 +6567,7 @@ function buildObjectSidebarMenu(context: SidebarMenuFactoryContext): boolean { if (currentDatabaseType() === "oceanbase-oracle") { items.push({ label: t("contextMenu.editObject"), action: () => openObjectSourceDialog(true), icon: Pencil }); } - items.push({ label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value }); + items.push(copyNameMenuItem()); items.push({ label: t("contextMenu.changeOpenMode"), action: () => emit("open-settings", "navigation"), icon: Settings2 }); return true; } @@ -6605,7 +6603,7 @@ function buildObjectSidebarMenu(context: SidebarMenuFactoryContext): boolean { icon: Code2, }); } - items.push(node.type === "trigger" ? copyNameMenuItem() : { label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value }); + items.push(copyNameMenuItem()); items.push({ label: t("contextMenu.changeOpenMode"), action: () => emit("open-settings", "navigation"), icon: Settings2 }); return true; } @@ -6615,7 +6613,7 @@ function buildObjectSidebarMenu(context: SidebarMenuFactoryContext): boolean { if (node.type === "type" || node.type === "type-body") { if (supportsTypeObjectSource(currentDatabaseType())) { items.push({ label: t("contextMenu.viewSource"), action: () => openObjectSourceDialog(false), icon: Code2 }); - items.push({ label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value }); + items.push(copyNameMenuItem()); items.push({ label: t("contextMenu.changeOpenMode"), action: () => emit("open-settings", "navigation"), icon: Settings2 }); return true; } @@ -6623,7 +6621,7 @@ function buildObjectSidebarMenu(context: SidebarMenuFactoryContext): boolean { items.push({ label: t("contextMenu.copyDdl"), action: copyCustomTypeDdl, icon: Copy }); items.push({ label: "", separator: true }); } - items.push({ label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value }); + items.push(copyNameMenuItem()); return true; } return false; diff --git a/apps/desktop/src/lib/sidebar/treeNodeClick.ts b/apps/desktop/src/lib/sidebar/treeNodeClick.ts index bf7e58484e..56c2e94299 100644 --- a/apps/desktop/src/lib/sidebar/treeNodeClick.ts +++ b/apps/desktop/src/lib/sidebar/treeNodeClick.ts @@ -72,7 +72,7 @@ const databaseChildGroupNodeTypes = new Set([ "group-packages", "group-types", ]); -const displayPathObjectNodeTypes = new Set(["table", "view", "materialized_view", "procedure", "function", "trigger", "event"]); +const displayPathObjectNodeTypes = new Set(["table", "view", "materialized_view", "procedure", "function", "trigger", "event", "sequence", "synonym", "package", "package-body", "type", "type-body"]); export function objectSourceKindForTreeNode(type: TreeNodeType): ObjectSourceKind | null { if (type === "view") return "VIEW"; @@ -198,9 +198,28 @@ export function copyNameForTreeNode(node: TreeNode): string { export function copyDisplayPathForTreeNode(node: TreeNode, connectionName: string): string | null { const connection = connectionName.trim(); const database = node.database?.trim(); - if (!connection || !database) return null; - if (node.type === "database") return `${connection}.${database}`; + const schema = (node.schema || (node.type === "schema" ? node.label : undefined))?.trim(); + if (!connection) return null; + if (!database && !schema) return null; + + if (node.type === "database") { + return database ? `${connection}.${database}` : null; + } + + if (node.type === "schema") { + const parts = [connection]; + if (database) parts.push(database); + if (schema && schema !== database) parts.push(schema); + return parts.length > 1 ? parts.join(".") : null; + } + if (!displayPathObjectNodeTypes.has(node.type)) return null; const objectName = (node.objectName || (node.type === "table" ? node.tableName : undefined) || node.label).trim(); - return objectName ? `${connection}.${database}.${objectName}` : null; + if (!objectName) return null; + + const parts = [connection]; + if (database) parts.push(database); + if (schema && schema !== database) parts.push(schema); + parts.push(objectName); + return parts.join("."); } diff --git a/packages/app-tests/treeNodeClick.test.ts b/packages/app-tests/treeNodeClick.test.ts index a27a9e77fe..8e40b01877 100644 --- a/packages/app-tests/treeNodeClick.test.ts +++ b/packages/app-tests/treeNodeClick.test.ts @@ -262,6 +262,119 @@ test("copying a MySQL display path uses connection, database, and object names", ); }); +test("copying display paths for schema-enabled databases (PostgreSQL, Oracle, SQL Server, SQLite)", () => { + // PostgreSQL schema node + assert.equal( + copyDisplayPathForTreeNode( + { + id: "conn:mydb:public", + label: "public", + type: "schema", + connectionId: "conn", + database: "mydb", + schema: "public", + }, + "prod-pg", + ), + "prod-pg.mydb.public", + ); + // PostgreSQL table under schema + assert.equal( + copyDisplayPathForTreeNode( + { + id: "conn:mydb:public:users", + label: "users", + type: "table", + connectionId: "conn", + database: "mydb", + schema: "public", + tableName: "users", + }, + "prod-pg", + ), + "prod-pg.mydb.public.users", + ); + // PostgreSQL routine under schema + assert.equal( + copyDisplayPathForTreeNode( + { + id: "conn:mydb:public:calculate_total", + label: "calculate_total", + type: "function", + connectionId: "conn", + database: "mydb", + schema: "public", + objectName: "calculate_total", + }, + "prod-pg", + ), + "prod-pg.mydb.public.calculate_total", + ); + // Oracle table (database equals schema or database omitted) + assert.equal( + copyDisplayPathForTreeNode( + { + id: "conn:HR:EMPLOYEES", + label: "EMPLOYEES", + type: "table", + connectionId: "conn", + database: "HR", + schema: "HR", + tableName: "EMPLOYEES", + }, + "dev-oracle", + ), + "dev-oracle.HR.EMPLOYEES", + ); + // SQL Server procedure with distinct database and schema + assert.equal( + copyDisplayPathForTreeNode( + { + id: "conn:master:dbo:sp_audit", + label: "sp_audit", + type: "procedure", + connectionId: "conn", + database: "master", + schema: "dbo", + objectName: "sp_audit", + }, + "dev-mssql", + ), + "dev-mssql.master.dbo.sp_audit", + ); + // SQLite table (main database) + assert.equal( + copyDisplayPathForTreeNode( + { + id: "conn:main:items", + label: "items", + type: "table", + connectionId: "conn", + database: "main", + tableName: "items", + }, + "local-sqlite", + ), + "local-sqlite.main.items", + ); + // Additional object types: sequence, package + assert.equal( + copyDisplayPathForTreeNode( + { + id: "conn:mydb:public:user_id_seq", + label: "user_id_seq", + type: "sequence", + connectionId: "conn", + database: "mydb", + schema: "public", + objectName: "user_id_seq", + }, + "prod-pg", + ), + "prod-pg.mydb.public.user_id_seq", + ); +}); + test("copying a display path rejects incomplete and synthetic nodes", () => { assert.equal( copyDisplayPathForTreeNode(