Skip to content

Commit 4f4ea03

Browse files
Added preference for max lenght and css related changes.
1 parent ea859d9 commit 4f4ea03

File tree

6 files changed

+26
-12
lines changed

6 files changed

+26
-12
lines changed

web/pgadmin/static/css/style.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
@import 'node_modules/@xterm/xterm/css/xterm.css';
55

6-
@import 'node_modules/jsoneditor/dist/jsoneditor.min.css';
76
@import 'node_modules/react-checkbox-tree/lib/react-checkbox-tree.css';
87

98
@import 'node_modules/@simonwep/pickr/dist/themes/monolith.min.css';

web/pgadmin/static/js/Theme/overrides/jsoneditor.override.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@ export default function jsonEditorOverride(theme) {
8888
color: theme.palette.text.primary + ' !important',
8989
fontWeight: 'normal !important',
9090
cursor:'pointer',
91-
border: '1px solid transparent !important',
92-
margin: '0.5px !important',
9391
padding: '2px 4px !important',
92+
margin: '1px !important',
9493
},
9594

9695
'.jse-button.jse-group-button.jse-selected': {
9796
color: theme.palette.primary.contrastTextLight ?? theme.palette.primary.main + ' !important',
9897
backgroundColor: theme.palette.primary.light + ' !important',
9998
borderColor: theme.palette.primary.main + ' !important',
99+
borderRight: '1px solid ' + theme.palette.primary.main + ' !important',
100100
'&:hover':{
101101
backgroundColor: theme.palette.primary.hoverLight + ' !important',
102102
}
@@ -117,6 +117,7 @@ export default function jsonEditorOverride(theme) {
117117
},
118118

119119
'.jse-button.jse-group-button': {
120+
margin: '0 !important',
120121
height: '32px !important',
121122
borderRadius: '0 !important',
122123
},

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { styled } from '@mui/material/styles';
1111
import _ from 'lodash';
1212
import PropTypes from 'prop-types';
1313
import CustomPropTypes from '../../../../../../static/js/custom_prop_types';
14+
import usePreferences from '../../../../../../preferences/static/js/store';
1415

1516

1617
const StyledNullAndDefaultFormatter = styled(NullAndDefaultFormatter)(({theme}) => ({
@@ -41,11 +42,13 @@ const FormatterPropTypes = {
4142
column: PropTypes.object,
4243
};
4344
export function TextFormatter({row, column}) {
45+
const maxColumnDataDisplayLength = usePreferences().getPreferences('sqleditor', 'max_column_data_display_length').value;
4446
let value = row[column.key];
4547
if(!_.isNull(value) && !_.isUndefined(value)) {
4648
value = value.toString();
47-
if (value.length > 200) {
48-
value = `${value.substring(0, 200).replace(/\n/g,' ')}...`;
49+
// If the length of the value is very large then we do not render the entire value and truncate it.
50+
if (value.length > maxColumnDataDisplayLength) {
51+
value = `${value.substring(0, maxColumnDataDisplayLength).replace(/\n/g,' ')}...`;
4952
}
5053
}
5154
return (

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ function cellClassGetter(col, isSelected, dataChangeStore, rowKeyGetter){
257257
};
258258
}
259259

260-
function initialiseColumns(columns, rows, totalRowCount, columnWidthBy) {
260+
function initialiseColumns(columns, rows, totalRowCount, columnWidthBy, maxColumnDataDisplayLength) {
261261
let retColumns = [
262262
...columns,
263263
];
@@ -266,7 +266,7 @@ function initialiseColumns(columns, rows, totalRowCount, columnWidthBy) {
266266
canvasContext.font = '12px Roboto';
267267

268268
for(const col of retColumns) {
269-
col.width = getColumnWidth(col, rows, canvasContext, columnWidthBy);
269+
col.width = getColumnWidth(col, rows, canvasContext, columnWidthBy, maxColumnDataDisplayLength);
270270
col.resizable = true;
271271
col.editorOptions = {
272272
commitOnOutsideClick: false,
@@ -338,15 +338,16 @@ function formatColumns(columns, dataChangeStore, selectedColumns, onColumnSelect
338338
return retColumns;
339339
}
340340

341-
function getColumnWidth(column, rows, canvas, columnWidthBy) {
341+
function getColumnWidth(column, rows, canvas, columnWidthBy, maxColumnDataDisplayLength) {
342342
const dataWidthReducer = (longest, nextRow) => {
343343
let value = nextRow[column.key];
344344
if(_.isNull(value) || _.isUndefined(value)) {
345345
value = '';
346346
}
347347
value = value.toString();
348-
if (value.length > 200) {
349-
value = `${value.substring(0, 200)}`;
348+
// If the length of the value is very large then we do not use the entire value and truncate it.
349+
if (value.length > maxColumnDataDisplayLength) {
350+
value = `${value.substring(0, maxColumnDataDisplayLength)}`;
350351
}
351352
return longest.length > value.length ? longest : value;
352353
};
@@ -373,7 +374,7 @@ function getColumnWidth(column, rows, canvas, columnWidthBy) {
373374
}
374375

375376
export default function QueryToolDataGrid({columns, rows, totalRowCount, dataChangeStore,
376-
onSelectedCellChange, selectedColumns, onSelectedColumnsChange, columnWidthBy, startRowNum, ...props}) {
377+
onSelectedCellChange, selectedColumns, onSelectedColumnsChange, columnWidthBy, startRowNum, maxColumnDataDisplayLength, ...props}) {
377378
const [readyColumns, setReadyColumns] = useState([]);
378379
const [lastSelectedColumn, setLastSelectedColumn] = useState(null);
379380
const eventBus = useContext(QueryToolEventsContext);
@@ -431,7 +432,7 @@ export default function QueryToolDataGrid({columns, rows, totalRowCount, dataCha
431432
}), [onSelectedCellChange]);
432433

433434
useEffect(()=>{
434-
let initCols = initialiseColumns(columns, rows, totalRowCount, columnWidthBy);
435+
let initCols = initialiseColumns(columns, rows, totalRowCount, columnWidthBy, maxColumnDataDisplayLength);
435436
setReadyColumns(formatColumns(initCols, dataChangeStore, selectedColumns, onColumnSelected, onSelectedColumnsChangeWrapped, props.rowKeyGetter));
436437
}, [columns]);
437438

@@ -496,4 +497,5 @@ QueryToolDataGrid.propTypes = {
496497
rowKeyGetter: PropTypes.func,
497498
columnWidthBy: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
498499
startRowNum: PropTypes.number,
500+
maxColumnDataDisplayLength: PropTypes.number,
499501
};

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,6 +1573,7 @@ export function ResultSet() {
15731573
queryToolCtx.preferences.sqleditor.column_data_max_width :
15741574
queryToolCtx.preferences?.sqleditor?.column_data_auto_resize
15751575
}
1576+
maxColumnDataDisplayLength={queryToolCtx.preferences?.sqleditor?.max_column_data_display_length}
15761577
key={rowsResetKey}
15771578
rowKeyGetter={rowKeyGetter}
15781579
onRowsChange={onRowsChange}

web/pgadmin/tools/sqleditor/utils/query_tool_preferences.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,14 @@ def register_query_tool_preferences(self):
375375
' rows with alternating background colors.')
376376
)
377377

378+
self.max_column_data_display_length = self.preference.register(
379+
'Results_grid', 'max_column_data_display_length',
380+
gettext("Max column data display length"), 'integer',
381+
200, category_label=PREF_LABEL_RESULTS_GRID,
382+
help_str=gettext('Maximum number of characters to display in the'
383+
' data preview.')
384+
)
385+
378386
self.sql_font_size = self.preference.register(
379387
'Editor', 'sql_font_size',
380388
gettext("Font size"), 'numeric', '1',

0 commit comments

Comments
 (0)