Fix graphical explain now that JSON data is sent as text to stop JS futzing with it. Fixes #4041

This commit is contained in:
Aditya Toshniwal 2019-03-01 12:38:57 +00:00 committed by Dave Page
parent d8f9e3e87b
commit 74cfeabd02

View File

@ -2339,14 +2339,18 @@ define('tools.querytool', [
* In case of Explain draw the graph on explain panel * In case of Explain draw the graph on explain panel
* and add json formatted data to collection and render. * and add json formatted data to collection and render.
*/ */
var explain_data_array = []; var explain_data_array = [],
if ( explain_data_json = null;
data.result && data.result.length >= 1 &&
data.result[0] && data.result[0][0] && data.result[0][0][0] && if(data.types[0].typname === 'json') {
data.result[0][0][0].hasOwnProperty('Plan') && /* json is sent as text, parse it */
_.isObject(data.result[0][0][0]['Plan']) explain_data_json = JSON.parse(data.result[0]);
if (explain_data_json && explain_data_json[0] &&
explain_data_json[0].hasOwnProperty('Plan') &&
_.isObject(explain_data_json[0]['Plan'])
) { ) {
var explain_data = [JSON.stringify(data.result[0][0], null, 2)]; var explain_data = [JSON.stringify(explain_data_json, null, 2)];
explain_data_array.push(explain_data); explain_data_array.push(explain_data);
// Make sure - the 'Data Output' panel is visible, before - we // Make sure - the 'Data Output' panel is visible, before - we
// start rendering the grid. // start rendering the grid.
@ -2361,10 +2365,11 @@ define('tools.querytool', [
// start rendering the grid. // start rendering the grid.
self.gridView.explain_panel.focus(); self.gridView.explain_panel.focus();
pgExplain.DrawJSONPlan( pgExplain.DrawJSONPlan(
$('.sql-editor-explain'), data.result[0][0] $('.sql-editor-explain'), explain_data_json
); );
}, 10 }, 10
); );
}
} else { } else {
// Make sure - the 'Data Output' panel is visible, before - we // Make sure - the 'Data Output' panel is visible, before - we
// start rendering the grid. // start rendering the grid.