Skip to content

Commit 8e51dcc

Browse files
authored
feat!: rename useInfiniteList → useDocuments (#363)
* feat!: rename useInfiniteList → useDocuments
1 parent 544019d commit 8e51dcc

File tree

9 files changed

+35
-35
lines changed

9 files changed

+35
-35
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {
22
DocumentHandle,
3-
useInfiniteList,
3+
useDocuments,
44
useManageFavorite,
55
useNavigateToStudioDocument,
66
useRecordDocumentHistoryEvent,
@@ -54,7 +54,7 @@ function ActionButtons({document}: {document: DocumentHandle}) {
5454
}
5555

5656
export function DocumentCoreInteractionsRoute(): JSX.Element {
57-
const {isPending, data, hasMore, loadMore} = useInfiniteList({
57+
const {isPending, data, hasMore, loadMore} = useDocuments({
5858
filter: '_type == "book"',
5959
orderings: [{field: '_updatedAt', direction: 'desc'}],
6060
})

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import {useInfiniteList} from '@sanity/sdk-react'
1+
import {useDocuments} from '@sanity/sdk-react'
22
import {Box, Button, Heading} from '@sanity/ui'
33
import {type JSX} from 'react'
44

55
import {DocumentGridLayout} from '../components/DocumentGridLayout/DocumentGridLayout'
66
import {DocumentPreview} from './DocumentPreview'
77

88
export function DocumentGridRoute(): JSX.Element {
9-
const {isPending, data, hasMore, loadMore} = useInfiniteList({
9+
const {isPending, data, hasMore, loadMore} = useDocuments({
1010
filter: '_type == "author"',
1111
orderings: [{field: 'name', direction: 'asc'}],
1212
})

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {useInfiniteList} from '@sanity/sdk-react'
1+
import {useDocuments} from '@sanity/sdk-react'
22
import {Box, Heading} from '@sanity/ui'
33
import {type JSX} from 'react'
44

@@ -7,7 +7,7 @@ import {DocumentPreview} from './DocumentPreview'
77
import {LoadMore} from './LoadMore'
88

99
export function DocumentListRoute(): JSX.Element {
10-
const {isPending, data, hasMore, loadMore} = useInfiniteList({
10+
const {isPending, data, hasMore, loadMore} = useDocuments({
1111
filter: '_type == "author"',
1212
orderings: [{field: '_updatedAt', direction: 'asc'}],
1313
})

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {type DocumentHandle, useInfiniteList} from '@sanity/sdk-react'
1+
import {type DocumentHandle, useDocuments} from '@sanity/sdk-react'
22
import {Box, Heading, Stack, Text, TextInput} from '@sanity/ui'
33
import {type JSX, useState} from 'react'
44

@@ -9,7 +9,7 @@ import {LoadMore} from './LoadMore'
99
export function SearchRoute(): JSX.Element {
1010
const [searchQuery, setSearchQuery] = useState('')
1111

12-
const {isPending, data, hasMore, loadMore, count} = useInfiniteList({
12+
const {isPending, data, hasMore, loadMore, count} = useDocuments({
1313
search: searchQuery,
1414
filter: '_type == "book"',
1515
orderings: [{field: '_updatedAt', direction: 'desc'}],

packages/react/src/_exports/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ export {useDocumentSyncStatus} from '../hooks/document/useDocumentSyncStatus'
3636
export {useEditDocument} from '../hooks/document/useEditDocument'
3737
export {usePermissions} from '../hooks/document/usePermissions'
3838
export {
39-
type InfiniteList,
40-
type InfiniteListOptions,
41-
useInfiniteList,
42-
} from '../hooks/infiniteList/useInfiniteList'
39+
type DocumentsOptions,
40+
type DocumentsResponse,
41+
useDocuments,
42+
} from '../hooks/documents/useDocuments'
4343
export {
4444
type PaginatedDocumentsOptions,
4545
type PaginatedDocumentsResponse,

packages/react/src/hooks/infiniteList/useInfiniteList.test.tsx renamed to packages/react/src/hooks/documents/useDocuments.test.tsx

Lines changed: 9 additions & 9 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 {useInfiniteList} from './useInfiniteList'
6+
import {useDocuments} from './useDocuments'
77

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

10-
describe('useInfiniteList', () => {
10+
describe('useDocuments', () => {
1111
beforeEach(() => {
1212
const dataset = [
1313
{
@@ -76,29 +76,29 @@ describe('useInfiniteList', () => {
7676

7777
it('should respect custom page size', () => {
7878
const customBatchSize = 2
79-
const {result} = renderHook(() => useInfiniteList({batchSize: customBatchSize}))
79+
const {result} = renderHook(() => useDocuments({batchSize: customBatchSize}))
8080

8181
expect(result.current.data.length).toBe(customBatchSize)
8282
})
8383

8484
it('should filter by document type', () => {
85-
const {result} = renderHook(() => useInfiniteList({filter: '_type == "movie"'}))
85+
const {result} = renderHook(() => useDocuments({filter: '_type == "movie"'}))
8686

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

9191
// groq-js doesn't support search filters yet
9292
it.skip('should apply search filter', () => {
93-
const {result} = renderHook(() => useInfiniteList({search: 'inter'}))
93+
const {result} = renderHook(() => useDocuments({search: 'inter'}))
9494

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

9999
it('should apply ordering', () => {
100100
const {result} = renderHook(() =>
101-
useInfiniteList({
101+
useDocuments({
102102
filter: '_type == "movie"',
103103
orderings: [{field: 'releaseYear', direction: 'desc'}],
104104
}),
@@ -110,7 +110,7 @@ describe('useInfiniteList', () => {
110110

111111
it('should load more data when loadMore is called', () => {
112112
const batchSize = 2
113-
const {result} = renderHook(() => useInfiniteList({batchSize: batchSize}))
113+
const {result} = renderHook(() => useDocuments({batchSize: batchSize}))
114114

115115
expect(result.current.data.length).toBe(batchSize)
116116

@@ -122,7 +122,7 @@ describe('useInfiniteList', () => {
122122
})
123123

124124
it('should indicate when there is more data to load', () => {
125-
const {result} = renderHook(() => useInfiniteList({batchSize: 3}))
125+
const {result} = renderHook(() => useDocuments({batchSize: 3}))
126126
expect(result.current.hasMore).toBe(true)
127127
// Load all remaining data
128128
act(() => {
@@ -133,7 +133,7 @@ describe('useInfiniteList', () => {
133133

134134
// New test case for resetting limit when filter changes
135135
it('should reset limit when filter changes', () => {
136-
const {result, rerender} = renderHook((props) => useInfiniteList(props), {
136+
const {result, rerender} = renderHook((props) => useDocuments(props), {
137137
initialProps: {batchSize: 2, filter: ''},
138138
})
139139
// Initially, data length equals pageSize (2)

packages/react/src/hooks/infiniteList/useInfiniteList.ts renamed to packages/react/src/hooks/documents/useDocuments.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ const DEFAULT_PERSPECTIVE = 'drafts'
1111
* Result structure returned from the infinite list query
1212
* @internal
1313
*/
14-
interface InfiniteListQueryResult {
14+
interface UseDocumentsQueryResult {
1515
count: number
1616
data: DocumentHandle[]
1717
}
1818

1919
/**
20-
* Configuration options for the useInfiniteList hook
20+
* Configuration options for the useDocuments hook
2121
*
2222
* @beta
2323
* @category Types
2424
*/
25-
export interface InfiniteListOptions extends QueryOptions {
25+
export interface DocumentsOptions extends QueryOptions {
2626
/**
2727
* GROQ filter expression to apply to the query
2828
*/
@@ -42,12 +42,12 @@ export interface InfiniteListOptions extends QueryOptions {
4242
}
4343

4444
/**
45-
* Return value from the useInfiniteList hook
45+
* Return value from the useDocuments hook
4646
*
4747
* @beta
4848
* @category Types
4949
*/
50-
export interface InfiniteList {
50+
export interface DocumentsResponse {
5151
/**
5252
* Array of document handles for the current batch
5353
*/
@@ -78,10 +78,10 @@ export interface InfiniteList {
7878
* @beta
7979
* @category Documents
8080
* @param options - Configuration options for the infinite list
81-
* @returns An object containing the list of document handles, the loading state, the total count of retrived document handles, and a function to load more
81+
* @returns An object containing the list of document handles, the loading state, the total count of retrieved document handles, and a function to load more
8282
* @example
8383
* ```tsx
84-
* const {data, hasMore, isPending, loadMore} = useInfiniteList({
84+
* const {data, hasMore, isPending, loadMore} = useDocuments({
8585
* filter: '_type == "post"',
8686
* search: searchTerm,
8787
* batchSize: 10,
@@ -104,14 +104,14 @@ export interface InfiniteList {
104104
* ```
105105
*
106106
*/
107-
export function useInfiniteList({
107+
export function useDocuments({
108108
batchSize = DEFAULT_BATCH_SIZE,
109109
params,
110110
search,
111111
filter,
112112
orderings,
113113
...options
114-
}: InfiniteListOptions): InfiniteList {
114+
}: DocumentsOptions): DocumentsResponse {
115115
const perspective = options.perspective ?? DEFAULT_PERSPECTIVE
116116
const [limit, setLimit] = useState(batchSize)
117117

@@ -155,7 +155,7 @@ export function useInfiniteList({
155155
const {
156156
data: {count, data},
157157
isPending,
158-
} = useQuery<InfiniteListQueryResult>(`{"count":${countQuery},"data":${dataQuery}}`, {
158+
} = useQuery<UseDocumentsQueryResult>(`{"count":${countQuery},"data":${dataQuery}}`, {
159159
...options,
160160
params,
161161
perspective,

packages/react/src/hooks/preview/usePreview.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export interface UsePreviewResults {
3636
* @param options - The document handle for the document you want to resolve preview values for, and an optional ref
3737
* @returns The preview values for the given document and a boolean to indicate whether the resolution is pending
3838
*
39-
* @example Combining with useInfiniteList to render a collection of document previews
39+
* @example Combining with useDocuments to render a collection of document previews
4040
* ```
4141
* // PreviewComponent.jsx
4242
* export default function PreviewComponent({ document }) {
@@ -51,7 +51,7 @@ export interface UsePreviewResults {
5151
* }
5252
*
5353
* // DocumentList.jsx
54-
* const { data } = useInfiniteList({ filter: '_type == "movie"' })
54+
* const { data } = useDocuments({ filter: '_type == "movie"' })
5555
* return (
5656
* <div>
5757
* <h1>Movies</h1>

packages/react/src/hooks/projection/useProjection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ export interface UseProjectionResults<TResult extends object> {
6565
* }
6666
* ```
6767
*
68-
* @example Combining with useInfiniteList to render a collection with specific fields
68+
* @example Combining with useDocuments to render a collection with specific fields
6969
* ```
7070
* // DocumentList.jsx
71-
* const { data } = useInfiniteList({ filter: '_type == "article"' })
71+
* const { data } = useDocuments({ filter: '_type == "article"' })
7272
* return (
7373
* <div>
7474
* <h1>Books</h1>

0 commit comments

Comments
 (0)