Skip to content

Commit 657b0f8

Browse files
Fixed an issue where query tool throws syntax error if a newly added row is untouched and saved. #8028
Fixed an issue where auto-width of wide columns in data output is incorrectly calculated. #8158
1 parent 2813d82 commit 657b0f8

File tree

4 files changed

+29
-24
lines changed

4 files changed

+29
-24
lines changed

docs/en_US/release_notes_8_14.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ New features
2525
| `Issue #5786 <https://github.com/pgadmin-org/pgadmin4/issues/5786>`_ - Allow the use of a pgpass file in the pgAdmin container via Docker secrets.
2626
| `Issue #6592 <https://github.com/pgadmin-org/pgadmin4/issues/6592>`_ - Fixed multiple issues and improved ERD auto-layout.
2727
| `Issue #8095 <https://github.com/pgadmin-org/pgadmin4/issues/8095>`_ - Added support for a builtin locale provider in the Database dialog.
28-
| `Issue #8134 <https://github.com/pgadmin-org/pgadmin4/issues/8134>`_ - Add a user preference to enable/disable alternating row background colors in the data output of query tool.
2928
3029
Housekeeping
3130
************
@@ -39,5 +38,9 @@ Bug fixes
3938
| `Issue #7486 <https://github.com/pgadmin-org/pgadmin4/issues/7486>`_ - Fixed an issue where indent with space was not aligning to next tab position.
4039
| `Issue #7865 <https://github.com/pgadmin-org/pgadmin4/issues/7865>`_ - Fixed an issue related to the query tool update connection after the server disconnected from the object explorer.
4140
| `Issue #8010 <https://github.com/pgadmin-org/pgadmin4/issues/8010>`_ - Fixed an issue where query tool should show results and messages only from the last executed query.
41+
| `Issue #8028 <https://github.com/pgadmin-org/pgadmin4/issues/8028>`_ - Fixed an issue where query tool throws syntax error if a newly added row is untouched and saved.
4242
| `Issue #8065 <https://github.com/pgadmin-org/pgadmin4/issues/8065>`_ - Ensure the crypt key is retrieved correctly on backend server restart.
43+
| `Issue #8098 <https://github.com/pgadmin-org/pgadmin4/issues/8098>`_ - Fixed an issue in schema diff where an error message popup was showing some garbage without any info.
4344
| `Issue #8127 <https://github.com/pgadmin-org/pgadmin4/issues/8127>`_ - Fixed an issue where query tool should not prompt for unsaved changes when there are no changes.
45+
| `Issue #8134 <https://github.com/pgadmin-org/pgadmin4/issues/8134>`_ - Add a user preference to enable/disable alternating row background colors in the data output of query tool.
46+
| `Issue #8158 <https://github.com/pgadmin-org/pgadmin4/issues/8158>`_ - Fixed an issue where auto-width of wide columns in data output is incorrectly calculated.

web/pgadmin/static/js/utils.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -654,15 +654,15 @@ export function requestAnimationAndFocus(ele) {
654654
});
655655
}
656656

657-
658-
export function scrollbarWidth() {
659-
// thanks too https://davidwalsh.name/detect-scrollbar-width
660-
const scrollDiv = document.createElement('div');
661-
scrollDiv.setAttribute('style', 'width: 100px; height: 100px; overflow: scroll; position:absolute; top:-9999px;');
662-
document.body.appendChild(scrollDiv);
663-
const scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth;
664-
document.body.removeChild(scrollDiv);
665-
return scrollbarWidth;
657+
export function measureText(text, font) {
658+
if(!measureText.ele) {
659+
measureText.ele = document.createElement('div');
660+
measureText.ele.style.cssText = `position: absolute; visibility: hidden; white-space: nowrap; font: ${font}`;
661+
document.body.appendChild(measureText.ele);
662+
}
663+
measureText.ele.innerHTML = text;
664+
const dim = measureText.ele.getBoundingClientRect();
665+
return {width: dim.width, height: dim.height};
666666
}
667667

668668
const CHART_THEME_COLORS = {

web/pgadmin/tools/sqleditor/static/js/components/QueryToolDataGrid/index.jsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import PropTypes from 'prop-types';
2323
import gettext from 'sources/gettext';
2424
import PgReactDataGrid from '../../../../../../static/js/components/PgReactDataGrid';
2525
import { isMac } from '../../../../../../static/js/keyboard_shortcuts';
26+
import { measureText } from '../../../../../../static/js/utils';
2627

2728
export const ROWNUM_KEY = '$_pgadmin_rownum_key_$';
2829
export const GRID_ROW_SELECT_KEY = '$_pgadmin_gridrowselect_key_$';
@@ -271,7 +272,7 @@ function initialiseColumns(columns, rows, totalRowCount, columnWidthBy) {
271272
canvasContext.font = '12px Roboto';
272273

273274
for(const col of retColumns) {
274-
col.width = getTextWidth(col, rows, canvasContext, columnWidthBy);
275+
col.width = getColumnWidth(col, rows, canvasContext, columnWidthBy);
275276
col.resizable = true;
276277
col.renderEditCellOptions = {
277278
commitOnOutsideClick: false,
@@ -347,7 +348,7 @@ function formatColumns(columns, dataChangeStore, selectedColumns, onSelectedColu
347348
return retColumns;
348349
}
349350

350-
function getTextWidth(column, rows, canvas, columnWidthBy) {
351+
function getColumnWidth(column, rows, canvas, columnWidthBy) {
351352
const dataWidthReducer = (longest, nextRow) => {
352353
let value = nextRow[column.key];
353354
if(_.isNull(value) || _.isUndefined(value)) {
@@ -358,25 +359,23 @@ function getTextWidth(column, rows, canvas, columnWidthBy) {
358359
};
359360

360361
let columnHeaderLen = column.display_name.length > column.display_type.length ?
361-
canvas.measureText(column.display_name).width : canvas.measureText(column.display_type).width;
362-
/* padding 12, icon-width 15 */
363-
columnHeaderLen += 15 + 12;
362+
measureText(column.display_name, '12px Roboto').width : measureText(column.display_type, '12px Roboto').width;
363+
/* padding 12, margin 4, icon-width 15, */
364+
columnHeaderLen += 15 + 12 + 4;
364365
if(column.column_type_internal == 'geometry' || column.column_type_internal == 'geography') {
365366
columnHeaderLen += 40;
366367
}
367368
let width = columnHeaderLen;
368369
if(typeof(columnWidthBy) == 'number') {
369-
/* padding 16 */
370-
width = 16 + Math.ceil(canvas.measureText(rows.reduce(dataWidthReducer, '')).width);
370+
/* padding 16, border 1px */
371+
width = 16 + measureText(rows.reduce(dataWidthReducer, ''), '12px Roboto').width + 1;
371372
if(width > columnWidthBy && columnWidthBy > 0) {
372373
width = columnWidthBy;
373374
}
374375
if(width < columnHeaderLen) {
375376
width = columnHeaderLen;
376377
}
377378
}
378-
/* Gracefull */
379-
width += 8;
380379
return width;
381380
}
382381

web/pgadmin/tools/sqleditor/static/js/components/sections/ResultSet.jsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -675,15 +675,18 @@ export class ResultSetUtils {
675675
return retVal;
676676
}
677677
let copiedRowsObjects = [];
678-
try {
679-
/* If the raw row objects are available, use to them identify null values */
680-
copiedRowsObjects = JSON.parse(localStorage.getItem('copied-rows'));
681-
} catch {/* Suppress the error */}
678+
if(fromClipboard) {
679+
try {
680+
/* If the raw row objects are available, use to them identify null values */
681+
copiedRowsObjects = JSON.parse(localStorage.getItem('copied-rows'));
682+
} catch {/* Suppress the error */}
683+
}
682684
for(const [recIdx, rec] of result?.entries()??[]) {
683685
// Convert 2darray to dict.
684686
let rowObj = {};
685687
for(const col of columns) {
686-
let columnVal = rec[col.pos];
688+
// if column data is undefined and there is not default value then set it to null.
689+
let columnVal = rec[col.pos] ?? (col.has_default_val ? undefined : null);
687690
/* If the source is clipboard, then it needs some extra handling */
688691
if(fromClipboard) {
689692
columnVal = this.processClipboardVal(columnVal, col, copiedRowsObjects[recIdx]?.[col.key], pasteSerials);

0 commit comments

Comments
 (0)