Skip to content

Commit 14dec7e

Browse files
authored
Add support for showing the column data type beside column name in the object explorer. #8968
1 parent 5e472ec commit 14dec7e

File tree

10 files changed

+42
-3
lines changed

10 files changed

+42
-3
lines changed
-100 KB
Loading

docs/en_US/preferences.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ Use the fields on the *Display* panel to specify general display preferences:
6060
all the shared servers from the object explorer. **Note:** This option is visible only when
6161
pgAdmin is running in server mode.
6262

63+
* When the *Show column data type?* switch is turned off, then the data types
64+
of the columns will not be displayed alongside their column names.
65+
6366
* When the *Show empty object collections?* switch is turned off, then all object
6467
collections which are empty will be hidden from browser tree.
6568

web/pgadmin/browser/register_browser_preferences.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ def register_browser_preferences(self):
3333
)
3434
)
3535

36+
self.show_column_datatype = self.preference.register(
37+
'display', 'show_column_datatype',
38+
gettext("Show column data type?"), 'boolean', True,
39+
category_label=PREF_LABEL_DISPLAY,
40+
help_str=gettext(
41+
'If turned off, then the data types of the columns '
42+
'will not be displayed alongside their column names.'
43+
)
44+
)
45+
3646
self.show_user_defined_templates = self.preference.register(
3747
'display', 'show_user_defined_templates',
3848
gettext("Show template databases?"), 'boolean', False,

web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,8 @@ def nodes(self, gid, sid, did, scid, tid, clid=None):
305305
row['name'],
306306
icon="icon-column",
307307
datatype=row['datatype'], # We need datatype somewhere in,
308-
description=row['description']
308+
description=row['description'],
309+
displaytypname=row['displaytypname'],
309310
),
310311
status=200
311312
)
@@ -318,7 +319,8 @@ def nodes(self, gid, sid, did, scid, tid, clid=None):
318319
row['name'],
319320
icon="icon-column",
320321
datatype=row['datatype'], # We need datatype somewhere in
321-
description=row['description']
322+
description=row['description'],
323+
displaytypname=row['displaytypname'],
322324
)) # exclusion constraint.
323325

324326
return make_json_response(

web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/static/js/column.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import { getNodeColumnSchema } from './column.ui';
1111
import _ from 'lodash';
12+
import usePreferences from '../../../../../../../../../preferences/static/js/store';
1213

1314
define('pgadmin.node.column', [
1415
'sources/gettext', 'sources/url_for', 'pgadmin.browser',
@@ -41,6 +42,14 @@ define('pgadmin.node.column', [
4142
sqlAlterHelp: 'sql-altertable.html',
4243
sqlCreateHelp: 'sql-altertable.html',
4344
dialogHelp: url_for('help.static', {'filename': 'column_dialog.html'}),
45+
// Overriding getNodeInfoLabel to add datatype alongside column name
46+
getNodeInfoLabel: function(data) {
47+
let show_column_datatype = usePreferences.getState().getPreferences('browser', 'show_column_datatype');
48+
if (show_column_datatype?.value && data.datatype && data.displaytypname) {
49+
return data.displaytypname;
50+
}
51+
return null;
52+
},
4453
canDrop: function(itemData, item){
4554
let node = pgBrowser.tree.findNodeByDomElement(item);
4655

web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/columns/sql/default/nodes.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
SELECT DISTINCT att.attname as name, att.attnum as OID, pg_catalog.format_type(ty.oid,NULL) AS datatype,
2+
pg_catalog.format_type(ty.oid,att.atttypmod) AS displaytypname,
23
att.attnotnull as not_null,
34
CASE WHEN att.atthasdef OR att.attidentity != '' OR ty.typdefault IS NOT NULL THEN True
45
ELSE False END as has_default_val, des.description, seq.seqtypid

web/pgadmin/browser/static/js/node.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ define('pgadmin.browser.node', [
9999
// during the copying process of any node.
100100
return d;
101101
},
102+
getNodeInfoLabel: function(data) {
103+
// Adds an extra informational label appended to the node label.
104+
// Override this function to return a string to display, or null for no extra label.
105+
if(data.info_label)
106+
return data.info_label;
107+
else
108+
return null;
109+
},
102110
hasId: true,
103111
///////
104112
// Initialization function

web/pgadmin/preferences/static/js/components/PreferencesComponent.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ export default function PreferencesComponent({panelId}) {
267267
});
268268
} else {
269269
const requiresTreeRefresh = _data.some((s) =>
270-
['show_system_objects', 'show_empty_coll_nodes', 'hide_shared_server', 'show_user_defined_templates'].includes(s.name) || s.name.startsWith('show_node_')
270+
['show_system_objects', 'show_empty_coll_nodes', 'hide_shared_server', 'show_user_defined_templates', 'show_column_datatype'].includes(s.name) || s.name.startsWith('show_node_')
271271
);
272272

273273
let requiresFullPageRefresh = false;

web/pgadmin/static/js/components/PgTree/FileTreeItem/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ export class FileTreeItem extends React.Component<IItemRendererXProps & IItemRen
112112
<span className='file-name'>
113113
{ _.unescape(this.props.item.getMetadata('data')._label)}
114114
</span>
115+
<span className="text-muted" style={{fontSize: '0.9em', whiteSpace: 'nowrap'}}>
116+
{_.unescape(this.props.item.getMetadata('data').info_label)}
117+
</span>
115118
<span className='children-count'>{itemChildren}</span>
116119
{tags.map((tag)=>(
117120
<div key={tag.text} className='file-tag' style={{'--tag-color': tag.color} as React.CSSProperties}>

web/pgadmin/static/js/tree/tree_nodes.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ export class ManageTreeNodes {
6060
public addNode = (_parent: string, _path: string, _data: []) => new Promise((res) => {
6161
_data.type = _data.inode ? FileType.Directory : FileType.File;
6262
_data._label = _data.label;
63+
64+
_data.info_label = pgAdmin.Browser.Nodes[_data._type]?.getNodeInfoLabel(_data);
65+
6366
_data.label = _.escape(_data.label);
6467

6568
_data.is_collection = isCollectionNode(_data._type);

0 commit comments

Comments
 (0)