Skip to content

Commit

Permalink
feat(components): add totalLength option on Pagination component
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed Sep 19, 2023
1 parent 535f6da commit 09d0a1d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,12 @@ describe("Pagination", () => {
expect(selectComp).toBeInTheDocument();
expect(selectChilds.length === pageSizes.length).toBeTruthy();
});

it("should display total length", () => {
const pageSizes = [10, 25, 50, 100, 200, 500];

render(<Sandbox {...Sandbox.args} pageSizes={pageSizes} totalLength={1000} />);

expect(screen.getByTestId("pagination-total-items")).toHaveTextContent("1,000 items");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export interface PaginationProps {
canNextPage: boolean;
pageCount: number;
pageIndex: number;
pageOptions?: any;
pageOptions?: number[];
pageSize: number;
setPageSize: any;
totalLength?: number;
Expand Down Expand Up @@ -117,7 +117,7 @@ export function Pagination(props: PaginationProps) {
<span className={"ml-3"}>{i18n("items per page")}</span>
</li>
{pageOptions && (
<li className={"mb-3 flex items-center"}>
<li className={"mb-3 mr-3 flex items-center"}>
<span>{i18n("Page")}&nbsp;</span>
<strong>
{pageIndex + 1} of {pageOptions.length}
Expand All @@ -129,6 +129,11 @@ export function Pagination(props: PaginationProps) {
)}
</li>
)}
{totalLength !== undefined && (
<li className={"mb-3 flex items-center"} data-testid='pagination-total-items'>
{i18n("Totals")}: <strong>{new Intl.NumberFormat(undefined).format(totalLength)}</strong> {i18n("items")}
</li>
)}
</nav>
);
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
import noop from "lodash/noop";
import React, { PropsWithChildren, useEffect, useState } from "react";
import {
CellProps,
FilterProps,
Renderer,
TableInstance,
TableOptions,
useFilters,
useGroupBy,
usePagination,
useSortBy,
useTable
} from "react-table";
import { CellProps, FilterProps, Renderer, TableOptions, useFilters, useGroupBy, usePagination, useSortBy, useTable } from "react-table";

import { OnClickOperation, Operation, QueryOptions } from "../../../interfaces";
import { Pagination as DefaultPagination } from "../../pagination/pagination.component";
Expand Down

0 comments on commit 09d0a1d

Please sign in to comment.