Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(sanity): update types #7073

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import {type SanityClient} from '@sanity/client'
import {DEFAULT_MAX_FIELD_DEPTH} from '@sanity/schema/_internal'
import {type ReferenceFilterSearchOptions, type ReferenceSchemaType} from '@sanity/types'
import {
type ReferenceFilterSearchOptions,
type ReferenceSchemaType,
type SanityDocumentLike,
} from '@sanity/types'
import {combineLatest, type Observable, of} from 'rxjs'
import {map, mergeMap, startWith, switchMap} from 'rxjs/operators'

Expand Down Expand Up @@ -200,8 +204,10 @@ export function referenceSearch(
maxDepth: options.maxFieldDepth || DEFAULT_MAX_FIELD_DEPTH,
})
return search(textTerm, {includeDrafts: true}).pipe(
map(({hits}) => hits.map(({hit}) => hit)),
map(collate),
map(({hits}) => hits.map(({hit}) => hit) as unknown as CollatedHit<SanityDocumentLike>[]),
map((collated: CollatedHit<SanityDocumentLike>[]) =>
collate(collated as unknown as SanityDocumentLike[]),
),
// pick the 100 best matches
map((collated) => collated.slice(0, 100)),
mergeMap((collated) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import {type SanityClient} from '@sanity/client'
import {
type CrossDatasetReferenceSchemaType,
type ReferenceFilterSearchOptions,
type SanityDocumentLike,
} from '@sanity/types'
import {type Observable} from 'rxjs'
import {map} from 'rxjs/operators'

import {createSearch} from '../../../../../search'
import {collate} from '../../../../../util'
import {collate, type CollatedHit} from '../../../../../util'

interface SearchHit {
id: string
Expand All @@ -31,7 +32,9 @@ export function search(
isCrossDataset: true,
}).pipe(
map(({hits}) => hits.map(({hit}) => hit)),
map(collate),
map(
collate as (value: SanityDocumentLike[], index: number) => CollatedHit<SanityDocumentLike>[],
),
map((collated) =>
collated.map((entry) => ({
id: entry.id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {type SanityClient} from '@sanity/client'
import {useCallback, useContext, useEffect, useMemo, useState} from 'react'
import {type ReactNode, useCallback, useContext, useEffect, useMemo, useState} from 'react'
import {AddonDatasetContext} from 'sanity/_singletons'

import {useClient} from '../../hooks'
Expand Down Expand Up @@ -135,7 +135,14 @@ function AddonDatasetProviderInner(props: AddonDatasetSetupProviderProps) {
return <AddonDatasetContext.Provider value={ctxValue}>{children}</AddonDatasetContext.Provider>
}

export function AddonDatasetProvider(props: AddonDatasetSetupProviderProps) {
/**
* TODO add proper comment & check tags
*
* @internal
* @beta
* @hidden
*/
export function AddonDatasetProvider(props: AddonDatasetSetupProviderProps): ReactNode {
const context = useContext(AddonDatasetContext)
// Avoid mounting the provider if it's already provided by a parent
if (context) return props.children
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function PaneItemPreview(props: PaneItemPreviewProps) {
return (
<>
<Text size={1} muted>
{(version ?? draft ?? published)?._id}
{((version ?? draft ?? published) as SanityDocument)?._id}
</Text>
<SanityDefaultPreview
{...getPreviewValueWithFallback({value, draft, published, version, perspective})}
Expand Down
Loading