Release v2.2.0
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
// Shared helpers for building paginated list response state.
|
||||
|
||||
function normalizePageNumber(value) {
|
||||
const pageNumber = Math.floor(Number(value) || 1);
|
||||
return Math.max(1, pageNumber);
|
||||
@@ -89,6 +91,15 @@ function buildPagination(totalItems, currentPage, pageParam, queryState, pageSiz
|
||||
const firstQuery = Object.assign({}, queryState, { [normalizedPageParam]: 1 });
|
||||
const lastQuery = Object.assign({}, queryState, { [normalizedPageParam]: totalPages });
|
||||
|
||||
let normalizedItemLabel = String(itemLabel || 'items');
|
||||
const total = Number(totalItems) || 0;
|
||||
|
||||
if (total === 1 && normalizedItemLabel.endsWith('s')) {
|
||||
normalizedItemLabel = normalizedItemLabel.slice(0, -1);
|
||||
} else if (total > 1 && !normalizedItemLabel.endsWith('s')) {
|
||||
normalizedItemLabel += 's';
|
||||
}
|
||||
|
||||
return {
|
||||
currentPage: safeCurrentPage,
|
||||
totalPages: totalPages,
|
||||
@@ -107,7 +118,7 @@ function buildPagination(totalItems, currentPage, pageParam, queryState, pageSiz
|
||||
pages: pages,
|
||||
pageSize: normalizedPageSize,
|
||||
pageParam: normalizedPageParam,
|
||||
itemLabel: String(itemLabel || 'items'),
|
||||
itemLabel: String(normalizedItemLabel || 'item'),
|
||||
ariaLabel: String(ariaLabel || 'Pagination')
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user