feat(sidebar): copy display paths for all database types

This commit is contained in:
lxk955 authored and GitHub committed 2026-10-03 13:44:40 +08:00
1 parent 8dc1297f6a
commit 30a4131bb2
3 files changed
+141 -11

No files matched your search

@@ -2369,7 +2369,7 @@ async function copyDisplayPath() {
function copyNameMenuItem(): ContextMenuItem { function copyNameMenuItem(): ContextMenuItem {
const node = activeNode.value; const node = activeNode.value;
const connectionName = node.connectionId ? connectionStore.getConfig(node.connectionId)?.name || "" : ""; const connectionName = node.connectionId ? connectionStore.getConfig(node.connectionId)?.name || "" : "";
if (currentDatabaseType() === "mysql" && copyDisplayPathForTreeNode(node, connectionName)) { if (copyDisplayPathForTreeNode(node, connectionName)) {
return { return {
label: t("contextMenu.copyName"), label: t("contextMenu.copyName"),
icon: Copy, icon: Copy,
@@ -6521,9 +6521,7 @@ function buildObjectSidebarMenu(context: SidebarMenuFactoryContext): boolean {
if (!isPackageMember && canViewDatabaseObjectDependencies(currentDatabaseType(), node)) { if (!isPackageMember && canViewDatabaseObjectDependencies(currentDatabaseType(), node)) {
items.push({ label: t("contextMenu.viewDependencies"), action: openDatabaseObjectDependencies, icon: Network }); items.push({ label: t("contextMenu.viewDependencies"), action: openDatabaseObjectDependencies, icon: Network });
} }
if (currentDatabaseType() === "mysql") {
items.push(copyNameMenuItem()); items.push(copyNameMenuItem());
}
if (!isPackageMember && canRenameObject.value) { if (!isPackageMember && canRenameObject.value) {
items.push({ items.push({
label: t("contextMenu.renameObject"), label: t("contextMenu.renameObject"),
@@ -6569,7 +6567,7 @@ function buildObjectSidebarMenu(context: SidebarMenuFactoryContext): boolean {
if (currentDatabaseType() === "oceanbase-oracle") { if (currentDatabaseType() === "oceanbase-oracle") {
items.push({ label: t("contextMenu.editObject"), action: () => openObjectSourceDialog(true), icon: Pencil }); 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 }); items.push({ label: t("contextMenu.changeOpenMode"), action: () => emit("open-settings", "navigation"), icon: Settings2 });
return true; return true;
} }
@@ -6605,7 +6603,7 @@ function buildObjectSidebarMenu(context: SidebarMenuFactoryContext): boolean {
icon: Code2, 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 }); items.push({ label: t("contextMenu.changeOpenMode"), action: () => emit("open-settings", "navigation"), icon: Settings2 });
return true; return true;
} }
@@ -6615,7 +6613,7 @@ function buildObjectSidebarMenu(context: SidebarMenuFactoryContext): boolean {
if (node.type === "type" || node.type === "type-body") { if (node.type === "type" || node.type === "type-body") {
if (supportsTypeObjectSource(currentDatabaseType())) { if (supportsTypeObjectSource(currentDatabaseType())) {
items.push({ label: t("contextMenu.viewSource"), action: () => openObjectSourceDialog(false), icon: Code2 }); 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 }); items.push({ label: t("contextMenu.changeOpenMode"), action: () => emit("open-settings", "navigation"), icon: Settings2 });
return true; return true;
} }
@@ -6623,7 +6621,7 @@ function buildObjectSidebarMenu(context: SidebarMenuFactoryContext): boolean {
items.push({ label: t("contextMenu.copyDdl"), action: copyCustomTypeDdl, icon: Copy }); items.push({ label: t("contextMenu.copyDdl"), action: copyCustomTypeDdl, icon: Copy });
items.push({ label: "", separator: true }); items.push({ label: "", separator: true });
} }
items.push({ label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value }); items.push(copyNameMenuItem());
return true; return true;
} }
return false; return false;
+23 -4
View File
@@ -72,7 +72,7 @@ const databaseChildGroupNodeTypes = new Set<TreeNodeType>([
"group-packages", "group-packages",
"group-types", "group-types",
]); ]);
const displayPathObjectNodeTypes = new Set<TreeNodeType>(["table", "view", "materialized_view", "procedure", "function", "trigger", "event"]); const displayPathObjectNodeTypes = new Set<TreeNodeType>(["table", "view", "materialized_view", "procedure", "function", "trigger", "event", "sequence", "synonym", "package", "package-body", "type", "type-body"]);
export function objectSourceKindForTreeNode(type: TreeNodeType): ObjectSourceKind | null { export function objectSourceKindForTreeNode(type: TreeNodeType): ObjectSourceKind | null {
if (type === "view") return "VIEW"; if (type === "view") return "VIEW";
@@ -198,9 +198,28 @@ export function copyNameForTreeNode(node: TreeNode): string {
export function copyDisplayPathForTreeNode(node: TreeNode, connectionName: string): string | null { export function copyDisplayPathForTreeNode(node: TreeNode, connectionName: string): string | null {
const connection = connectionName.trim(); const connection = connectionName.trim();
const database = node.database?.trim(); const database = node.database?.trim();
if (!connection || !database) return null; const schema = (node.schema || (node.type === "schema" ? node.label : undefined))?.trim();
if (node.type === "database") return `${connection}.${database}`; 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; if (!displayPathObjectNodeTypes.has(node.type)) return null;
const objectName = (node.objectName || (node.type === "table" ? node.tableName : undefined) || node.label).trim(); 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(".");
} }
+113
View File
@@ -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", () => { test("copying a display path rejects incomplete and synthetic nodes", () => {
assert.equal( assert.equal(
copyDisplayPathForTreeNode( copyDisplayPathForTreeNode(