mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-21 04:22:31 +00:00
fix(desktop): copy raw column names from tree
This commit is contained in:
@@ -79,5 +79,9 @@ export function sidebarSelectionCopyAction(event: ShortcutLikeEvent): SidebarSel
|
||||
export function copyNameForTreeNode(node: TreeNode): string {
|
||||
if (tableChildGroupNodeTypes.has(node.type) && node.tableName) return node.tableName;
|
||||
if (databaseChildGroupNodeTypes.has(node.type)) return node.schema || node.database || node.label;
|
||||
if (node.type === "column") {
|
||||
if (node.meta && "name" in node.meta) return node.meta.name;
|
||||
return node.label.replace(/\s+\(.+\)$/, "");
|
||||
}
|
||||
return node.label;
|
||||
}
|
||||
|
||||
@@ -136,3 +136,34 @@ test("copying database object group rows uses the parent schema or database name
|
||||
"db",
|
||||
);
|
||||
});
|
||||
|
||||
test("copying column rows uses the column name without type suffix", () => {
|
||||
assert.equal(
|
||||
copyNameForTreeNode({
|
||||
id: "conn:db:public:orders:__columns:status",
|
||||
label: "status (varchar)",
|
||||
type: "column",
|
||||
meta: {
|
||||
name: "status",
|
||||
data_type: "varchar",
|
||||
is_nullable: true,
|
||||
column_default: null,
|
||||
is_primary_key: false,
|
||||
extra: null,
|
||||
comment: null,
|
||||
numeric_precision: null,
|
||||
numeric_scale: null,
|
||||
character_maximum_length: null,
|
||||
},
|
||||
}),
|
||||
"status",
|
||||
);
|
||||
assert.equal(
|
||||
copyNameForTreeNode({
|
||||
id: "conn:db:public:orders:__columns:status",
|
||||
label: "status (varchar)",
|
||||
type: "column",
|
||||
}),
|
||||
"status",
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user