From a4e9f04a2e51ef142d57f6e4b91d4e2103598cab Mon Sep 17 00:00:00 2001 From: Nikhil Mohite Date: Wed, 27 Dec 2023 11:06:04 +0530 Subject: [PATCH] =?UTF-8?q?Fixed=20an=20issue=20where=20changes=20done=20t?= =?UTF-8?q?o=C2=A0a=20node=20using=20edit=20dialog=20are=20not=20reflectin?= =?UTF-8?q?g=20on=20the=20properties=20tab=20if=20the=20properties=20tab?= =?UTF-8?q?=20is=20active.=20#7041?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../browser/server_groups/servers/__init__.py | 20 ++++++++++++++++++- .../server_groups/servers/static/js/server.js | 2 ++ .../misc/properties/ObjectNodeProperties.jsx | 20 +++++++++++++++---- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/web/pgadmin/browser/server_groups/servers/__init__.py b/web/pgadmin/browser/server_groups/servers/__init__.py index 0e6591da7..192f1826b 100644 --- a/web/pgadmin/browser/server_groups/servers/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/__init__.py @@ -13,6 +13,7 @@ from flask import render_template, request, make_response, jsonify, \ current_app, url_for, session from flask_babel import gettext from flask_security import current_user, login_required +from psycopg.conninfo import make_conninfo, conninfo_to_dict from pgadmin.browser.server_groups.servers.types import ServerType from pgadmin.browser.utils import PGChildNodeView from pgadmin.utils.ajax import make_json_response, bad_request, forbidden, \ @@ -1052,6 +1053,10 @@ class ServerNode(PGChildNodeView): conn = manager.connection() connected = conn.connected() + # Get updated connection string to show on UI, if user change host, + # port and user when server is connected + display_connection_str = self.update_connection_string(manager, server) + if server.shared and server.user_id != current_user.id: shared_server = ServerModule.get_shared_server(server, gid) server = ServerModule.get_shared_server_properties(server, @@ -1116,12 +1121,25 @@ class ServerNode(PGChildNodeView): 'gss_encrypted': manager.gss_encrypted, 'cloud_status': server.cloud_status, 'connection_params': connection_params, - 'connection_string': manager.display_connection_string, + 'connection_string': display_connection_str, 'prepare_threshold': server.prepare_threshold } return ajax_response(response) + @staticmethod + def update_connection_string(manager, server): + # Get current connection info in dict. + con_info = conninfo_to_dict(manager.display_connection_string) + + # Update host, port and user + con_info['host'] = server.host + con_info['port'] = server.port + con_info['user'] = server.username + + display_conn_string = make_conninfo(**con_info) + return display_conn_string + @login_required def create(self, gid): """Add a server node to the settings database""" diff --git a/web/pgadmin/browser/server_groups/servers/static/js/server.js b/web/pgadmin/browser/server_groups/servers/static/js/server.js index d9b2a6565..4de89ca03 100644 --- a/web/pgadmin/browser/server_groups/servers/static/js/server.js +++ b/web/pgadmin/browser/server_groups/servers/static/js/server.js @@ -210,6 +210,8 @@ define('pgadmin.node.server', [ d = t.itemData(i); t.removeIcon(i); d.connected = false; + // Update server tree node data after server diconnected. + t.update(i,d); // Generate the event that server is disconnected pgBrowser.Events.trigger( diff --git a/web/pgadmin/misc/properties/ObjectNodeProperties.jsx b/web/pgadmin/misc/properties/ObjectNodeProperties.jsx index 3706184c4..0d6245260 100644 --- a/web/pgadmin/misc/properties/ObjectNodeProperties.jsx +++ b/web/pgadmin/misc/properties/ObjectNodeProperties.jsx @@ -20,7 +20,7 @@ import usePreferences from '../../preferences/static/js/store'; import PropTypes from 'prop-types'; export default function ObjectNodeProperties({panelId, node, treeNodeInfo, nodeData, actionType, formType, onEdit, onSave, onClose, - isActive, setIsStale}) { + isActive, setIsStale, isStale}) { const layoutDocker = React.useContext(LayoutDockerContext); const nodeType = nodeData?._type; const pgAdmin = usePgAdmin(); @@ -29,6 +29,8 @@ export default function ObjectNodeProperties({panelId, node, treeNodeInfo, nodeD let inCatalog = treeNodeInfo && ('catalog' in treeNodeInfo); let urlBase = generateNodeUrl.call(node, treeNodeInfo, actionType, nodeData, false, node.url_jump_after_node); const api = getApiInstance(); + // To check node data is updated or not + const staleCounter = useRef(0); const url = (isNew)=>{ return urlBase + (isNew ? '' : nodeData._id); }; @@ -196,15 +198,24 @@ export default function ObjectNodeProperties({panelId, node, treeNodeInfo, nodeD && formType !== 'tab') { schema.filterGroups = [gettext('Security')]; } + // Reset stale counter. + useEffect(()=> { + staleCounter.current = 0; + }, [nodeData?._id]); const key = useMemo(()=>{ + // If node data is updated increase the counter to show updated data. + if(isStale){ + staleCounter.current += 1; + } if( actionType != 'properties' || isActive) { - return nodeData?._id; + // Not required any action. } else { initData = ()=>Promise.resolve({}); - return nodeData?._id + '-0'; } - }, [isActive, nodeData?._id]); + + return nodeData?._id + '-' + staleCounter.current; + }, [isActive, nodeData?._id, isStale]); /* Fire at will, mount the DOM */ return ( @@ -243,4 +254,5 @@ ObjectNodeProperties.propTypes = { onClose: PropTypes.func, isActive: PropTypes.bool, setIsStale: PropTypes.func, + isStale: PropTypes.bool, };