@@ -36,18 +36,27 @@ export const generateYAxis = (revenue: Revenue[]) => {
36
36
} ;
37
37
38
38
export const generatePagination = ( currentPage : number , totalPages : number ) => {
39
+ // If the total number of pages is 7 or less,
40
+ // display all pages without any ellipsis.
39
41
if ( totalPages <= 7 ) {
40
42
return Array . from ( { length : totalPages } , ( _ , i ) => i + 1 ) ;
41
43
}
42
44
45
+ // If the current page is among the first 3 pages,
46
+ // show the first 3, an ellipsis, and the last 2 pages.
43
47
if ( currentPage <= 3 ) {
44
48
return [ 1 , 2 , 3 , '...' , totalPages - 1 , totalPages ] ;
45
49
}
46
50
51
+ // If the current page is among the last 3 pages,
52
+ // show the first 2, an ellipsis, and the last 3 pages.
47
53
if ( currentPage >= totalPages - 2 ) {
48
54
return [ 1 , 2 , '...' , totalPages - 2 , totalPages - 1 , totalPages ] ;
49
55
}
50
56
57
+ // If the current page is somewhere in the middle,
58
+ // show the first page, an ellipsis, the current page and its neighbors,
59
+ // another ellipsis, and the last page.
51
60
return [
52
61
1 ,
53
62
'...' ,
0 commit comments