Skip to content

Commit 828d6aa

Browse files
authored
added possibility to define, if the page size in the paging can be changed by the user (#54)
added possibility to define, if the page size in the paging can be changed by the user
1 parent 9aa8875 commit 828d6aa

3 files changed

Lines changed: 39 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Possibility to define, if the page size in the paging can be changed by the user
13+
1014
## [3.3.0] - 2024-03-08
1115

1216
### Added

cypress/cypress/component/Paging/Paging.cy.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,36 @@ describe("Paging.cy.tsx", () => {
6868
// Check pagination class set
6969
cy.get("[data-cy-root] > .container-fluid").should("have.class", "paging");
7070
});
71+
72+
it("paging without change of page size", () => {
73+
const itemsPerPage = faker.datatype.number({ min: 1, max: 999 });
74+
const pages = faker.datatype.number({ min: 3, max: 999 });
75+
const currentPage = faker.datatype.number({ min: 2, max: pages - 1 });
76+
const translations = { showedItemsText: "Item {from} to {to} from {total}", itemsPerPageDropdown: "Items per page" };
77+
78+
cy.mount(
79+
<Paging
80+
currentItemsPerPage={itemsPerPage}
81+
currentPage={currentPage}
82+
currentRecordCount={itemsPerPage}
83+
setCurrentPage={cy.spy().as("setCurrentPage")}
84+
totalRecords={pages * itemsPerPage}
85+
setItemsPerPage={cy.spy().as("setItemsPerPage")}
86+
translations={translations}
87+
changePageSizePossible={false}
88+
/>,
89+
);
90+
91+
// Check pages per item dropdown is not shown by checking that the first child is the paging from to text
92+
cy.get("[data-cy-root] > .container-fluid > .row > .col-6:first-of-type")
93+
.children()
94+
.first()
95+
.should(
96+
"have.text",
97+
translations.showedItemsText
98+
.replace("{from}", (currentPage * itemsPerPage - itemsPerPage + 1).toString())
99+
.replace("{to}", (currentPage * itemsPerPage).toString())
100+
.replace("{total}", (pages * itemsPerPage).toString()),
101+
);
102+
});
71103
});

src/lib/Paging/Paging.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ interface PagingProps {
1111
possiblePageItemCounts?: number[];
1212
maxPagesShown?: number;
1313
showControls?: boolean;
14+
changePageSizePossible?: boolean;
1415
setItemsPerPage(itemsPerPage: number): void;
1516
setCurrentPage(itemsPerPage: number): void;
1617
}
@@ -30,6 +31,7 @@ function Paging({
3031
possiblePageItemCounts,
3132
maxPagesShown = 7,
3233
showControls = true,
34+
changePageSizePossible = true,
3335
setItemsPerPage,
3436
setCurrentPage,
3537
}: PagingProps) {
@@ -48,7 +50,7 @@ function Paging({
4850
<div className="container-fluid paging">
4951
<Row style={{ marginBottom: "20px" }}>
5052
<Col xs={pagingPossible && currentItemsPerPage < totalRecords ? 6 : 12} style={{ paddingLeft: 0 }}>
51-
{pagingPossible && (
53+
{pagingPossible && changePageSizePossible && (
5254
<UncontrolledButtonDropdown>
5355
<DropdownToggle caret color="link" size="sm">
5456
{currentItemsPerPage}

0 commit comments

Comments
 (0)