diff --git a/src/components/tables/TransactionsTable.tsx b/src/components/tables/TransactionsTable.tsx index a2e61ac..ae1dd15 100644 --- a/src/components/tables/TransactionsTable.tsx +++ b/src/components/tables/TransactionsTable.tsx @@ -184,10 +184,10 @@ export function TransactionsTable(props: TransactionTableProps) { const _IsLoading = isLoading; - useEffect(() => { - filter.offset = 0; - setFilter(filter); - }, [filter.limit]); + // useEffect(() => { + // filter.offset = 0; + // setFilter(filter); + // }, [filter.limit]); return ( <> diff --git a/src/components/ui/Pagination/index.tsx b/src/components/ui/Pagination/index.tsx index e8f366e..ff0522a 100644 --- a/src/components/ui/Pagination/index.tsx +++ b/src/components/ui/Pagination/index.tsx @@ -3,8 +3,22 @@ import { Box, Text, Select } from "grommet"; import { Filter } from "src/types"; import { FormPrevious, FormNext } from "grommet-icons"; import { formatNumber } from "src/components/ui/utils"; +import styled from "styled-components"; -export type TPaginationAction = "nextPage" | "prevPage"; +const NavigationItem = styled(Box)<{ disabled?: boolean }>` + border-radius: 4px; + height: 28px; + align-items: center; + justify-content: center; + padding: 4px 8px; + text-align: center; + background: ${(props) => props.theme.global.colors.backgroundBack}; + cursor: ${(props) => props.disabled ? 'default': 'pointer'}; + opacity: ${(props) => props.disabled ? 0.6: 1}; + border: 1px solid ${(props) => props.theme.global.colors.border}; +` + +export type TPaginationAction = "nextPage" | "prevPage" | "firstPage" | "lastPage"; interface PaginationNavigator { filter: Filter; @@ -32,6 +46,15 @@ export function PaginationNavigator(props: PaginationNavigator) { const { offset = 0, limit = 10 } = filter; + const onFirstPageClick = () => { + const newFilter = JSON.parse(JSON.stringify(filter)) as Filter; + newFilter.offset = 0; + + if (!isLoading) { + onChange(newFilter, "firstPage"); + } + }; + const onPrevClick = () => { const newFilter = JSON.parse(JSON.stringify(filter)) as Filter; newFilter.offset = newFilter.offset - (filter.limit || 10); @@ -49,17 +72,31 @@ export function PaginationNavigator(props: PaginationNavigator) { } }; + const onLastPageClick = () => { + const newFilter = JSON.parse(JSON.stringify(filter)) as Filter; + const limit = filter.limit || 10 + newFilter.offset = limit * +Math.ceil(Number(totalElements) / limit).toFixed(0) - limit + if (!isLoading) { + onChange(newFilter, "lastPage"); + } + }; + + const currentPage = +(+offset / limit).toFixed(0) + 1 + const totalPages = +Math.ceil(Number(totalElements) / limit).toFixed(0) + return ( = totalPages} /> ); @@ -68,8 +105,10 @@ interface PaginationProps { currentPage: number; totalPages: number; showPages?: boolean; + onFirstPageClick: () => void; onPrevPageClick: () => void; onNextPageClick: () => void; + onLastPageClick: () => void; disableNextBtn: boolean; disablePrevBtn: boolean; } @@ -78,38 +117,40 @@ function Pagination(props: PaginationProps) { const { currentPage, totalPages, + onFirstPageClick, onPrevPageClick, onNextPageClick, + onLastPageClick, showPages, disableNextBtn, disablePrevBtn, } = props; return ( - - - {showPages && ( - {formatNumber(+currentPage)} - )} - {showPages && /} - {showPages && ( - {formatNumber(+totalPages)} - )} - + + {showPages && + + First + + } + + + + {showPages && + + + Page {formatNumber(+currentPage)} of {formatNumber(+totalPages)} + + + } + + + + {showPages && + + Last + + } ); } @@ -134,7 +175,7 @@ export function PaginationRecordsPerPage(props: ElementsPerPage) { return ( - +