Skip to content

Commit

Permalink
chore: update table pagination mui
Browse files Browse the repository at this point in the history
  • Loading branch information
RRanath committed Aug 13, 2024
1 parent 0ff39b0 commit 037c448
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 49 deletions.
67 changes: 20 additions & 47 deletions app/components/Table/Pagination.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React from 'react';
import { Dropdown, Button } from '@button-inc/bcgov-theme';
import styled from 'styled-components';
import TablePagination from '@mui/material/TablePagination';
import { IconButtonProps, TablePagination } from '@mui/material';

interface Props {
/**
Expand All @@ -25,51 +23,14 @@ export const DEFAULT_PAGE_SIZE = 20;

const PAGE_SIZE_OPTIONS = [20, 50, 100];

const paginationComponents = {
select: Dropdown,
toolbar: styled.div`
display: flex;
font-size: 0.8rem;
justify-content: flex-end;
align-items: baseline;
& > * {
margin-right: 0.5rem;
}
`,
};

const actionButtonProps = {
variant: 'secondary',
const actionButtonProps: IconButtonProps = {
size: 'small',
style: {
padding: '0.33rem 0.50rem',
marginRight: '0.2rem',
},
};

const paginationComponentsProps = {
actions: {
components: {
FirstButton: Button,
LastButton: Button,
NextButton: Button,
BackButton: Button,
},
componentsProps: {
firstButton: actionButtonProps,
lastButton: actionButtonProps,
nextButton: actionButtonProps,
backButton: actionButtonProps,
},
showFirstButton: true,
showLastButton: true,
},
select: {
size: 'small',
style: { width: '3.5rem' },
},
};

const FilterableTablePagination: React.FunctionComponent<Props> = ({
totalCount,
pageSize = DEFAULT_PAGE_SIZE,
Expand Down Expand Up @@ -97,16 +58,28 @@ const FilterableTablePagination: React.FunctionComponent<Props> = ({
className={disabled ? 'disabled' : ''}
>
<TablePagination
component="div"
rowsPerPageOptions={PAGE_SIZE_OPTIONS}
colSpan={3}
count={totalCount}
page={activePage}
rowsPerPage={pageSize}
rowsPerPageOptions={PAGE_SIZE_OPTIONS}
page={activePage}
labelRowsPerPage="Items per page:"
showFirstButton
showLastButton
slotProps={{
select: {
size: 'small',
style: { width: '3.5rem' },
},
actions: {
firstButton: actionButtonProps,
lastButton: actionButtonProps,
nextButton: actionButtonProps,
previousButton: actionButtonProps,
},
}}
onPageChange={handlePageChange}
onRowsPerPageChange={handlePageSizeChange}
labelRowsPerPage="Items per page:"
slots={paginationComponents as any}
slotProps={paginationComponentsProps as any}
/>
</td>
);
Expand Down
8 changes: 6 additions & 2 deletions app/tests/components/Table/Pagination.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,13 @@ describe('PaginationBar', () => {
</tfoot>
</table>
);
fireEvent.change(screen.getByLabelText(/items per page/i), {
target: { value: 50 },
const pageSizeSelect = screen.getByRole('combobox', {
name: /items per page/i,
});
fireEvent.mouseDown(pageSizeSelect);

const pageSizeOption = screen.getByRole('option', { name: /50/i });
fireEvent.click(pageSizeOption);

expect(handlePageSizeChange).toHaveBeenCalledWith(50);
});
Expand Down

0 comments on commit 037c448

Please sign in to comment.