From f2876cabe8bc701db76987e32bd569b4bd3cba1c Mon Sep 17 00:00:00 2001 From: Anil Sahoo Date: Thu, 30 Nov 2023 18:23:52 +0530 Subject: [PATCH] 1. Fixed an issue where database name was missing in an error message if name contains any special characters. #6488 2. Add a confirmation dialog before closing a query tool when a query is already running. --- .../servers/databases/__init__.py | 4 ++- .../components/dialogs/CloseRunningDialog.jsx | 33 +++++++++++++++++++ .../js/components/sections/MainToolBar.jsx | 19 +++++++++-- 3 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 web/pgadmin/tools/sqleditor/static/js/components/dialogs/CloseRunningDialog.jsx diff --git a/web/pgadmin/browser/server_groups/servers/databases/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/__init__.py index b0e4f6b3b..87cdf4fe9 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/__init__.py @@ -34,6 +34,7 @@ from pgadmin.tools.sqleditor.utils.query_history import QueryHistory from pgadmin.tools.schema_diff.node_registry import SchemaDiffRegistry from pgadmin.model import db, Server, Database +from pgadmin.browser.utils import underscore_escape class DatabaseModule(CollectionNodeModule): @@ -1041,7 +1042,8 @@ class DatabaseView(PGChildNodeView): auto_reconnect=True) status, errmsg = conn.connect() - return internal_server_error(errormsg=msg) + return internal_server_error( + errormsg=underscore_escape(msg)) return make_json_response(success=1) diff --git a/web/pgadmin/tools/sqleditor/static/js/components/dialogs/CloseRunningDialog.jsx b/web/pgadmin/tools/sqleditor/static/js/components/dialogs/CloseRunningDialog.jsx new file mode 100644 index 000000000..7c40cc0e9 --- /dev/null +++ b/web/pgadmin/tools/sqleditor/static/js/components/dialogs/CloseRunningDialog.jsx @@ -0,0 +1,33 @@ +import React from 'react'; +import { useModalStyles } from '../../../../../../static/js/helpers/ModalProvider'; +import gettext from 'sources/gettext'; +import { Box } from '@material-ui/core'; +import { DefaultButton, PrimaryButton } from '../../../../../../static/js/components/Buttons'; +import CloseIcon from '@material-ui/icons/CloseRounded'; +import CheckRoundedIcon from '@material-ui/icons/CheckRounded'; +import HTMLReactParser from 'html-react-parser'; +import PropTypes from 'prop-types'; + +export default function CloseRunningDialog({closeModal, text, onYes}) { + const classes = useModalStyles(); + return ( + + {typeof(text) == 'string' ? HTMLReactParser(text) : text} + + } onClick={()=>{ + closeModal(); + }} >{gettext('No')} + } onClick={()=>{ + onYes?.(); + closeModal(); + }} >{gettext('Yes')} + + + ); +} + +CloseRunningDialog.propTypes = { + closeModal: PropTypes.func, + text: PropTypes.string, + onYes: PropTypes.func, +}; diff --git a/web/pgadmin/tools/sqleditor/static/js/components/sections/MainToolBar.jsx b/web/pgadmin/tools/sqleditor/static/js/components/sections/MainToolBar.jsx index 59f11d42a..2518df0bf 100644 --- a/web/pgadmin/tools/sqleditor/static/js/components/sections/MainToolBar.jsx +++ b/web/pgadmin/tools/sqleditor/static/js/components/sections/MainToolBar.jsx @@ -35,6 +35,7 @@ import CustomPropTypes from '../../../../../../static/js/custom_prop_types'; import ConfirmTransactionContent from '../dialogs/ConfirmTransactionContent'; import { isMac } from '../../../../../../static/js/keyboard_shortcuts'; import { LayoutDocker } from '../../../../../../static/js/helpers/Layout'; +import CloseRunningDialog from '../dialogs/CloseRunningDialog'; const useStyles = makeStyles((theme)=>({ root: { @@ -288,8 +289,22 @@ export function MainToolBar({containerRef, onFilterClick, onManageMacros}) { }; const warnTxnClose = ()=>{ if(!isInTxn() || !queryToolCtx.preferences?.sqleditor.prompt_commit_transaction) { - eventBus.fireEvent(QUERY_TOOL_EVENTS.FORCE_CLOSE_PANEL); - return; + /* This will show Close query tool dialog if there is any query running and transaction is active i.e queryToolConnCtx.connectionStatus is 1 */ + if(queryToolConnCtx.connectionStatus==CONNECTION_STATUS.TRANSACTION_STATUS_ACTIVE){ + queryToolCtx.modal.showModal(gettext('Close query tool?'), (closeModal)=>( + { + eventBus.fireEvent(QUERY_TOOL_EVENTS.FORCE_CLOSE_PANEL); + }} + /> + )); + return; + } else { + eventBus.fireEvent(QUERY_TOOL_EVENTS.FORCE_CLOSE_PANEL); + return; + } } queryToolCtx.modal.showModal(gettext('Commit transaction?'), (closeModal)=>(