Skip to content

Commit

Permalink
set page to 0 when switching between tables
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelPesce committed Aug 2, 2023
1 parent d5a4e91 commit ead497a
Showing 1 changed file with 62 additions and 63 deletions.
125 changes: 62 additions & 63 deletions electron/ui/src/components/OverrideTable/OverrideTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,69 +10,6 @@ import { INFRASTRUCTURE_CAPEX_MAPPING, VARIABLE_INDEXES } from '../../assets/In
import OverrideTableRows from './OverrideTableRows';



function TablePaginationActions(props) {
const theme = useTheme();
const { count, page, rowsPerPage, onPageChange } = props;

const handleFirstPageButtonClick = (event) => {
onPageChange(event, 0);
};

const handleBackButtonClick = (event) => {
onPageChange(event, page - 1);
};

const handleNextButtonClick = (event) => {
onPageChange(event, page + 1);
};

const handleLastPageButtonClick = (event) => {
onPageChange(event, Math.max(0, Math.ceil(count / rowsPerPage) - 1));
};

return (
<Box sx={{ flexShrink: 0, ml: 2.5 }}>
<IconButton
onClick={handleFirstPageButtonClick}
disabled={page === 0}
aria-label="first page"
>
{theme.direction === 'rtl' ? <LastPageIcon /> : <FirstPageIcon />}
</IconButton>
<IconButton
onClick={handleBackButtonClick}
disabled={page === 0}
aria-label="previous page"
>
{theme.direction === 'rtl' ? <KeyboardArrowRight /> : <KeyboardArrowLeft />}
</IconButton>
<IconButton
onClick={handleNextButtonClick}
disabled={page >= Math.ceil(count / rowsPerPage) - 1}
aria-label="next page"
>
{theme.direction === 'rtl' ? <KeyboardArrowLeft /> : <KeyboardArrowRight />}
</IconButton>
<IconButton
onClick={handleLastPageButtonClick}
disabled={page >= Math.ceil(count / rowsPerPage) - 1}
aria-label="last page"
>
{theme.direction === 'rtl' ? <FirstPageIcon /> : <LastPageIcon />}
</IconButton>
</Box>
);
}

TablePaginationActions.propTypes = {
count: PropTypes.number.isRequired,
onPageChange: PropTypes.func.isRequired,
page: PropTypes.number.isRequired,
rowsPerPage: PropTypes.number.isRequired,
};


export default function OverrideTable(props) {

const {
Expand Down Expand Up @@ -102,6 +39,7 @@ export default function OverrideTable(props) {
)
setVisibleRows(tempVisibleRows)
setRows(tempRows)
setPage(0)

},[data, scenario, category])

Expand Down Expand Up @@ -333,3 +271,64 @@ const renderOutputTable = () => {
}



function TablePaginationActions(props) {
const theme = useTheme();
const { count, page, rowsPerPage, onPageChange } = props;

const handleFirstPageButtonClick = (event) => {
onPageChange(event, 0);
};

const handleBackButtonClick = (event) => {
onPageChange(event, page - 1);
};

const handleNextButtonClick = (event) => {
onPageChange(event, page + 1);
};

const handleLastPageButtonClick = (event) => {
onPageChange(event, Math.max(0, Math.ceil(count / rowsPerPage) - 1));
};

return (
<Box sx={{ flexShrink: 0, ml: 2.5 }}>
<IconButton
onClick={handleFirstPageButtonClick}
disabled={page === 0}
aria-label="first page"
>
{theme.direction === 'rtl' ? <LastPageIcon /> : <FirstPageIcon />}
</IconButton>
<IconButton
onClick={handleBackButtonClick}
disabled={page === 0}
aria-label="previous page"
>
{theme.direction === 'rtl' ? <KeyboardArrowRight /> : <KeyboardArrowLeft />}
</IconButton>
<IconButton
onClick={handleNextButtonClick}
disabled={page >= Math.ceil(count / rowsPerPage) - 1}
aria-label="next page"
>
{theme.direction === 'rtl' ? <KeyboardArrowLeft /> : <KeyboardArrowRight />}
</IconButton>
<IconButton
onClick={handleLastPageButtonClick}
disabled={page >= Math.ceil(count / rowsPerPage) - 1}
aria-label="last page"
>
{theme.direction === 'rtl' ? <FirstPageIcon /> : <LastPageIcon />}
</IconButton>
</Box>
);
}

TablePaginationActions.propTypes = {
count: PropTypes.number.isRequired,
onPageChange: PropTypes.func.isRequired,
page: PropTypes.number.isRequired,
rowsPerPage: PropTypes.number.isRequired,
};

0 comments on commit ead497a

Please sign in to comment.