Skip to content

Commit a524eaa

Browse files
Fixed review comments.
1 parent 1a5514b commit a524eaa

3 files changed

Lines changed: 23 additions & 9 deletions

File tree

web/pgadmin/tools/sqleditor/__init__.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,9 +2200,14 @@ def download_binary_data(trans_id):
22002200
(status, error_msg, conn, trans_obj,
22012201
session_obj) = check_transaction_status(trans_id)
22022202

2203-
if error_msg:
2204-
return internal_server_error(
2205-
errormsg=error_msg
2203+
if isinstance(error_msg, Response):
2204+
return error_msg
2205+
if error_msg == ERROR_MSG_TRANS_ID_NOT_FOUND:
2206+
return make_json_response(
2207+
success=0,
2208+
errormsg=error_msg,
2209+
info='DATAGRID_TRANSACTION_REQUIRED',
2210+
status=404
22062211
)
22072212

22082213
if not status or conn is None or trans_obj is None or \
@@ -2250,7 +2255,7 @@ def download_binary_data(trans_id):
22502255
errormsg='Invalid row/column position.'
22512256
)
22522257

2253-
return send_file(
2258+
return send_file(
22542259
BytesIO(binary_data),
22552260
as_attachment=True,
22562261
download_name='binary_data',

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import GetAppRoundedIcon from '@mui/icons-material/GetAppRounded';
1717
import { PgIconButton } from '../../../../../../static/js/components/Buttons';
1818
import { QUERY_TOOL_EVENTS } from '../QueryToolConstants';
1919
import { QueryToolEventsContext } from '../QueryToolComponent';
20+
import { DataGridExtrasContext } from './index';
2021

2122
const StyledNullAndDefaultFormatter = styled(NullAndDefaultFormatter)(({theme}) => ({
2223
'& .Formatters-disabledCell': {
@@ -73,16 +74,24 @@ export function NumberFormatter({row, column}) {
7374
}
7475
NumberFormatter.propTypes = FormatterPropTypes;
7576

76-
export function BinaryFormatter({row, column, ...props}) {
77+
export function BinaryFormatter({row, column}) {
7778
let value = row[column.key];
7879
const eventBus = useContext(QueryToolEventsContext);
80+
const dataGridExtras = useContext(DataGridExtrasContext);
7981
const downloadBinaryData = usePreferences().getPreferences('misc', 'enable_binary_data_download').value;
82+
83+
// Use clientPK as the absolute row position
84+
// rowKeyGetter returns the clientPK value which is a sequential counter (0, 1, 2, ...)
85+
// that persists across pagination and represents the 0-based absolute position in the result set
86+
const absoluteRowPos = parseInt(dataGridExtras?.rowKeyGetter?.(row) ?? 0);
87+
console.log(absoluteRowPos)
88+
8089
return (
8190
<StyledNullAndDefaultFormatter value={value} column={column}>
8291
<span className='Formatters-disabledCell'>[{value}]</span>&nbsp;&nbsp;
83-
{downloadBinaryData &&
92+
{downloadBinaryData &&
8493
<PgIconButton size="xs" title={gettext('Download binary data')} icon={<GetAppRoundedIcon />}
85-
onClick={()=>eventBus.fireEvent(QUERY_TOOL_EVENTS.TRIGGER_SAVE_BINARY_DATA, props.rowIdx, column.pos)}/>}
94+
onClick={()=>eventBus.fireEvent(QUERY_TOOL_EVENTS.TRIGGER_SAVE_BINARY_DATA, absoluteRowPos, column.pos)}/>}
8695
</StyledNullAndDefaultFormatter>
8796
);
8897
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,8 @@ export default function QueryToolDataGrid({columns, rows, totalRowCount, dataCha
429429
}, []);
430430

431431
const dataGridExtras = useMemo(()=>({
432-
onSelectedCellChange, handleShortcuts, startRowNum
433-
}), [onSelectedCellChange]);
432+
onSelectedCellChange, handleShortcuts, startRowNum, rowKeyGetter: props.rowKeyGetter
433+
}), [onSelectedCellChange, props.rowKeyGetter]);
434434

435435
// Save column width to window object on resize
436436
const handleColumnResize = (column, width) => {

0 commit comments

Comments
 (0)