From ad0567bd85e3cec5249b25b01336c770a392def2 Mon Sep 17 00:00:00 2001 From: Nikhil Mohite Date: Fri, 12 Jan 2024 17:19:27 +0530 Subject: [PATCH] Add support for selecting a schema in the backup database dialog with no tables, mviews, views or foreign tables. #7053 Fixed a UI border issue on the dependencies tab for columns with icon. #7055 --- web/pgadmin/static/js/PgTreeView/index.jsx | 2 +- web/pgadmin/static/js/components/PgTable.jsx | 2 +- web/pgadmin/tools/backup/__init__.py | 13 ++++++- web/pgadmin/tools/grant_wizard/__init__.py | 40 +++++++++++++++++++- 4 files changed, 52 insertions(+), 5 deletions(-) diff --git a/web/pgadmin/static/js/PgTreeView/index.jsx b/web/pgadmin/static/js/PgTreeView/index.jsx index 51c022b37..18f40ce15 100644 --- a/web/pgadmin/static/js/PgTreeView/index.jsx +++ b/web/pgadmin/static/js/PgTreeView/index.jsx @@ -198,7 +198,7 @@ function CollectionArrow({ node, tree, selectedNodeIds }) { }; return ( - {node.isInternal ? : null} + {node.isInternal && node?.children.length > 0 ? : null} ); } diff --git a/web/pgadmin/static/js/components/PgTable.jsx b/web/pgadmin/static/js/components/PgTable.jsx index 7e347cfe3..81bc19ed6 100644 --- a/web/pgadmin/static/js/components/PgTable.jsx +++ b/web/pgadmin/static/js/components/PgTable.jsx @@ -149,7 +149,7 @@ const useStyles = makeStyles((theme) => ({ cellIcon: { paddingLeft: '1.8em', paddingTop: '0.35em', - height: 35, + borderRadius: 0, backgroundPosition: '1%', }, emptyPanel: { diff --git a/web/pgadmin/tools/backup/__init__.py b/web/pgadmin/tools/backup/__init__.py index fdfcf64d4..4e00401ce 100644 --- a/web/pgadmin/tools/backup/__init__.py +++ b/web/pgadmin/tools/backup/__init__.py @@ -580,8 +580,9 @@ def objects(sid, did, scid=None): server_info['template_path'] = 'grant_wizard/ppas/#{0}#'.format( server_info['version']) - res, msg = get_data(sid, did, scid, 'schema' if scid else 'database', - server_info) + res, msg, empty_schema_list = get_data(sid, did, scid, + 'schema' if scid else 'database', + server_info, True) tree_data = { 'table': [], @@ -643,6 +644,14 @@ def objects(sid, did, scid=None): ch['children'] = children + for empty_schema in empty_schema_list: + schema_group.append({ + 'id': empty_schema, + 'name': empty_schema, + 'icon': 'icon-schema', + 'children': [], + 'is_schema': True, + }) return make_json_response( data=schema_group, success=200 diff --git a/web/pgadmin/tools/grant_wizard/__init__.py b/web/pgadmin/tools/grant_wizard/__init__.py index a1e5187d4..7dd210d1f 100644 --- a/web/pgadmin/tools/grant_wizard/__init__.py +++ b/web/pgadmin/tools/grant_wizard/__init__.py @@ -274,7 +274,8 @@ def properties(sid, did, node_id, node_type): ) -def get_data(sid, did, node_id, node_type, server_data): +def get_data(sid, did, node_id, node_type, server_data, + return_emtpy_schema=False): get_schema_sql_url = '/sql/get_schemas.sql' # unquote encoded url parameter @@ -306,46 +307,80 @@ def get_data(sid, did, node_id, node_type, server_data): if len(res) > 0: res_data.extend(res['rows']) + empty_schema_list = [] for row in node_types: + is_empty_schema = True if 'oid' in row: node_id = row['oid'] if ntype == 'schema': status, res = _get_rows_for_type( conn, 'function', server_prop, node_id) + _append_rows(status, res, 'function') status, res = _get_rows_for_type( conn, 'procedure', server_prop, node_id) + _append_rows(status, res, 'procedure') status, res = _get_rows_for_type( conn, 'trigger_function', server_prop, node_id) + _append_rows(status, res, 'trigger function') status, res = _get_rows_for_type( conn, 'sequence', server_prop, node_id) + + if len(res['rows']): + is_empty_schema = False + _append_rows(status, res, 'sequence') status, res = _get_rows_for_type( conn, 'table', server_prop, node_id) + + if len(res['rows']): + is_empty_schema = False + _append_rows(status, res, 'table') status, res = _get_rows_for_type( conn, 'view', server_prop, node_id) + + if len(res['rows']): + is_empty_schema = False + _append_rows(status, res, 'view') status, res = _get_rows_for_type( conn, 'mview', server_prop, node_id) + + if len(res['rows']): + is_empty_schema = False + _append_rows(status, res, 'materialized view') status, res = _get_rows_for_type( conn, 'foreign_table', server_prop, node_id) + + if len(res['rows']): + is_empty_schema = False + _append_rows(status, res, 'foreign table') status, res = _get_rows_for_type( conn, 'package', server_prop, node_id) + + if (type(res) is list and len(res) > 0) or ( + 'rows' in res and len(res['rows']) > 0): + is_empty_schema = False + _append_rows(status, res, 'package') + + if is_empty_schema and row['name'] not in empty_schema_list: + empty_schema_list.append(row['name']) + else: status, res = _get_rows_for_type(conn, ntype, server_prop, node_id) _append_rows(status, res, 'function') @@ -355,6 +390,9 @@ def get_data(sid, did, node_id, node_type, server_data): msg = gettext('Unable to fetch the {} objects'.format( ", ".join(failed_objects)) ) + if return_emtpy_schema: + return res_data, msg, empty_schema_list + return res_data, msg