From 516625a5b8c83f1ed14072b0a9bdc41380229936 Mon Sep 17 00:00:00 2001 From: RitaDias Date: Fri, 23 Aug 2024 10:06:04 +0200 Subject: [PATCH] refactor(sanity): re-add sanity::versionOf --- .../bundles/hooks/useDocumentVersions.tsx | 39 +++++++++---------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/packages/sanity/src/core/bundles/hooks/useDocumentVersions.tsx b/packages/sanity/src/core/bundles/hooks/useDocumentVersions.tsx index 62bfedb6a80..c69ff8ce4d1 100644 --- a/packages/sanity/src/core/bundles/hooks/useDocumentVersions.tsx +++ b/packages/sanity/src/core/bundles/hooks/useDocumentVersions.tsx @@ -42,27 +42,24 @@ export function useDocumentVersions(props: DocumentPerspectiveProps): DocumentPe const documentPreviewStore = useDocumentPreviewStore() const observable = useMemo(() => { - return ( - documentPreviewStore - // TODO - re-add versionOf once CL has it ready - .unstable_observeDocumentIdSet(`_id in path("versions.**") && _id match '*.${publishedId}'`) - .pipe( - map(({documentIds}) => { - return documentIds.flatMap((id) => { - // eslint-disable-next-line max-nested-callbacks - const matchingBundle = bundles?.find((bundle) => getBundleSlug(id) === bundle.slug) - return matchingBundle || [] - }) - }), - map((data) => ({data})), - catchError((error) => { - return of({error}) - }), - scan((state, result) => { - return {...state, ...result} - }, INITIAL_STATE), - ) - ) + return documentPreviewStore + .unstable_observeDocumentIdSet(`sanity::versionOf("${publishedId}")`) + .pipe( + map(({documentIds}) => { + return documentIds.flatMap((id) => { + // eslint-disable-next-line max-nested-callbacks + const matchingBundle = bundles?.find((bundle) => getBundleSlug(id) === bundle.slug) + return matchingBundle || [] + }) + }), + map((data) => ({data})), + catchError((error) => { + return of({error}) + }), + scan((state, result) => { + return {...state, ...result} + }, INITIAL_STATE), + ) }, [bundles, documentPreviewStore, publishedId]) return useObservable(observable, INITIAL_STATE)