Skip to content

Commit

Permalink
Set the correct pagination for the table
Browse files Browse the repository at this point in the history
  • Loading branch information
kkosiorowska committed Jan 23, 2024
1 parent 4692228 commit 4b967f4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
10 changes: 6 additions & 4 deletions dapp/src/components/TransactionHistory/Table/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ import React from "react"
import { UseTransactionHistoryTableResult } from "#/types"
import { HStack, IconButton } from "@chakra-ui/react"
import { TextSm } from "#/components/shared/Typography"
import { PAGINATION_BUTTONS } from "./utils/pagination"
import { PAGINATION_BUTTONS, getPaginationState } from "./utils/pagination"

function TableFooter({ table }: { table: UseTransactionHistoryTableResult }) {
const { pageIndex, pageSize } = table.getState().pagination
const rowCount = table.getFilteredRowModel().rows.length
const { rowMin, rowMax } = getPaginationState(pageIndex, pageSize, rowCount)

return (
<HStack mt={6}>
{PAGINATION_BUTTONS.map(({ ariaLabel, onClick, isDisabled, icon }) => (
Expand All @@ -18,9 +22,7 @@ function TableFooter({ table }: { table: UseTransactionHistoryTableResult }) {
/>
))}
<TextSm>
{`Page ${
table.getState().pagination.pageIndex + 1
} of ${table.getPageCount()}`}
{`Showing ${rowMin}-${rowMax} out of ${rowCount} transactions`}
</TextSm>
</HStack>
)
Expand Down
11 changes: 11 additions & 0 deletions dapp/src/components/TransactionHistory/Table/utils/pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,14 @@ export const PAGINATION_BUTTONS = [
!table.getCanNextPage(),
},
]

export const getPaginationState = (
pageIndex: number,
pageSize: number,
rowCount: number,
) => {
const rowMin = pageIndex * pageSize + 1
const rowMax = Math.min((pageIndex + 1) * pageSize, rowCount)

return { rowMin, rowMax }
}
2 changes: 1 addition & 1 deletion dapp/src/hooks/useTransactionHistoryTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { useState } from "react"

const PAGINATION_STATE = {
pageIndex: 0,
pageSize: 2,
pageSize: 10,
}

export function useTransactionHistoryTable({
Expand Down

0 comments on commit 4b967f4

Please sign in to comment.