Ensure that the query tool creates a new tab with the appropriate user when pressing Alt+Shift+Q. #5210 (#5350)

This commit is contained in:
Aditya Toshniwal
2022-09-23 11:19:48 +05:30
committed by GitHub
parent 98c50afe8e
commit 9a6516a8b3
7 changed files with 54 additions and 43 deletions

View File

@@ -25,7 +25,8 @@ Housekeeping
Bug fixes Bug fixes
********* *********
| `Issue #5188 <https://github.com/pgadmin-org/pgadmin4/issues/5188>`_ - Ensure that the continue/start button should be disabled if the user stops the Debugger for the procedures.
| `Issue #5210 <https://github.com/pgadmin-org/pgadmin4/issues/5210>`_ - Ensure that the query tool creates a new tab with the appropriate user when pressing Alt+Shift+Q.
| `Issue #5249 <https://github.com/pgadmin-org/pgadmin4/issues/5249>`_ - Added the ability to display the selected text from the query tool in the find/replace box. | `Issue #5249 <https://github.com/pgadmin-org/pgadmin4/issues/5249>`_ - Added the ability to display the selected text from the query tool in the find/replace box.
| `Issue #5262 <https://github.com/pgadmin-org/pgadmin4/issues/5262>`_ - Ensure that the user management dialog should not allow the same email addresses with different letter casings when creating users. | `Issue #5262 <https://github.com/pgadmin-org/pgadmin4/issues/5262>`_ - Ensure that the user management dialog should not allow the same email addresses with different letter casings when creating users.
| `Issue #5308 <https://github.com/pgadmin-org/pgadmin4/issues/5308>`_ - Ensure that the default value for a column should be used if it is made empty. | `Issue #5308 <https://github.com/pgadmin-org/pgadmin4/issues/5308>`_ - Ensure that the default value for a column should be used if it is made empty.
| `Issue #5188 <https://github.com/pgadmin-org/pgadmin4/issues/5188>`_ - Ensure that the continue/start button should be disabled if the user stops the Debugger for the procedures.

View File

@@ -284,14 +284,9 @@ def panel(trans_id):
if request.args: if request.args:
params = {k: v for k, v in request.args.items()} params = {k: v for k, v in request.args.items()}
close_url = ''
if request.form: if request.form:
params['title'] = request.form['title'] for key, val in request.form.items():
close_url = request.form['close_url'] params[key] = val
if 'sql_filter' in request.form:
params['sql_filter'] = request.form['sql_filter']
if 'query_url' in request.form:
params['query_url'] = request.form['query_url']
params['trans_id'] = trans_id params['trans_id'] = trans_id
@@ -318,7 +313,8 @@ def panel(trans_id):
params['fgcolor'] = s.fgcolor or 'black' params['fgcolor'] = s.fgcolor or 'black'
params['server_name'] = underscore_escape(s.name) params['server_name'] = underscore_escape(s.name)
params['username'] = underscore_escape(s.username) if 'user' not in params:
params['user'] = underscore_escape(s.username)
params['layout'] = get_setting('SQLEditor/Layout') params['layout'] = get_setting('SQLEditor/Layout')
params['macros'] = get_user_macros() params['macros'] = get_user_macros()
params['is_desktop_mode'] = current_app.PGADMIN_RUNTIME params['is_desktop_mode'] = current_app.PGADMIN_RUNTIME
@@ -327,7 +323,6 @@ def panel(trans_id):
return render_template( return render_template(
"sqleditor/index.html", "sqleditor/index.html",
close_url=close_url,
title=underscore_unescape(params['title']), title=underscore_unescape(params['title']),
params=json.dumps(params), params=json.dumps(params),
requirejs=True, requirejs=True,
@@ -359,15 +354,21 @@ def initialize_sqleditor(trans_id, sgid, sid, did=None):
# Read the data if present. Skipping read may cause connection # Read the data if present. Skipping read may cause connection
# reset error if data is sent from the client # reset error if data is sent from the client
if request.data: if request.data:
_ = request.data data = json.loads(request.data, encoding='utf-8')
req_args = request.args req_args = request.args
if ('recreate' in req_args and if ('recreate' in req_args and
req_args['recreate'] == '1'): req_args['recreate'] == '1'):
connect = False connect = False
kwargs = {
'user': data['user'] if 'user' in data else None,
'role': data['role'] if 'role' in data else None,
'password': None
}
is_error, errmsg, conn_id, version = _init_sqleditor( is_error, errmsg, conn_id, version = _init_sqleditor(
trans_id, connect, sgid, sid, did) trans_id, connect, sgid, sid, did, **kwargs)
if is_error: if is_error:
return errmsg return errmsg
@@ -2437,8 +2438,9 @@ def clear_query_history(trans_id):
status, error_msg, conn, trans_obj, session_ob = \ status, error_msg, conn, trans_obj, session_ob = \
check_transaction_status(trans_id) check_transaction_status(trans_id)
filter = request.get_json(silent=True) filter_json = request.get_json(silent=True)
return QueryHistory.clear(current_user.id, trans_obj.sid, conn.db, filter) return QueryHistory.clear(current_user.id, trans_obj.sid, conn.db,
filter_json)
@blueprint.route( @blueprint.route(

View File

@@ -13,7 +13,6 @@ import * as toolBar from 'pgadmin.browser.toolbar';
import * as panelTitleFunc from './sqleditor_title'; import * as panelTitleFunc from './sqleditor_title';
import * as commonUtils from 'sources/utils'; import * as commonUtils from 'sources/utils';
import $ from 'jquery'; import $ from 'jquery';
import url_for from 'sources/url_for';
import _ from 'lodash'; import _ from 'lodash';
import pgWindow from 'sources/window'; import pgWindow from 'sources/window';
import pgAdmin from 'sources/pgadmin'; import pgAdmin from 'sources/pgadmin';
@@ -258,7 +257,7 @@ export default class SQLEditor {
} }
openQueryToolPanel(trans_id, is_query_tool, panel_title, closeUrl, queryToolForm) { openQueryToolPanel(trans_id, is_query_tool, panel_title, queryToolForm) {
let self = this; let self = this;
let browser_preferences = pgBrowser.get_preferences_for_module('browser'); let browser_preferences = pgBrowser.get_preferences_for_module('browser');
let propertiesPanel = pgBrowser.docker.findPanels('properties'); let propertiesPanel = pgBrowser.docker.findPanels('properties');
@@ -310,21 +309,24 @@ export default class SQLEditor {
openQueryToolURL(queryToolPanel); openQueryToolURL(queryToolPanel);
} }
launch(trans_id, panel_url, is_query_tool, panel_title, sURL=null, sql_filter=null) { launch(trans_id, panel_url, is_query_tool, panel_title, params={}) {
const self = this; const self = this;
let closeUrl = url_for('sqleditor.close', {'trans_id': trans_id});
let queryToolForm = ` let queryToolForm = `
<form id="queryToolForm" action="${panel_url}" method="post"> <form id="queryToolForm" action="${panel_url}" method="post">
<input id="title" name="title" hidden /> <input id="title" name="title" hidden />`;
<input id="conn_title" name="conn_title" hidden />
<input name="close_url" value="${closeUrl}" hidden />`;
if(sURL && typeof(sURL) === 'string'){ if(params.query_url && typeof(params.query_url) === 'string'){
queryToolForm +=`<input name="query_url" value="${sURL}" hidden />`; queryToolForm +=`<input name="query_url" value="${params.query_url}" hidden />`;
} }
if(sql_filter) { if(params.sql_filter) {
queryToolForm +=`<textarea name="sql_filter" hidden>${sql_filter}</textarea>`; queryToolForm +=`<textarea name="sql_filter" hidden>${params.sql_filter}</textarea>`;
}
if(params.user) {
queryToolForm +=`<input name="user" value="${_.escape(params.user)}" hidden />`;
}
if(params.role) {
queryToolForm +=`<input name="role" value="${_.escape(params.role)}" hidden />`;
} }
/* Escape backslashes as it is stripped by back end */ /* Escape backslashes as it is stripped by back end */
@@ -354,7 +356,7 @@ export default class SQLEditor {
/* On successfully initialization find the dashboard panel, /* On successfully initialization find the dashboard panel,
* create new panel and add it to the dashboard panel. * create new panel and add it to the dashboard panel.
*/ */
self.openQueryToolPanel(trans_id, is_query_tool, panel_title, closeUrl, queryToolForm); self.openQueryToolPanel(trans_id, is_query_tool, panel_title, queryToolForm);
} }
return true; return true;
} }

View File

@@ -100,14 +100,14 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
sgid: params.sgid, sgid: params.sgid,
sid: params.sid, sid: params.sid,
did: params.did, did: params.did,
user: _.unescape(params.username), user: _.unescape(params.user),
role: null, role: _.unescape(params.role),
title: _.unescape(params.title), title: _.unescape(params.title),
fgcolor: params.fgcolor, fgcolor: params.fgcolor,
bgcolor: params.bgcolor, bgcolor: params.bgcolor,
conn_title: getTitle( conn_title: getTitle(
pgAdmin, null, selectedNodeInfo, true, _.unescape(params.server_name), _.unescape(params.database_name) || getDatabaseLabel(selectedNodeInfo), pgAdmin, null, selectedNodeInfo, true, _.unescape(params.server_name), _.unescape(params.database_name) || getDatabaseLabel(selectedNodeInfo),
_.unescape(params.username), params.is_query_tool == 'true' ? true : false), _.unescape(params.role) || _.unescape(params.user), params.is_query_tool == 'true' ? true : false),
server_name: _.unescape(params.server_name), server_name: _.unescape(params.server_name),
database_name: _.unescape(params.database_name) || getDatabaseLabel(selectedNodeInfo), database_name: _.unescape(params.database_name) || getDatabaseLabel(selectedNodeInfo),
is_selected: true, is_selected: true,
@@ -259,7 +259,10 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
...qtState.params, ...qtState.params,
}); });
} }
api.post(baseUrl, qtState.params.is_query_tool ? null : JSON.stringify(qtState.params.sql_filter)) api.post(baseUrl, qtState.params.is_query_tool ? {
user: qtState.params.user,
role: qtState.params.role,
} : JSON.stringify(qtState.params.sql_filter))
.then(()=>{ .then(()=>{
setQtState({ setQtState({
connected: true, connected: true,
@@ -578,7 +581,7 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
sid: data.sid, sid: data.sid,
did: data.did, did: data.did,
user: data.user, user: data.user,
role: data.role ?? null, role: data.role,
password: data.password, password: data.password,
title: getTitle(pgAdmin, qtState.preferences.browser, null, false, data.server_name, data.database_name, data.role || data.user, true), title: getTitle(pgAdmin, qtState.preferences.browser, null, false, data.server_name, data.database_name, data.role || data.user, true),
conn_title: getTitle(pgAdmin, null, null, true, data.server_name, data.database_name, data.role || data.user, true), conn_title: getTitle(pgAdmin, null, null, true, data.server_name, data.database_name, data.role || data.user, true),
@@ -629,8 +632,11 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
}; };
const gridUrl = showQueryTool.generateUrl(transId, parentData, null); const gridUrl = showQueryTool.generateUrl(transId, parentData, null);
const title = getTitle(pgAdmin, qtState.preferences.browser, null, false, selectedConn.server_name, selectedConn.database_name, selectedConn.user); const title = getTitle(pgAdmin, qtState.preferences.browser, null, false, selectedConn.server_name, selectedConn.database_name, selectedConn.role || selectedConn.user);
showQueryTool.launchQueryTool(pgWindow.pgAdmin.Tools.SQLEditor, transId, gridUrl, title, ''); showQueryTool.launchQueryTool(pgWindow.pgAdmin.Tools.SQLEditor, transId, gridUrl, title, {
user: selectedConn.user,
role: selectedConn.role,
});
}; };
const onManageMacros = useCallback(()=>{ const onManageMacros = useCallback(()=>{
@@ -734,7 +740,8 @@ QueryToolComponent.propTypes = {
bgcolor: PropTypes.string, bgcolor: PropTypes.string,
fgcolor: PropTypes.string, fgcolor: PropTypes.string,
is_query_tool: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]).isRequired, is_query_tool: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]).isRequired,
username: PropTypes.string, user: PropTypes.string,
role: PropTypes.string,
server_name: PropTypes.string, server_name: PropTypes.string,
database_name: PropTypes.string, database_name: PropTypes.string,
layout: PropTypes.string, layout: PropTypes.string,

View File

@@ -135,9 +135,9 @@ export function ConnectionBar({connected, connecting, connectionStatus, connecti
onClose={()=>{setConnDropdownOpen(false);}} onClose={()=>{setConnDropdownOpen(false);}}
className={classes.menu} className={classes.menu}
> >
{(connectionList||[]).map((conn)=>{ {(connectionList||[]).map((conn, i)=>{
return ( return (
<PgMenuItem key={conn.conn_title} hasCheck checked={conn.is_selected} value={conn} <PgMenuItem key={i+conn.conn_title} hasCheck checked={conn.is_selected} value={conn}
onClick={onConnItemClick}>{conn.conn_title}</PgMenuItem> onClick={onConnItemClick}>{conn.conn_title}</PgMenuItem>
); );
})} })}

View File

@@ -50,7 +50,6 @@ function generateTitle(pgBrowser, treeIdentifier) {
} }
export function showQueryTool(queryToolMod, pgBrowser, url, treeIdentifier, transId) { export function showQueryTool(queryToolMod, pgBrowser, url, treeIdentifier, transId) {
const sURL = url || '';
const queryToolTitle = generateTitle(pgBrowser, treeIdentifier); const queryToolTitle = generateTitle(pgBrowser, treeIdentifier);
const currentNode = pgBrowser.tree.findNodeByDomElement(treeIdentifier); const currentNode = pgBrowser.tree.findNodeByDomElement(treeIdentifier);
@@ -69,7 +68,7 @@ export function showQueryTool(queryToolMod, pgBrowser, url, treeIdentifier, tran
} }
const gridUrl = generateUrl(transId, parentData); const gridUrl = generateUrl(transId, parentData);
launchQueryTool(queryToolMod, transId, gridUrl, queryToolTitle, sURL); launchQueryTool(queryToolMod, transId, gridUrl, queryToolTitle, {query_url: url});
} }
export function generateScript(parentData, queryToolMod) { export function generateScript(parentData, queryToolMod) {
@@ -108,11 +107,11 @@ export function showERDSqlTool(parentData, erdSqlId, queryToolTitle, queryToolMo
}; };
const gridUrl = generateUrl(transId, parentData, erdSqlId); const gridUrl = generateUrl(transId, parentData, erdSqlId);
launchQueryTool(queryToolMod, transId, gridUrl, queryToolTitle, ''); launchQueryTool(queryToolMod, transId, gridUrl, queryToolTitle, {});
} }
export function launchQueryTool(queryToolMod, transId, gridUrl, queryToolTitle, sURL) { export function launchQueryTool(queryToolMod, transId, gridUrl, queryToolTitle, params) {
let retVal = queryToolMod.launch(transId, gridUrl, true, queryToolTitle, sURL); let retVal = queryToolMod.launch(transId, gridUrl, true, queryToolTitle, params);
if(!retVal) { if(!retVal) {
Notify.alert( Notify.alert(

View File

@@ -165,7 +165,7 @@ function showFilterDialog(pgBrowser, treeNodeInfo, queryToolMod, transId,
let helpUrl = url_for('help.static', {'filename': 'viewdata_filter.html'}); let helpUrl = url_for('help.static', {'filename': 'viewdata_filter.html'});
let okCallback = function() { let okCallback = function() {
queryToolMod.launch(transId, gridUrl, false, queryToolTitle, null, schema._sessData.filter_sql); queryToolMod.launch(transId, gridUrl, false, queryToolTitle, null, {sql_filter: schema._sessData.filter_sql});
}; };
getUtilityView(schema, treeNodeInfo, 'create', 'dialog', j[0], panel, getUtilityView(schema, treeNodeInfo, 'create', 'dialog', j[0], panel,