Skip to content

Commit 50d390a

Browse files
authored
Merge branch 'main' into main
2 parents f8c5bad + 60a26d1 commit 50d390a

File tree

5 files changed

+14
-9
lines changed

5 files changed

+14
-9
lines changed

Diff for: src/__tests__/operations/paginate.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ test('displays an out of range page', () => {
9393
items: processed,
9494
pagesCount,
9595
actualPageIndex,
96-
} = processItems(items, { currentPageIndex: 3 }, { pagination: {} });
96+
} = processItems(items, { currentPageIndex: 3 }, { pagination: { allowPageOutOfRange: true } });
9797
expect(actualPageIndex).toEqual(3);
9898
expect(pagesCount).toEqual(2);
9999
expect(processed).toHaveLength(0);

Diff for: src/interfaces.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export interface UseCollectionOptions<T> {
4444
freeTextFiltering?: PropertyFilterFreeTextFiltering;
4545
};
4646
sorting?: { defaultState?: SortingState<T> };
47-
pagination?: { defaultPage?: number; pageSize?: number };
47+
pagination?: { defaultPage?: number; pageSize?: number; allowPageOutOfRange?: boolean };
4848
selection?: {
4949
defaultSelectedItems?: ReadonlyArray<T>;
5050
keepSelection?: boolean;

Diff for: src/operations/pagination.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function createPageProps<T>(
1616
const pageSize = pagination.pageSize ?? DEFAULT_PAGE_SIZE;
1717
const pagesCount = Math.ceil(items.length / pageSize);
1818
let pageIndex = currentPageIndex ?? 1;
19-
if (pageIndex < 1 || Number.isNaN(pageIndex)) {
19+
if (pageIndex < 1 || (pageIndex > pagesCount && !pagination.allowPageOutOfRange) || Number.isNaN(pageIndex)) {
2020
pageIndex = 1;
2121
}
2222
return { pageSize, pagesCount, pageIndex };

Diff for: src/types.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,10 @@
55
* subset of node.js types, safe to use in browser and bundlers
66
* we do not use `lib.dom` types because they are not available in SSR environment
77
*/
8-
declare const process: { env: { NODE_ENV?: string } };
9-
declare const console: { warn: (...args: Array<any>) => void };
8+
declare global {
9+
const process: { env: { NODE_ENV?: string } };
10+
const console: { warn: (...args: Array<any>) => void };
11+
}
12+
13+
// dummy export to make typescript treat this file as ES module
14+
export {};

Diff for: src/utils.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,22 @@ export function createActions<T>({
8484
return {
8585
setFiltering(filteringText) {
8686
dispatch({ type: 'filtering', filteringText });
87-
collectionRef.current && collectionRef.current.scrollToTop();
87+
collectionRef.current?.scrollToTop();
8888
},
8989
setSorting(state: SortingState<T>) {
9090
dispatch({ type: 'sorting', sortingState: state });
91-
collectionRef.current && collectionRef.current.scrollToTop();
91+
collectionRef.current?.scrollToTop();
9292
},
9393
setCurrentPage(pageIndex: number) {
9494
dispatch({ type: 'pagination', pageIndex });
95-
collectionRef.current && collectionRef.current.scrollToTop();
95+
collectionRef.current?.scrollToTop();
9696
},
9797
setSelectedItems(selectedItems: Array<T>) {
9898
dispatch({ type: 'selection', selectedItems });
9999
},
100100
setPropertyFiltering(query: PropertyFilterQuery) {
101101
dispatch({ type: 'property-filtering', query });
102-
collectionRef.current && collectionRef.current.scrollToTop();
102+
collectionRef.current?.scrollToTop();
103103
},
104104
setExpandedItems(expandedItems: ReadonlyArray<T>) {
105105
dispatch({ type: 'expansion', expandedItems });

0 commit comments

Comments
 (0)