Fixed an issue where changes done to a node using edit dialog are not reflecting on the properties tab if the properties tab is active. #7041

This commit is contained in:
Nikhil Mohite 2023-12-27 11:06:04 +05:30 committed by GitHub
parent 6d399f4fd7
commit a4e9f04a2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 5 deletions

View File

@ -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"""

View File

@ -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(

View File

@ -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,
};