Skip to content

Commit 544019d

Browse files
authored
feat!: rename usePaginatedList → usePaginatedDocuments (#364)
* feat!: rename usePaginatedList → usePaginatedDocuments
1 parent 778a63a commit 544019d

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed

apps/kitchensink-react/src/DocumentCollection/DocumentProjectionRoute.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {DocumentHandle} from '@sanity/sdk'
2-
import {usePaginatedList, useProjection} from '@sanity/sdk-react'
2+
import {usePaginatedDocuments, useProjection} from '@sanity/sdk-react'
33
import {Box, Button, Card, Flex, Label, Spinner, Stack, Text, TextInput} from '@sanity/ui'
44
import {JSX, ReactNode, Suspense, useRef, useState} from 'react'
55
import {ErrorBoundary} from 'react-error-boundary'
@@ -204,7 +204,7 @@ export function DocumentProjectionRoute(): JSX.Element {
204204
count,
205205
startIndex,
206206
endIndex,
207-
} = usePaginatedList({
207+
} = usePaginatedDocuments({
208208
filter: '_type == "author" && count(favoriteBooks) > 0',
209209
orderings: [{field: 'name', direction: 'asc'}],
210210
search: searchTerm,

packages/react/src/_exports/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ export {
4141
useInfiniteList,
4242
} from '../hooks/infiniteList/useInfiniteList'
4343
export {
44-
type PaginatedList,
45-
type PaginatedListOptions,
46-
usePaginatedList,
47-
} from '../hooks/paginatedList/usePaginatedList'
44+
type PaginatedDocumentsOptions,
45+
type PaginatedDocumentsResponse,
46+
usePaginatedDocuments,
47+
} from '../hooks/paginatedDocuments/usePaginatedDocuments'
4848
export {
4949
usePreview,
5050
type UsePreviewOptions,

packages/react/src/hooks/paginatedList/usePaginatedList.test.tsx renamed to packages/react/src/hooks/paginatedDocuments/usePaginatedDocuments.test.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import {describe, vi} from 'vitest'
33

44
import {evaluateSync, parse} from '../_synchronous-groq-js.mjs'
55
import {useQuery} from '../query/useQuery'
6-
import {usePaginatedList} from './usePaginatedList'
6+
import {usePaginatedDocuments} from './usePaginatedDocuments'
77

88
vi.mock('../query/useQuery')
99

10-
describe('usePaginatedList', () => {
10+
describe('usePaginatedDocuments', () => {
1111
beforeEach(() => {
1212
const dataset = [
1313
{
@@ -76,30 +76,30 @@ describe('usePaginatedList', () => {
7676

7777
it('should respect custom page size', () => {
7878
const customPageSize = 2
79-
const {result} = renderHook(() => usePaginatedList({pageSize: customPageSize}))
79+
const {result} = renderHook(() => usePaginatedDocuments({pageSize: customPageSize}))
8080

8181
expect(result.current.pageSize).toBe(customPageSize)
8282
expect(result.current.data.length).toBeLessThanOrEqual(customPageSize)
8383
})
8484

8585
it('should filter by document type', () => {
86-
const {result} = renderHook(() => usePaginatedList({filter: '_type == "movie"'}))
86+
const {result} = renderHook(() => usePaginatedDocuments({filter: '_type == "movie"'}))
8787

8888
expect(result.current.data.every((doc) => doc._type === 'movie')).toBe(true)
8989
expect(result.current.count).toBe(5) // 5 movies in the dataset
9090
})
9191

9292
// groq-js doesn't support search filters yet
9393
it.skip('should apply search filter', () => {
94-
const {result} = renderHook(() => usePaginatedList({search: 'inter'}))
94+
const {result} = renderHook(() => usePaginatedDocuments({search: 'inter'}))
9595

9696
// Should match "Interstellar"
9797
expect(result.current.data.some((doc) => doc._id === 'movie3')).toBe(true)
9898
})
9999

100100
it('should apply ordering', () => {
101101
const {result} = renderHook(() =>
102-
usePaginatedList({
102+
usePaginatedDocuments({
103103
filter: '_type == "movie"',
104104
orderings: [{field: 'releaseYear', direction: 'desc'}],
105105
}),
@@ -111,7 +111,7 @@ describe('usePaginatedList', () => {
111111

112112
it('should calculate pagination values correctly', () => {
113113
const pageSize = 2
114-
const {result} = renderHook(() => usePaginatedList({pageSize}))
114+
const {result} = renderHook(() => usePaginatedDocuments({pageSize}))
115115

116116
expect(result.current.currentPage).toBe(1)
117117
expect(result.current.totalPages).toBe(3) // 6 items with page size 2
@@ -122,7 +122,7 @@ describe('usePaginatedList', () => {
122122

123123
it('should navigate to next page', () => {
124124
const pageSize = 2
125-
const {result} = renderHook(() => usePaginatedList({pageSize}))
125+
const {result} = renderHook(() => usePaginatedDocuments({pageSize}))
126126

127127
expect(result.current.currentPage).toBe(1)
128128
expect(result.current.data.length).toBe(pageSize)
@@ -138,7 +138,7 @@ describe('usePaginatedList', () => {
138138

139139
it('should navigate to previous page', () => {
140140
const pageSize = 2
141-
const {result} = renderHook(() => usePaginatedList({pageSize}))
141+
const {result} = renderHook(() => usePaginatedDocuments({pageSize}))
142142

143143
// Go to page 2 first
144144
act(() => {
@@ -158,7 +158,7 @@ describe('usePaginatedList', () => {
158158

159159
it('should navigate to first page', () => {
160160
const pageSize = 2
161-
const {result} = renderHook(() => usePaginatedList({pageSize}))
161+
const {result} = renderHook(() => usePaginatedDocuments({pageSize}))
162162

163163
// Go to last page first
164164
act(() => {
@@ -178,7 +178,7 @@ describe('usePaginatedList', () => {
178178

179179
it('should navigate to last page', () => {
180180
const pageSize = 2
181-
const {result} = renderHook(() => usePaginatedList({pageSize}))
181+
const {result} = renderHook(() => usePaginatedDocuments({pageSize}))
182182

183183
act(() => {
184184
result.current.lastPage()
@@ -190,7 +190,7 @@ describe('usePaginatedList', () => {
190190

191191
it('should navigate to specific page', () => {
192192
const pageSize = 2
193-
const {result} = renderHook(() => usePaginatedList({pageSize}))
193+
const {result} = renderHook(() => usePaginatedDocuments({pageSize}))
194194

195195
act(() => {
196196
result.current.goToPage(2) // Go to page 2
@@ -215,7 +215,7 @@ describe('usePaginatedList', () => {
215215

216216
it('should set page availability flags correctly', () => {
217217
const pageSize = 2
218-
const {result} = renderHook(() => usePaginatedList({pageSize}))
218+
const {result} = renderHook(() => usePaginatedDocuments({pageSize}))
219219
// On first page
220220
expect(result.current.hasFirstPage).toBe(false)
221221
expect(result.current.hasPreviousPage).toBe(false)
@@ -241,7 +241,7 @@ describe('usePaginatedList', () => {
241241

242242
// New test case for resetting the current page when filter changes
243243
it('should reset current page when filter changes', () => {
244-
const {result, rerender} = renderHook((props) => usePaginatedList(props), {
244+
const {result, rerender} = renderHook((props) => usePaginatedDocuments(props), {
245245
initialProps: {pageSize: 2, filter: ''},
246246
})
247247
// Initially, current page should be 1

packages/react/src/hooks/paginatedList/usePaginatedList.ts renamed to packages/react/src/hooks/paginatedDocuments/usePaginatedDocuments.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import {useQuery} from '../query/useQuery'
77
const DEFAULT_PERSPECTIVE = 'drafts'
88

99
/**
10-
* Configuration options for the usePaginatedList hook
10+
* Configuration options for the usePaginatedDocuments hook
1111
*
1212
* @beta
1313
* @category Types
1414
*/
15-
export interface PaginatedListOptions extends QueryOptions {
15+
export interface PaginatedDocumentsOptions extends QueryOptions {
1616
/**
1717
* GROQ filter expression to apply to the query
1818
*/
@@ -32,12 +32,12 @@ export interface PaginatedListOptions extends QueryOptions {
3232
}
3333

3434
/**
35-
* Return value from the usePaginatedList hook
35+
* Return value from the usePaginatedDocuments hook
3636
*
3737
* @beta
3838
* @category Types
3939
*/
40-
export interface PaginatedList {
40+
export interface PaginatedDocumentsResponse {
4141
/**
4242
* Array of document handles for the current page
4343
*/
@@ -136,7 +136,7 @@ export interface PaginatedList {
136136
* previousPage,
137137
* hasNextPage,
138138
* hasPreviousPage
139-
* } = usePaginatedList({
139+
* } = usePaginatedDocuments({
140140
* filter: '_type == "post"',
141141
* search: searchTerm,
142142
* pageSize: 10,
@@ -160,14 +160,14 @@ export interface PaginatedList {
160160
* ```
161161
*
162162
*/
163-
export function usePaginatedList({
163+
export function usePaginatedDocuments({
164164
filter = '',
165165
pageSize = 25,
166166
params = {},
167167
orderings,
168168
search,
169169
...options
170-
}: PaginatedListOptions = {}): PaginatedList {
170+
}: PaginatedDocumentsOptions = {}): PaginatedDocumentsResponse {
171171
const [pageIndex, setPageIndex] = useState(0)
172172
const key = JSON.stringify({filter, search, params, orderings, pageSize})
173173
// Reset the pageIndex to 0 whenever any query parameters (filter, search,

0 commit comments

Comments
 (0)