feat(sidebar): copy MySQL object display paths

Closes #5903
This commit is contained in:
t8y2 committed 2026-08-13 14:35:09 +00:00
1 parent 34f6389503
commit 0b530145ba
12 files changed
+176 -6

No files matched your search

@@ -101,7 +101,7 @@ import {
usesTreeSchemaMode, usesTreeSchemaMode,
isSingleDatabase, isSingleDatabase,
} from "@/lib/database/databaseCapabilities"; } from "@/lib/database/databaseCapabilities";
import { copyNameForTreeNode, isDirectNavigationTreeNode, isDocumentBrowserTreeNode, objectSourceTargetForTreeNode, shouldRunTreeNodeRowAction, treeNodeRowAction, treeNodeRowDoubleClickAction } from "@/lib/sidebar/treeNodeClick"; import { copyDisplayPathForTreeNode, copyNameForTreeNode, isDirectNavigationTreeNode, isDocumentBrowserTreeNode, objectSourceTargetForTreeNode, shouldRunTreeNodeRowAction, treeNodeRowAction, treeNodeRowDoubleClickAction } from "@/lib/sidebar/treeNodeClick";
import { customTypeCapabilities, supportsTypeObjectSource } from "@/lib/database/databaseObjectCapabilities"; import { customTypeCapabilities, supportsTypeObjectSource } from "@/lib/database/databaseObjectCapabilities";
import { mongoCollectionTableTypeFromNode, mongoDropIndexFailureCount } from "@/lib/sidebar/mongoCollectionMutation"; import { mongoCollectionTableTypeFromNode, mongoDropIndexFailureCount } from "@/lib/sidebar/mongoCollectionMutation";
import { dataTabOpenModeFromTreeClick, type DataTabOpenMode } from "@/lib/sidebar/dataTabOpenPolicy"; import { dataTabOpenModeFromTreeClick, type DataTabOpenMode } from "@/lib/sidebar/dataTabOpenPolicy";
@@ -1679,6 +1679,35 @@ async function copyName() {
} }
} }
async function copyDisplayPath() {
const node = activeNode.value;
const connectionName = node.connectionId ? connectionStore.getConfig(node.connectionId)?.name || "" : "";
const path = copyDisplayPathForTreeNode(node, connectionName);
if (!path) return;
try {
await copyToClipboard(path);
toast(t("connection.copied"), 2000);
} catch (e: any) {
toast(t("grid.copyFailed", { message: e?.message || String(e) }), 5000);
}
}
function copyNameMenuItem(): ContextMenuItem {
const node = activeNode.value;
const connectionName = node.connectionId ? connectionStore.getConfig(node.connectionId)?.name || "" : "";
if (currentDatabaseType() === "mysql" && copyDisplayPathForTreeNode(node, connectionName)) {
return {
label: t("contextMenu.copyName"),
icon: Copy,
children: [
{ label: t("contextMenu.name"), action: copyName, icon: Copy },
{ label: t("contextMenu.fullPath"), action: copyDisplayPath, icon: Copy },
],
};
}
return { label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value };
}
async function copyCustomTypeDdl() { async function copyCustomTypeDdl() {
const node = createSidebarActionTarget(activeNode.value); const node = createSidebarActionTarget(activeNode.value);
if (!node.connectionId || !node.database) return; if (!node.connectionId || !node.database) return;
@@ -4490,7 +4519,7 @@ function buildDatabaseSidebarMenu(context: SidebarMenuFactoryContext): boolean {
items.push({ label: t("contextMenu.closeDatabaseConnection"), action: closeDatabaseConnection, icon: Unplug }); items.push({ label: t("contextMenu.closeDatabaseConnection"), action: closeDatabaseConnection, icon: Unplug });
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());
items.push({ label: "", separator: true }); items.push({ label: "", separator: true });
if (canOpenObjectBrowser.value) { if (canOpenObjectBrowser.value) {
items.push({ label: t("contextMenu.openObjectBrowser"), action: openObjectBrowser, icon: TableProperties }); items.push({ label: t("contextMenu.openObjectBrowser"), action: openObjectBrowser, icon: TableProperties });
@@ -4782,7 +4811,7 @@ function buildObjectSidebarMenu(context: SidebarMenuFactoryContext): boolean {
return true; return true;
} }
const destructiveActions: ContextMenuItem[] = []; const destructiveActions: ContextMenuItem[] = [];
items.push({ label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value }); items.push(copyNameMenuItem());
items.push({ label: "", separator: true }); items.push({ label: "", separator: true });
items.push({ label: t("contextMenu.viewData"), action: openDataImmediately, icon: TableProperties }); items.push({ label: t("contextMenu.viewData"), action: openDataImmediately, icon: TableProperties });
items.push({ items.push({
@@ -4929,7 +4958,7 @@ function buildObjectSidebarMenu(context: SidebarMenuFactoryContext): boolean {
} }
if (node.type === "index" || node.type === "fkey" || (node.type === "trigger" && !!node.tableName)) { if (node.type === "index" || node.type === "fkey" || (node.type === "trigger" && !!node.tableName)) {
items.push({ label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value }); items.push(node.type === "trigger" ? copyNameMenuItem() : { label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value });
if (currentDatabaseType() === "xugu" && buildXuguCompileSql({ objectType: node.type, schema: node.schema, name: node.objectName || node.label })) { if (currentDatabaseType() === "xugu" && buildXuguCompileSql({ objectType: node.type, schema: node.schema, name: node.objectName || node.label })) {
items.push({ label: t("contextMenu.compileObject"), action: compileXuguObject, icon: Wrench }); items.push({ label: t("contextMenu.compileObject"), action: compileXuguObject, icon: Wrench });
} }
@@ -4969,6 +4998,9 @@ function buildObjectSidebarMenu(context: SidebarMenuFactoryContext): boolean {
items.push({ label: t("contextMenu.compileObject"), action: compileXuguObject, icon: Wrench }); items.push({ label: t("contextMenu.compileObject"), action: compileXuguObject, icon: Wrench });
} }
items.push({ label: t("contextMenu.viewSource"), action: () => openObjectSourceDialog(false), icon: Code2 }); items.push({ label: t("contextMenu.viewSource"), action: () => openObjectSourceDialog(false), icon: Code2 });
if (currentDatabaseType() === "mysql") {
items.push(copyNameMenuItem());
}
if (!isPackageMember && canRenameObject.value) { if (!isPackageMember && canRenameObject.value) {
items.push({ items.push({
label: t("contextMenu.renameObject"), label: t("contextMenu.renameObject"),
@@ -5011,7 +5043,7 @@ function buildObjectSidebarMenu(context: SidebarMenuFactoryContext): boolean {
icon: Code2, icon: Code2,
}); });
} }
items.push({ label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value }); items.push(node.type === "trigger" ? copyNameMenuItem() : { label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value });
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;
} }
+2
View File
@@ -2630,6 +2630,8 @@ export default {
closeAllRegularTabs: "Close All Regular Tabs", closeAllRegularTabs: "Close All Regular Tabs",
closeAllFixedTabs: "Close All Fixed Tabs", closeAllFixedTabs: "Close All Fixed Tabs",
copyName: "Copy Name", copyName: "Copy Name",
name: "Name",
fullPath: "Full Path",
copyFinalProxyPort: "Copy Final Proxy Port", copyFinalProxyPort: "Copy Final Proxy Port",
finalProxyPortCopied: "Final proxy port {port} copied", finalProxyPortCopied: "Final proxy port {port} copied",
setDefaultDatabase: "Set as Default Database", setDefaultDatabase: "Set as Default Database",
+2
View File
@@ -2560,6 +2560,8 @@ export default withEnglishFallback({
closeAllRegularTabs: "Cerrar todas las pestañas normales", closeAllRegularTabs: "Cerrar todas las pestañas normales",
closeAllFixedTabs: "Cerrar todas las pestañas fijadas", closeAllFixedTabs: "Cerrar todas las pestañas fijadas",
copyName: "Copiar nombre", copyName: "Copiar nombre",
name: "Nombre",
fullPath: "Ruta completa",
copyFinalProxyPort: "Copiar puerto proxy final", copyFinalProxyPort: "Copiar puerto proxy final",
finalProxyPortCopied: "Puerto proxy final {port} copiado", finalProxyPortCopied: "Puerto proxy final {port} copiado",
setDefaultDatabase: "Establecer como base de datos predeterminada", setDefaultDatabase: "Establecer como base de datos predeterminada",
+2
View File
@@ -2558,6 +2558,8 @@ export default withEnglishFallback({
closeAllRegularTabs: "Chiudi Tutte le Schede Normali", closeAllRegularTabs: "Chiudi Tutte le Schede Normali",
closeAllFixedTabs: "Chiudi Tutte le Schede Fisse", closeAllFixedTabs: "Chiudi Tutte le Schede Fisse",
copyName: "Copia Nome", copyName: "Copia Nome",
name: "Nome",
fullPath: "Percorso completo",
copyFinalProxyPort: "Copia porta proxy finale", copyFinalProxyPort: "Copia porta proxy finale",
finalProxyPortCopied: "Porta proxy finale {port} copiata", finalProxyPortCopied: "Porta proxy finale {port} copiata",
setDefaultDatabase: "Imposta come Database Predefinito", setDefaultDatabase: "Imposta come Database Predefinito",
+2
View File
@@ -2583,6 +2583,8 @@ export default withEnglishFallback({
closeAllRegularTabs: "すべての通常タブを閉じる", closeAllRegularTabs: "すべての通常タブを閉じる",
closeAllFixedTabs: "すべての固定タブを閉じる", closeAllFixedTabs: "すべての固定タブを閉じる",
copyName: "名前をコピー", copyName: "名前をコピー",
name: "名前",
fullPath: "フルパス",
copyFinalProxyPort: "最終プロキシポートをコピー", copyFinalProxyPort: "最終プロキシポートをコピー",
finalProxyPortCopied: "最終プロキシポート {port} をコピーしました", finalProxyPortCopied: "最終プロキシポート {port} をコピーしました",
setDefaultDatabase: "デフォルトデータベースに設定", setDefaultDatabase: "デフォルトデータベースに設定",
+2
View File
@@ -2483,6 +2483,8 @@ export default withEnglishFallback({
closeAllRegularTabs: "모든 일반 탭 닫기", closeAllRegularTabs: "모든 일반 탭 닫기",
closeAllFixedTabs: "모든 고정 탭 닫기", closeAllFixedTabs: "모든 고정 탭 닫기",
copyName: "이름 복사", copyName: "이름 복사",
name: "이름",
fullPath: "전체 경로",
copyFinalProxyPort: "최종 프록시 포트 복사", copyFinalProxyPort: "최종 프록시 포트 복사",
finalProxyPortCopied: "최종 프록시 포트 {port} 복사됨", finalProxyPortCopied: "최종 프록시 포트 {port} 복사됨",
setDefaultDatabase: "기본 데이터베이스로 설정", setDefaultDatabase: "기본 데이터베이스로 설정",
+2
View File
@@ -2562,6 +2562,8 @@ export default withEnglishFallback({
copyFinalProxyPort: "Copiar porta final do proxy", copyFinalProxyPort: "Copiar porta final do proxy",
finalProxyPortCopied: "Porta final do proxy {port} copiada", finalProxyPortCopied: "Porta final do proxy {port} copiada",
copyName: "Copiar Nome", copyName: "Copiar Nome",
name: "Nome",
fullPath: "Caminho completo",
setDefaultDatabase: "Definir como Banco de Dados Padrão", setDefaultDatabase: "Definir como Banco de Dados Padrão",
clearDefaultDatabase: "Limpar Banco de Dados Padrão", clearDefaultDatabase: "Limpar Banco de Dados Padrão",
setDefaultSchema: "Definir como Schema Padrão", setDefaultSchema: "Definir como Schema Padrão",
+2
View File
@@ -2554,6 +2554,8 @@ export default withEnglishFallback({
closeAllRegularTabs: "关闭全部普通标签页", closeAllRegularTabs: "关闭全部普通标签页",
closeAllFixedTabs: "关闭全部固定标签页", closeAllFixedTabs: "关闭全部固定标签页",
copyName: "复制名称", copyName: "复制名称",
name: "名称",
fullPath: "完整路径",
copyFinalProxyPort: "复制最终代理端口", copyFinalProxyPort: "复制最终代理端口",
finalProxyPortCopied: "最终代理端口 {port} 已复制", finalProxyPortCopied: "最终代理端口 {port} 已复制",
setDefaultDatabase: "设为默认数据库", setDefaultDatabase: "设为默认数据库",
+2
View File
@@ -2559,6 +2559,8 @@ export default withEnglishFallback({
closeAllRegularTabs: "關閉全部普通分頁", closeAllRegularTabs: "關閉全部普通分頁",
closeAllFixedTabs: "關閉全部固定分頁", closeAllFixedTabs: "關閉全部固定分頁",
copyName: "複製名稱", copyName: "複製名稱",
name: "名稱",
fullPath: "完整路徑",
copyFinalProxyPort: "複製最終代理連接埠", copyFinalProxyPort: "複製最終代理連接埠",
finalProxyPortCopied: "最終代理連接埠 {port} 已複製", finalProxyPortCopied: "最終代理連接埠 {port} 已複製",
setDefaultDatabase: "設為預設資料庫", setDefaultDatabase: "設為預設資料庫",
@@ -45,6 +45,7 @@ const sourceNodeTypes = new Set<TreeNodeType>(["materialized_view", "procedure",
const savedSqlNodeTypes = new Set<TreeNodeType>(["saved-sql-file"]); const savedSqlNodeTypes = new Set<TreeNodeType>(["saved-sql-file"]);
const tableChildGroupNodeTypes = new Set<TreeNodeType>(["group-columns", "group-indexes", "group-fkeys", "group-triggers", "group-constraints", "group-partitions", "group-table-partitions", "group-table-subpartitions"]); const tableChildGroupNodeTypes = new Set<TreeNodeType>(["group-columns", "group-indexes", "group-fkeys", "group-triggers", "group-constraints", "group-partitions", "group-table-partitions", "group-table-subpartitions"]);
const databaseChildGroupNodeTypes = new Set<TreeNodeType>(["group-tables", "group-views", "group-materialized-views", "group-procedures", "group-functions", "group-triggers", "group-sequences", "group-synonyms", "group-packages", "group-types"]); const databaseChildGroupNodeTypes = new Set<TreeNodeType>(["group-tables", "group-views", "group-materialized-views", "group-procedures", "group-functions", "group-triggers", "group-sequences", "group-synonyms", "group-packages", "group-types"]);
const displayPathObjectNodeTypes = new Set<TreeNodeType>(["table", "view", "materialized_view", "procedure", "function", "trigger"]);
export function objectSourceKindForTreeNode(type: TreeNodeType): ObjectSourceKind | null { export function objectSourceKindForTreeNode(type: TreeNodeType): ObjectSourceKind | null {
if (type === "view") return "VIEW"; if (type === "view") return "VIEW";
@@ -156,3 +157,13 @@ export function copyNameForTreeNode(node: TreeNode): string {
} }
return node.label; return node.label;
} }
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}`;
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;
}
+23
View File
@@ -91,6 +91,29 @@ test("table copy menu uses the shared single and multi-selection clipboard path"
assert.match(copySelectedNamesBody, /copyToClipboard\(nodes\.map\(copyNameForTreeNode\)\.join\("\\n"\)\)/); assert.match(copySelectedNamesBody, /copyToClipboard\(nodes\.map\(copyNameForTreeNode\)\.join\("\\n"\)\)/);
}); });
test("MySQL object name menus expose leaf and display-path copy choices", () => {
const runtimeHost = readFileSync("apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue", "utf8");
const copyNameBody = functionBody(runtimeHost, "copyName");
const copyDisplayPathBody = functionBody(runtimeHost, "copyDisplayPath");
const copyNameMenuItemBody = functionBody(runtimeHost, "copyNameMenuItem");
const connectionMenuBody = functionBody(runtimeHost, "buildConnectionSidebarMenu");
const databaseMenuBody = functionBody(runtimeHost, "buildDatabaseSidebarMenu");
const objectMenuBody = functionBody(runtimeHost, "buildObjectSidebarMenu");
assert.match(copyNameBody, /copyNameForTreeNode\(node\)/);
assert.match(copyDisplayPathBody, /copyDisplayPathForTreeNode\(node, connectionName\)/);
assert.match(copyNameMenuItemBody, /currentDatabaseType\(\) === "mysql"/);
assert.match(copyNameMenuItemBody, /children: \[/);
assert.match(copyNameMenuItemBody, /t\("contextMenu\.name"\)/);
assert.match(copyNameMenuItemBody, /t\("contextMenu\.fullPath"\)/);
assert.match(copyNameMenuItemBody, /return \{ label: t\("contextMenu\.copyName"\), action: copyName, icon: Copy, shortcut: shortcutCopyName\.value \}/);
assert.doesNotMatch(connectionMenuBody, /copyNameMenuItem\(\)/);
assert.match(databaseMenuBody, /items\.push\(copyNameMenuItem\(\)\)/);
assert.match(objectMenuBody, /items\.push\(copyNameMenuItem\(\)\)/);
assert.match(objectMenuBody, /node\.type === "trigger" \? copyNameMenuItem\(\)/);
assert.match(objectMenuBody, /node\.type === "sequence"[\s\S]*action: copyName/);
});
test("successful tree table paste consumes only the clipboard used to start it", () => { test("successful tree table paste consumes only the clipboard used to start it", () => {
const runtimeHost = readFileSync("apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue", "utf8"); const runtimeHost = readFileSync("apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue", "utf8");
const confirmPasteTableBody = functionBody(runtimeHost, "confirmPasteTable"); const confirmPasteTableBody = functionBody(runtimeHost, "confirmPasteTable");
+89 -1
View File
@@ -1,6 +1,6 @@
import { afterAll, beforeAll, test, vi } from "vitest"; import { afterAll, beforeAll, test, vi } from "vitest";
import assert from "node:assert/strict"; import assert from "node:assert/strict";
import { copyNameForTreeNode, isDocumentBrowserTreeNode, objectSourceKindForTreeNode, shouldRunTreeNodeRowAction, sidebarSelectionCopyAction, treeNodeRowAction, treeNodeRowDoubleClickAction } from "../../apps/desktop/src/lib/sidebar/treeNodeClick.ts"; import { copyDisplayPathForTreeNode, copyNameForTreeNode, isDocumentBrowserTreeNode, objectSourceKindForTreeNode, shouldRunTreeNodeRowAction, sidebarSelectionCopyAction, treeNodeRowAction, treeNodeRowDoubleClickAction } from "../../apps/desktop/src/lib/sidebar/treeNodeClick.ts";
beforeAll(() => vi.stubGlobal("navigator", { platform: "Linux x86_64" })); beforeAll(() => vi.stubGlobal("navigator", { platform: "Linux x86_64" }));
afterAll(() => vi.unstubAllGlobals()); afterAll(() => vi.unstubAllGlobals());
@@ -193,6 +193,94 @@ test("copying database object group rows uses the parent schema or database name
); );
}); });
test("copying a MySQL display path uses connection, database, and object names", () => {
assert.equal(
copyDisplayPathForTreeNode(
{
id: "conn:app",
label: "app",
type: "database",
connectionId: "conn",
database: "app",
},
"dev-mysql",
),
"dev-mysql.app",
);
assert.equal(
copyDisplayPathForTreeNode(
{
id: "conn:app:orders",
label: "orders",
type: "table",
connectionId: "conn",
database: "app",
tableName: "orders",
},
"dev-mysql",
),
"dev-mysql.app.orders",
);
assert.equal(
copyDisplayPathForTreeNode(
{
id: "conn:app:__views:active_orders",
label: "active_orders",
type: "view",
connectionId: "conn",
database: "app",
objectName: "active_orders",
},
"dev-mysql",
),
"dev-mysql.app.active_orders",
);
assert.equal(
copyDisplayPathForTreeNode(
{
id: "conn:app:orders:__triggers:audit_orders",
label: "audit_orders",
type: "trigger",
connectionId: "conn",
database: "app",
tableName: "orders",
objectName: "audit_orders",
},
"dev-mysql",
),
"dev-mysql.app.audit_orders",
);
});
test("copying a display path rejects incomplete and synthetic nodes", () => {
assert.equal(
copyDisplayPathForTreeNode(
{
id: "conn:app:__tables",
label: "tree.tables",
type: "group-tables",
connectionId: "conn",
database: "app",
},
"dev-mysql",
),
null,
);
assert.equal(
copyDisplayPathForTreeNode(
{
id: "conn:app:orders",
label: "orders",
type: "table",
connectionId: "conn",
database: "app",
},
"",
),
null,
);
});
test("copying column rows uses the column name without type suffix", () => { test("copying column rows uses the column name without type suffix", () => {
assert.equal( assert.equal(
copyNameForTreeNode({ copyNameForTreeNode({