From e95eb14651379bce43eb03ec8ca17b783a5f0489 Mon Sep 17 00:00:00 2001 From: Pradip Parkale Date: Thu, 23 Jun 2022 18:15:16 +0530 Subject: [PATCH] Fixed an issue where the connection wasn't being closed when the user switched to a new connection and closed the query tool. Fixes #7461 Fixed the 'Show activity?' issue which was missed during Dashboard porting. --- docs/en_US/release_notes_6_11.rst | 1 + web/pgadmin/dashboard/static/js/Dashboard.jsx | 98 ++++++++++--------- .../sqleditor/static/js/SQLEditorModule.js | 10 -- .../js/components/QueryToolComponent.jsx | 14 ++- .../sqleditor/templates/sqleditor/index.html | 15 --- 5 files changed, 64 insertions(+), 74 deletions(-) diff --git a/docs/en_US/release_notes_6_11.rst b/docs/en_US/release_notes_6_11.rst index 17fd9e50b..208757c36 100644 --- a/docs/en_US/release_notes_6_11.rst +++ b/docs/en_US/release_notes_6_11.rst @@ -33,4 +33,5 @@ Bug fixes | `Issue #7443 `_ - Fixed and issue where 'Use spaces' not working in the query tool. | `Issue #7453 `_ - Fixed an issue where the Database restriction is not working. | `Issue #7460 `_ - Fixed an issue where pgAdmin stuck while creating a new index. + | `Issue #7461 `_ - Fixed an issue where the connection wasn't being closed when the user switched to a new connection and closed the query tool. | `Issue #7468 `_ - Skip the history records if the JSON info can't be parsed instead of showing 'No history'. diff --git a/web/pgadmin/dashboard/static/js/Dashboard.jsx b/web/pgadmin/dashboard/static/js/Dashboard.jsx index 0367015e8..0cc839cf3 100644 --- a/web/pgadmin/dashboard/static/js/Dashboard.jsx +++ b/web/pgadmin/dashboard/static/js/Dashboard.jsx @@ -800,56 +800,58 @@ export default function Dashboard({ pageVisible={true} > )} - - - {props.dbConnected ? gettext('Database activity') : gettext('Server activity')}{' '} - - - - - {tabs.map((tabValue, i) => { - return ; - })} - - + {!_.isUndefined(preferences) && preferences.show_activity && ( + + + {props.dbConnected ? gettext('Database activity') : gettext('Server activity')}{' '} + + + + + {tabs.map((tabValue, i) => { + return ; + })} + + + + + + + + + + + + + + + - - - - - - - - - - - - - + )} ) : sid && !props.serverConnected ? ( diff --git a/web/pgadmin/tools/sqleditor/static/js/SQLEditorModule.js b/web/pgadmin/tools/sqleditor/static/js/SQLEditorModule.js index 33ed0adc1..9fa8cca64 100644 --- a/web/pgadmin/tools/sqleditor/static/js/SQLEditorModule.js +++ b/web/pgadmin/tools/sqleditor/static/js/SQLEditorModule.js @@ -288,16 +288,6 @@ export default class SQLEditor { panelTitleFunc.setQueryToolDockerTitle(queryToolPanel, is_query_tool, _.unescape(panel_title)); queryToolPanel.focus(); - // Listen on the panel closed event. - if (queryToolPanel.isVisible()) { - queryToolPanel.on(wcDocker.EVENT.CLOSED, function() { - $.ajax({ - url: closeUrl, - method: 'DELETE', - }); - }); - } - queryToolPanel.on(wcDocker.EVENT.VISIBILITY_CHANGED, function() { queryToolPanel.trigger(wcDocker.EVENT.RESIZED); }); diff --git a/web/pgadmin/tools/sqleditor/static/js/components/QueryToolComponent.jsx b/web/pgadmin/tools/sqleditor/static/js/components/QueryToolComponent.jsx index b61303397..0bb2b3fbc 100644 --- a/web/pgadmin/tools/sqleditor/static/js/components/QueryToolComponent.jsx +++ b/web/pgadmin/tools/sqleditor/static/js/components/QueryToolComponent.jsx @@ -346,6 +346,15 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN }, []); useEffect(()=>{ + const closeConn = ()=>{ + api.delete( + url_for('sqleditor.close', { + 'trans_id': qtState.params.trans_id, + }) + ); + }; + window.addEventListener('unload', closeConn); + const pushHistory = (h)=>{ api.post( url_for('sqleditor.add_query_history', { @@ -355,7 +364,10 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN ).catch((error)=>{console.error(error);}); }; eventBus.current.registerListener(QUERY_TOOL_EVENTS.PUSH_HISTORY, pushHistory); - return ()=>{eventBus.current.deregisterListener(QUERY_TOOL_EVENTS.PUSH_HISTORY, pushHistory);}; + return ()=>{ + eventBus.current.deregisterListener(QUERY_TOOL_EVENTS.PUSH_HISTORY, pushHistory); + window.removeEventListener('unload', closeConn); + }; }, [qtState.params.trans_id]); diff --git a/web/pgadmin/tools/sqleditor/templates/sqleditor/index.html b/web/pgadmin/tools/sqleditor/templates/sqleditor/index.html index bcb6a04ea..cd71864ff 100644 --- a/web/pgadmin/tools/sqleditor/templates/sqleditor/index.html +++ b/web/pgadmin/tools/sqleditor/templates/sqleditor/index.html @@ -42,21 +42,6 @@ window.pgAdmin.Tools.SQLEditor.loadComponent( document.getElementById('sqleditor-container'), {{ params|safe }}); - if(window.opener) { - $(window).on('unload', function(ev) { - $.ajax({ - method: 'DELETE', - url: '{{close_url}}' - }); - }); - } else { - $(window).on('beforeunload', function(ev) { - $.ajax({ - method: 'DELETE', - url: '{{close_url}}' - }); - }); - } }, function() { console.log(arguments); });