Skip to content

Commit

Permalink
Fix issues found while testing pagination changes. #1780
Browse files Browse the repository at this point in the history
  • Loading branch information
adityatoshniwal committed Nov 7, 2024
1 parent 772c6ec commit 3417186
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 33 deletions.
6 changes: 1 addition & 5 deletions web/pgadmin/misc/bgprocess/processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,7 @@ def random_number(size):
import secrets
import string

return ''.join(
secrets.choice(
string.ascii_uppercase + string.digits
) for _ in range(size)
)
return ''.join(secrets.choice(string.digits) for _ in range(size))

created = False
size = 0
Expand Down
4 changes: 2 additions & 2 deletions web/pgadmin/static/js/components/PgReactDataGrid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const StyledReactDataGrid = styled(ReactDataGrid)(({theme})=>({
'&[aria-colindex="1"]': {
padding: 0,
},
'&[aria-selected=true]:not([role="columnheader"])': {
'&[aria-selected=true]:not([aria-colindex="1"]):not([role="columnheader"])': {
outlineWidth: '0px',
outlineOffset: '0px',
},
Expand Down Expand Up @@ -61,7 +61,7 @@ const StyledReactDataGrid = styled(ReactDataGrid)(({theme})=>({
},
'&.ReactGrid-cellSelection': {
'& .rdg-cell': {
'&[aria-selected=true]:not([role="columnheader"])': {
'&[aria-selected=true]:not([aria-colindex="1"]):not([role="columnheader"])': {
outlineWidth: '1px',
outlineOffset: '-1px',
backgroundColor: theme.palette.primary.light,
Expand Down
2 changes: 1 addition & 1 deletion web/pgadmin/static/js/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import pgAdmin from 'sources/pgadmin';
export function minMaxValidator(label, value, minValue, maxValue) {
if((_.isUndefined(value) || _.isNull(value) || String(value) === ''))
return null;
if (!_.isUndefined(minValue) && value < minValue) {
if (!_.isUndefined(minValue) && (value < minValue || value === '-')) {
return sprintf(pgAdmin.Browser.messages.MUST_GR_EQ, label, minValue);
} else if (!_.isUndefined(maxValue) && value > maxValue) {
return sprintf(pgAdmin.Browser.messages.MUST_LESS_EQ, label, maxValue);
Expand Down
14 changes: 10 additions & 4 deletions web/pgadmin/tools/psql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,16 @@ def non_windows_platform(parent, p, fd, data, max_read_bytes, sid):
timeout = 0
# module provides access to platform-specific I/O
# monitoring functions
(data_ready, _, _) = select.select([parent, fd], [], [],
timeout)

read_terminal_data(parent, data_ready, max_read_bytes, sid)
try:
(data_ready, _, _) = select.select([parent, fd], [], [],
timeout)

read_terminal_data(parent, data_ready, max_read_bytes, sid)
except OSError as e:
# If the process is killed, bad file descriptor exception may
# occur. Handle it gracefully
if p.poll() is not None:
raise e


def pty_handel_io(connection_data, data, sid):
Expand Down
4 changes: 2 additions & 2 deletions web/pgadmin/tools/sqleditor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ def poll(trans_id):
pagination = {
'page_size': page_size,
'page_count': math.ceil(conn.total_rows / page_size),
'page_no': math.floor(rows_fetched_from / page_size) + 1,
'page_no': math.floor((rows_fetched_from - 1) / page_size) + 1,
'rows_from': rows_fetched_from,
'rows_to': rows_fetched_to
}
Expand Down Expand Up @@ -1197,7 +1197,7 @@ def fetch_window(trans_id, from_rownum=0, to_rownum=0):
pagination = {
'page_size': page_size,
'page_count': math.ceil(conn.total_rows / page_size),
'page_no': math.floor(rows_fetched_from / page_size) + 1,
'page_no': math.floor((rows_fetched_from - 1) / page_size) + 1,
'rows_from': rows_fetched_from,
'rows_to': rows_fetched_to
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ const StyledPgReactDataGrid = styled(PgReactDataGrid)(({theme})=>({
'& .rdg-cell:nth-of-type(1)': {
backgroundColor: theme.palette.grey[600],
},
'& .rdg-cell:nth-of-type(1)[aria-selected="true"]':{
backgroundColor: theme.palette.primary.main,
color: theme.palette.primary.contrastText,
},
'&[aria-selected="true"] .rdg-cell:nth-of-type(1)': {
backgroundColor: theme.palette.primary.main,
color: theme.palette.primary.contrastText,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -868,15 +868,19 @@ export function ResultSet() {
eventBus.fireEvent(QUERY_TOOL_EVENTS.SELECTED_ROWS_COLS_CELL_CHANGED, selectedRows.size, selectedColumns.size, selectedRange.current, selectedCell.current?.length);
};

const resetSelectionAndChanges = ()=>{
dispatchDataChange({type: 'reset'});
setSelectedRows(new Set());
setSelectedColumns(new Set());
};

const executionStartCallback = async (query, {
explainObject, macroSQL, external=false, reconnect=false, executeCursor=false, refreshData=false
})=>{
const yesCallback = async ()=>{
/* Reset */
eventBus.fireEvent(QUERY_TOOL_EVENTS.HIGHLIGHT_ERROR, null);
dispatchDataChange({type: 'reset'});
setSelectedRows(new Set());
setSelectedColumns(new Set());
resetSelectionAndChanges();
rsu.current.resetClientPKIndex();
setLoaderText(gettext('Waiting for the query to complete...'));
setDataOutputQuery(query);
Expand Down Expand Up @@ -1110,6 +1114,7 @@ export function ResultSet() {
pageDataDirty.current = false;
fetchWindow(...args);
}
resetSelectionAndChanges();
});
return ()=>{
deregFetch();
Expand Down Expand Up @@ -1234,9 +1239,7 @@ export function ResultSet() {
});
setColumns((prev)=>prev);
}
dispatchDataChange({type: 'reset'});
setSelectedRows(new Set());
setSelectedColumns(new Set());
resetSelectionAndChanges();
eventBus.fireEvent(QUERY_TOOL_EVENTS.SET_CONNECTION_STATUS, respData.data.transaction_status);
eventBus.fireEvent(QUERY_TOOL_EVENTS.SET_MESSAGE, '');
pgAdmin.Browser.notifier.success(gettext('Data saved successfully.'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import PropTypes from 'prop-types';
import CodeMirror from '../../../../../../static/js/components/ReactCodeMirror';
import { setEditorPosition } from '../QueryToolDataGrid/Editors';
import { InputText } from '../../../../../../static/js/components/FormComponents';
import { minMaxValidator } from '../../../../../../static/js/validators';
import { isEmptyString, minMaxValidator } from '../../../../../../static/js/validators';

const StyledDiv = styled('div')(({theme})=>({
padding: '2px',
Expand Down Expand Up @@ -111,6 +111,7 @@ function PaginationInputs({pagination, totalRowCount, clearSelection}) {
from: pagination.rows_from ?? 0,
to: pagination.rows_to ?? 0,
pageNo: pagination.page_no ?? 0,
pageCount: pagination.page_count ?? 0,
});

const goToPage = (pageNo)=>{
Expand Down Expand Up @@ -138,37 +139,48 @@ function PaginationInputs({pagination, totalRowCount, clearSelection}) {
}
};

useEffect(()=>{
setInputs({
from: pagination.rows_from ?? 0,
to: pagination.rows_to ?? 0,
pageNo: pagination.page_no ?? 0,
pageCount: pagination.page_count ?? 0,
});
}, [pagination, editPageRange]);

useEffect(()=>{
// validate
setErrorInputs((prev)=>{
let errors = {...prev};

if(minMaxValidator('', inputs.pageNo, 1, pagination.page_count)) {
if(minMaxValidator('', inputs.pageNo, 1, inputs.pageCount) || isEmptyString(inputs.pageNo)) {
errors.pageNo = true;
} else {
errors.pageNo = false;
}
if(minMaxValidator('', inputs.from, 1, inputs.to)) {
if(minMaxValidator('', inputs.from, 1, inputs.to) || isEmptyString(inputs.from)) {
errors.from = true;
} else {
errors.from = false;
}
if(minMaxValidator('', inputs.to, 1, totalRowCount)) {
if(minMaxValidator('', inputs.to, 1, totalRowCount) || isEmptyString(inputs.to)) {
errors.to = true;
} else {
errors.to = false;
}

return errors;
});
}, [inputs, pagination]);
}, [inputs]);

return (
<Box className='PaginationInputs'>
{editPageRange ?
<Box display="flex" gap="2px" alignItems="center">
<div>{gettext('Showing rows:')}</div>
<InputText size="small"
<InputText
type="int"
size="small"
controlProps={{maxLength: 7}}
style={{
maxWidth: '10ch'
Expand All @@ -179,7 +191,9 @@ function PaginationInputs({pagination, totalRowCount, clearSelection}) {
error={errorInputs['from']}
/>
<div>{gettext('to')}</div>
<InputText size="small"
<InputText
type="int"
size="small"
controlProps={{maxLength: 7}}
style={{
maxWidth: '10ch'
Expand All @@ -194,7 +208,7 @@ function PaginationInputs({pagination, totalRowCount, clearSelection}) {
{editPageRange && <PgIconButton size="xs"
title={editPageRange ? gettext('Apply (or press Enter on input)') : gettext('Edit range')}
onClick={()=>eventBus.fireEvent(QUERY_TOOL_EVENTS.FETCH_WINDOW, inputs.from, inputs.to)}
icon={<CheckRoundedIcon />}
disabled={errorInputs.from || errorInputs.to} icon={<CheckRoundedIcon />}
/>}
<PgIconButton size="xs"
title={editPageRange ? gettext('Cancel edit') : gettext('Edit range')}
Expand All @@ -204,7 +218,9 @@ function PaginationInputs({pagination, totalRowCount, clearSelection}) {
</PgButtonGroup>
<div className='PaginationInputs-divider'>&nbsp;</div>
<span>{gettext('Page No:')}</span>
<InputText size="small"
<InputText
type="int"
size="small"
controlProps={{maxLength: 7}}
style={{
maxWidth: '10ch'
Expand Down

0 comments on commit 3417186

Please sign in to comment.