diff --git a/packages/sanity/src/core/search/common/types.ts b/packages/sanity/src/core/search/common/types.ts index 3b4784f9b5fd..43da95b73d0e 100644 --- a/packages/sanity/src/core/search/common/types.ts +++ b/packages/sanity/src/core/search/common/types.ts @@ -107,6 +107,7 @@ export type SearchOptions = { cursor?: string limit?: number perspective?: string + bundlePerspective?: string isCrossDataset?: boolean queryType?: 'prefixLast' | 'prefixNone' } diff --git a/packages/sanity/src/core/search/weighted/createSearchQuery.ts b/packages/sanity/src/core/search/weighted/createSearchQuery.ts index 1b83a0967b86..f2d49627c0aa 100644 --- a/packages/sanity/src/core/search/weighted/createSearchQuery.ts +++ b/packages/sanity/src/core/search/weighted/createSearchQuery.ts @@ -146,7 +146,7 @@ export function createSearchQuery( // Default to `_id asc` (GROQ default) if no search sort is provided const sortOrder = toOrderClause(searchOpts?.sort || [{field: '_id', direction: 'asc'}]) - const projectionFields = ['_type', '_id', '_version'] + const projectionFields = ['_type', '_id', '_originalId', '_version'] const selection = selections.length > 0 ? `...select(${selections.join(',\n')})` : '' const finalProjection = projectionFields.join(', ') + (selection ? `, ${selection}` : '') @@ -186,7 +186,11 @@ export function createSearchQuery( __limit: limit, ...(params || {}), }, - options: {tag, perspective: searchOpts.perspective}, + options: { + tag, + perspective: searchOpts.perspective, + bundlePerspective: searchOpts.bundlePerspective, + }, searchSpec: specs, terms, } diff --git a/packages/sanity/src/core/util/draftUtils.ts b/packages/sanity/src/core/util/draftUtils.ts index 8bf591653e7b..0a7b37db8660 100644 --- a/packages/sanity/src/core/util/draftUtils.ts +++ b/packages/sanity/src/core/util/draftUtils.ts @@ -188,6 +188,7 @@ interface CollateOptions { export function collate< T extends { _id: string + _originalId: string _type: string }, >(documents: T[], {bundlePerspective}: CollateOptions = {}): CollatedHit[] { @@ -213,21 +214,17 @@ export function collate< } if (!isVersion) { - entry[publishedId === doc._id ? 'published' : 'draft'] = doc + const isPublished = publishedId === doc._id + entry[isPublished ? 'published' : 'draft'] = doc + if (isPublished) { + entry.version = doc + } } return res }, new Map()) - return ( - Array.from(byId.values()) - // Remove entries that have no data, because all the following conditions are true: - // - // 1. They have no published version. - // 2. They have no draft version. - // 3. They have a version, but not the one that is currently checked out. - .filter((entry) => entry.published ?? entry.version ?? entry.draft) - ) + return Array.from(byId.values()) } /** @internal */ diff --git a/packages/sanity/src/structure/components/paneItem/PaneItemPreview.tsx b/packages/sanity/src/structure/components/paneItem/PaneItemPreview.tsx index e47a13ae481c..d19b48159b51 100644 --- a/packages/sanity/src/structure/components/paneItem/PaneItemPreview.tsx +++ b/packages/sanity/src/structure/components/paneItem/PaneItemPreview.tsx @@ -69,8 +69,8 @@ export function PaneItemPreview(props: PaneItemPreviewProps) { }) const isInPerspective = useMemo( - () => getDocumentIsInPerspective(value._id, perspective), - [perspective, value._id], + () => getDocumentIsInPerspective(value._originalId ?? value._id, perspective), + [perspective, value._originalId, value._id], ) const status = isLoading ? null : ( diff --git a/packages/sanity/src/structure/panes/documentList/listenSearchQuery.ts b/packages/sanity/src/structure/panes/documentList/listenSearchQuery.ts index 19c321bf663d..4c9022f08e70 100644 --- a/packages/sanity/src/structure/panes/documentList/listenSearchQuery.ts +++ b/packages/sanity/src/structure/panes/documentList/listenSearchQuery.ts @@ -127,6 +127,9 @@ export function listenSearchQuery(options: ListenQueryOptions): Observable