Skip to content

Commit 4204132

Browse files
author
Laurie T. Malau
committed
fix ellipses
1 parent 5aabd21 commit 4204132

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

components/dashboard/src/components/Pagination.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@ function Pagination(props: {
2424
if (currentPage !== 1) setCurrentPage(currentPage - 1);
2525
};
2626
const getClassnames = (pageNumber: string | number) => {
27-
let classnamesString = "text-gray-500 w-8 text-center rounded-md cursor-pointer hover:bg-gray-50";
2827
if (pageNumber === currentPage) {
29-
return classnamesString + " bg-gray-100 pointer-events-none";
28+
return "text-gray-500 w-8 text-center rounded-md hover:bg-gray-50 bg-gray-100 disabled pointer-events-none";
3029
}
3130
if (pageNumber === "...") {
32-
return classnamesString + "pointer-events-none";
31+
return "text-gray-500 w-8 text-center rounded-md hover:bg-gray-50 disabled pointer-events-none";
3332
}
34-
return classnamesString;
33+
return "text-gray-500 w-8 text-center rounded-md hover:bg-gray-50 cursor-pointer";
3534
};
3635

3736
return (

components/dashboard/src/custom-hooks/usePagination.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const usePagination = (props: {
1414
}) => {
1515
const { totalResults, totalNumberOfPages, currentPage, resultsPerPage } = props;
1616
const adjacentToCurrentPage = 1; // This is the number(s) we see next to the currentPage
17-
const totalNumbersShownInPagination = 5;
17+
const totalNumbersShownInPagination = 6;
1818

1919
const pageNumbersAsArray = (startRange: number, endRange: number) => {
2020
return [...Array(endRange + 1).keys()].slice(startRange);
@@ -28,28 +28,26 @@ export const usePagination = (props: {
2828
}
2929

3030
// Otherwise, we show the ellipses
31-
// Make sure when calculating it's still within the range
32-
const adjacentRightIsWithinRange = Math.min(currentPage + adjacentToCurrentPage, totalNumberOfPages);
33-
const adjacentLeftIsWithinRange = Math.max(currentPage - adjacentToCurrentPage, 1);
31+
const toTheRightOfCurrent = Math.min(currentPage + adjacentToCurrentPage, totalNumberOfPages);
32+
const toTheLeftOfCurrent = Math.max(currentPage - adjacentToCurrentPage, 1);
3433

35-
const showRightEllipsis =
36-
adjacentRightIsWithinRange < totalNumberOfPages - minimumAmountInBetweenToShowEllipsis; // e.g. "1 2 3 ... 7"
37-
const showLeftEllipsis = adjacentLeftIsWithinRange > minimumAmountInBetweenToShowEllipsis; // e.g. 1 ... 5 6 7"
34+
const showRightEllipsis = toTheRightOfCurrent < totalNumberOfPages - minimumAmountInBetweenToShowEllipsis; // e.g. "1 2 3 ... 7"
35+
const showLeftEllipsis = toTheLeftOfCurrent > minimumAmountInBetweenToShowEllipsis; // e.g. 1 ... 5 6 7"
3836

39-
if (showRightEllipsis) {
37+
if (showRightEllipsis && !showLeftEllipsis) {
4038
let leftSideNumbers = 3;
4139
let leftPageNumbersAsArray = pageNumbersAsArray(1, leftSideNumbers);
4240
return [...leftPageNumbersAsArray, "...", totalNumberOfPages];
4341
}
4442

45-
if (showLeftEllipsis) {
43+
if (showLeftEllipsis && !showRightEllipsis) {
4644
let rightSideNumbers = 3;
4745
let rightPageNumbersAsArray = pageNumbersAsArray(totalNumberOfPages - rightSideNumbers, totalNumberOfPages);
4846
return [1, "...", ...rightPageNumbersAsArray];
4947
}
5048

5149
if (showRightEllipsis && showLeftEllipsis) {
52-
let middleNumbers = pageNumbersAsArray(adjacentLeftIsWithinRange, adjacentRightIsWithinRange);
50+
let middleNumbers = pageNumbersAsArray(toTheLeftOfCurrent, toTheRightOfCurrent);
5351
return [1, "...", ...middleNumbers, "...", totalNumberOfPages];
5452
}
5553
}, [totalResults, totalNumberOfPages, currentPage, adjacentToCurrentPage, pageNumbersAsArray, resultsPerPage]);

components/dashboard/src/teams/TeamUsage.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ function TeamUsage() {
130130
const lastResultOnCurrentPage = currentPage * resultsPerPage;
131131
const firstResultOnCurrentPage = lastResultOnCurrentPage - resultsPerPage;
132132
const totalNumberOfPages = Math.ceil(billedUsage.length / resultsPerPage);
133-
console.log("totalNumberOfPages", totalNumberOfPages);
134133
const currentPaginatedResults = billedUsage.slice(firstResultOnCurrentPage, lastResultOnCurrentPage);
135134

136135
return (

0 commit comments

Comments
 (0)