Skip to content

Commit

Permalink
Fixes #36469 - fix the pagination algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
ronlavi2412 authored and nofaralfasi committed Mar 19, 2024
1 parent 8ce9809 commit c4797c3
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions webpack/helpers/pageParamsHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ export const useCurrentPagination = history => {
* to make the pagination work on tables where `page * per_page > totalCount`,
* we needed to add the following calculation for the `last` variable
*/
export const pageToVars = ({ page, per_page }, totalCount = 0) => ({
first: page * per_page,
last: page > 1 && totalCount > 0 ? totalCount - per_page : per_page,
});
export const pageToVars = ({ page, per_page }, totalCount = 0) => {
totalCount = totalCount || per_page;
return ({
first: Math.min(page * per_page, totalCount),
last: Math.min(per_page, totalCount - (page - 1) * per_page),
});
}

export const useParamsToVars = (history, totalCount) =>
pageToVars(useCurrentPagination(history), totalCount);

0 comments on commit c4797c3

Please sign in to comment.