Skip to content

Commit bac9a7a

Browse files
authored
[AP-6104] Fixing pagination issue (#778)
* fixing pagination issue * fixing pagination issue * fixing pagination issue * fixing pagination issue * bumped version to 11.4.1 * reverting non PR related changes
1 parent 0297730 commit bac9a7a

3 files changed

Lines changed: 58 additions & 22 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@nordcloud/gnui",
33
"description": "Nordcloud Design System - a collection of reusable React components used in Nordcloud's SaaS products",
4-
"version": "11.4.0",
4+
"version": "11.4.1",
55
"license": "MIT",
66
"repository": {
77
"type": "git",

src/components/extendedPagination/ExtendedPagination.spec.tsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,42 @@ test("shows `prev` and 'next' button for start index 1", () => {
161161
expect(screen.getByTestId("prev-page")).toBeInTheDocument();
162162
});
163163

164+
test("shows trailing jump on page 3 when there are 6 pages and start index is 1", () => {
165+
getComponent({
166+
count: 119,
167+
from: 60,
168+
size: 20,
169+
firstPage: 1,
170+
});
171+
172+
expect(screen.getByTestId("last-page")).toBeInTheDocument();
173+
expect(screen.getByTestId("last-page-dots")).toBeInTheDocument();
174+
});
175+
176+
test("does not show trailing jump on page 4 when there are 6 pages and start index is 1", () => {
177+
getComponent({
178+
count: 119,
179+
from: 80,
180+
size: 20,
181+
firstPage: 1,
182+
});
183+
184+
expect(screen.queryByTestId("last-page")).not.toBeInTheDocument();
185+
expect(screen.queryByTestId("last-page-dots")).not.toBeInTheDocument();
186+
});
187+
188+
test("keeps trailing jump visible on page 3 when there are 7 pages and start index is 1", () => {
189+
getComponent({
190+
count: 139,
191+
from: 60,
192+
size: 20,
193+
firstPage: 1,
194+
});
195+
196+
expect(screen.getByTestId("last-page")).toBeInTheDocument();
197+
expect(screen.getByTestId("last-page-dots")).toBeInTheDocument();
198+
});
199+
164200
test("notifies about changing page", () => {
165201
getComponent(getParams());
166202
const button = screen.getByTestId("button-1");

src/components/extendedPagination/ExtendedPagination.tsx

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ function Pagination({
4848
}
4949
};
5050

51+
const pages = [...getPages()].filter((index) => index < nPages);
52+
5153
const setPage = (pageNumber: number) => {
5254
if (currentPage !== pageNumber) {
5355
set(pageNumber * size);
@@ -57,7 +59,7 @@ function Pagination({
5759
const showFirstPageJump =
5860
currentPage >= baseNumberOfPages && nPages > baseNumberOfPages;
5961
const showLastPageJump =
60-
currentPage + baseNumberOfPages <= nPages && nPages > baseNumberOfPages;
62+
nPages > baseNumberOfPages && !pages.includes(nPages - 1);
6163

6264
return (
6365
<nav
@@ -96,26 +98,24 @@ function Pagination({
9698
</li>
9799
</When>
98100

99-
{[...getPages()]
100-
.filter((index) => index < nPages)
101-
.map((index) => {
102-
return (
103-
<li key={`p${index + firstPage}`}>
104-
<button
105-
type="button"
106-
disabled={index < 0}
107-
data-testid={`button-${index + firstPage}`}
108-
className={`pagination-link ${
109-
index + firstPage === currentPage ? `current` : ""
110-
}`}
111-
onClick={() => setPage(index + firstPage)}
112-
onKeyDown={() => setPage(index + firstPage)}
113-
>
114-
<span>{index + 1}</span>
115-
</button>
116-
</li>
117-
);
118-
})}
101+
{pages.map((index) => {
102+
return (
103+
<li key={`p${index + firstPage}`}>
104+
<button
105+
type="button"
106+
disabled={index < 0}
107+
data-testid={`button-${index + firstPage}`}
108+
className={`pagination-link ${
109+
index + firstPage === currentPage ? `current` : ""
110+
}`}
111+
onClick={() => setPage(index + firstPage)}
112+
onKeyDown={() => setPage(index + firstPage)}
113+
>
114+
<span>{index + 1}</span>
115+
</button>
116+
</li>
117+
);
118+
})}
119119

120120
<When condition={showLastPageJump}>
121121
<li className="dots" data-testid="last-page-dots">

0 commit comments

Comments
 (0)