Skip to content

Commit 3cc67bd

Browse files
committed
Fixed review comments
1 parent 85d2921 commit 3cc67bd

File tree

3 files changed

+9
-26
lines changed

3 files changed

+9
-26
lines changed

web/pgadmin/tools/sqleditor/static/js/components/QueryToolComponent.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,6 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
881881
eol: qtState.eol,
882882
connection_list: qtState.connection_list,
883883
current_file: qtState.current_file,
884-
qtPanelId: qtPanelId,
885884
toggleQueryTool: () => setQtStatePartial((prev)=>{
886885
return {
887886
...prev,

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

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

259-
function initialiseColumns(columns, rows, totalRowCount, columnWidthBy, maxColumnDataDisplayLength, qtPanelId) {
259+
function initialiseColumns(columns, rows, totalRowCount, columnWidthBy, maxColumnDataDisplayLength) {
260260
let retColumns = [
261261
...columns,
262262
];
@@ -265,7 +265,7 @@ function initialiseColumns(columns, rows, totalRowCount, columnWidthBy, maxColum
265265
canvasContext.font = '12px Roboto';
266266

267267
for(const col of retColumns) {
268-
col.width = getColumnWidth(col, rows, canvasContext, columnWidthBy, maxColumnDataDisplayLength, qtPanelId);
268+
col.width = getColumnWidth(col, rows, canvasContext, columnWidthBy, maxColumnDataDisplayLength);
269269
col.resizable = true;
270270
col.editorOptions = {
271271
commitOnOutsideClick: false,
@@ -336,15 +336,8 @@ function formatColumns(columns, dataChangeStore, selectedColumns, onColumnSelect
336336

337337
return retColumns;
338338
}
339-
// Helper to get or initialize the widths store on window
340-
function getWidthsStore() {
341-
if (!window.pgAdminGridColumnWidths) {
342-
window.pgAdminGridColumnWidths = {};
343-
}
344-
return window.pgAdminGridColumnWidths;
345-
}
346339

347-
function getColumnWidth(column, rows, canvasContext, columnWidthBy, maxColumnDataDisplayLength, qtPanelId) {
340+
function getColumnWidth(column, rows, canvasContext, columnWidthBy, maxColumnDataDisplayLength) {
348341
const dataWidthReducer = (longest, nextRow) => {
349342
let value = nextRow[column.key];
350343
if(_.isNull(value) || _.isUndefined(value)) {
@@ -377,19 +370,15 @@ function getColumnWidth(column, rows, canvasContext, columnWidthBy, maxColumnDat
377370
}
378371
}
379372

380-
// Use window object for storing widths
381-
const widthsStore = getWidthsStore();
382-
const savedWidths = widthsStore[qtPanelId] || {};
383-
384-
return savedWidths[column.display_name] || width;
373+
if (!window.columnWidths) window.columnWidths = {};
374+
return window.columnWidths[column.display_name] || width;
385375
}
386376

387377
export default function QueryToolDataGrid({columns, rows, totalRowCount, dataChangeStore,
388378
onSelectedCellChange, selectedColumns, onSelectedColumnsChange, columnWidthBy, startRowNum, maxColumnDataDisplayLength, ...props}) {
389379
const [readyColumns, setReadyColumns] = useState([]);
390380
const [lastSelectedColumn, setLastSelectedColumn] = useState(null);
391381
const eventBus = useContext(QueryToolEventsContext);
392-
const qtPanelId = props.qtPanelId;
393382
const onColumnSelected = (columnIdx, isSelected, isShiftClick)=>{
394383
const newSelectedCols = new Set(selectedColumns);
395384
const start = isShiftClick && lastSelectedColumn ? Math.min(columnIdx, lastSelectedColumn) : columnIdx;
@@ -445,15 +434,12 @@ export default function QueryToolDataGrid({columns, rows, totalRowCount, dataCha
445434

446435
// Save column width to window object on resize
447436
const handleColumnResize = (column, width) => {
448-
const widthsStore = getWidthsStore();
449-
if (!widthsStore[qtPanelId]) {
450-
widthsStore[qtPanelId] = {};
451-
}
452-
widthsStore[qtPanelId][column.display_name] = width;
437+
if (!window.columnWidths) window.columnWidths = {};
438+
window.columnWidths[column.display_name] = width;
453439
};
454440

455441
useEffect(()=>{
456-
let initCols = initialiseColumns(columns, rows, totalRowCount, columnWidthBy, maxColumnDataDisplayLength, qtPanelId);
442+
let initCols = initialiseColumns(columns, rows, totalRowCount, columnWidthBy, maxColumnDataDisplayLength);
457443
setReadyColumns(formatColumns(initCols, dataChangeStore, selectedColumns, onColumnSelected, onSelectedColumnsChangeWrapped, props.rowKeyGetter));
458444
}, [columns]);
459445

@@ -475,7 +461,7 @@ export default function QueryToolDataGrid({columns, rows, totalRowCount, dataCha
475461
enableCellSelect={true}
476462
onCopy={handleCopy}
477463
onMultiCopy={handleCopy}
478-
onColumnResize={handleColumnResize} // <-- Add this line
464+
onColumnResize={handleColumnResize}
479465
renderers={{
480466
renderRow: renderCustomRow,
481467
}}
@@ -520,5 +506,4 @@ QueryToolDataGrid.propTypes = {
520506
columnWidthBy: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
521507
startRowNum: PropTypes.number,
522508
maxColumnDataDisplayLength: PropTypes.number,
523-
qtPanelId: PropTypes.string,
524509
};

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1549,7 +1549,6 @@ export function ResultSet() {
15491549
onSelectedCellChange={setSelectedCell}
15501550
onSelectedRangeChange={setSelectedRange}
15511551
stripedRows={queryToolCtx.preferences?.sqleditor?.striped_rows}
1552-
qtPanelId={queryToolCtx.qtPanelId}
15531552
/>
15541553
</Box>
15551554
</>}

0 commit comments

Comments
 (0)