From 47fcbed54440010e06c7cb36ef5b59cc1f774088 Mon Sep 17 00:00:00 2001 From: pedrobonamin Date: Wed, 4 Sep 2024 09:52:02 +0200 Subject: [PATCH 1/2] fix(core): update useReleaseHistory to fetch with the version documents --- .../src/core/releases/tool/detail/ReleaseDetail.tsx | 2 +- .../tool/detail/documentTable/useReleaseHistory.ts | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/sanity/src/core/releases/tool/detail/ReleaseDetail.tsx b/packages/sanity/src/core/releases/tool/detail/ReleaseDetail.tsx index 16d78dcff4a..c639aa7bed6 100644 --- a/packages/sanity/src/core/releases/tool/detail/ReleaseDetail.tsx +++ b/packages/sanity/src/core/releases/tool/detail/ReleaseDetail.tsx @@ -45,7 +45,7 @@ export const ReleaseDetail = () => { const {loading: documentsLoading, results} = useBundleDocuments(parsedBundleId) const documentIds = results.map((result) => result.document?._id) - const history = useReleaseHistory(documentIds) + const history = useReleaseHistory(documentIds, parsedBundleId) const bundle = data?.find((storeBundle) => storeBundle._id === parsedBundleId) const bundleHasDocuments = !!results.length diff --git a/packages/sanity/src/core/releases/tool/detail/documentTable/useReleaseHistory.ts b/packages/sanity/src/core/releases/tool/detail/documentTable/useReleaseHistory.ts index babd4658e44..0ceb7b9106d 100644 --- a/packages/sanity/src/core/releases/tool/detail/documentTable/useReleaseHistory.ts +++ b/packages/sanity/src/core/releases/tool/detail/documentTable/useReleaseHistory.ts @@ -1,5 +1,5 @@ import {useCallback, useEffect, useMemo, useState} from 'react' -import {getPublishedId, type TransactionLogEventWithEffects, useClient} from 'sanity' +import {getVersionId, type TransactionLogEventWithEffects, useClient} from 'sanity' import {getJsonStream} from '../../../../store/_legacy/history/history/getJsonStream' import {API_VERSION} from '../../../../tasks/constants' @@ -12,7 +12,10 @@ export type DocumentHistory = { } // TODO: Update this to contemplate the _revision change on any of the internal bundle documents, and fetch only the history of that document if changes. -export function useReleaseHistory(bundleDocumentsIds: string[]): { +export function useReleaseHistory( + bundleDocumentsIds: string[], + releaseId: string, +): { documentsHistory: Record collaborators: string[] loading: boolean @@ -21,14 +24,14 @@ export function useReleaseHistory(bundleDocumentsIds: string[]): { const {dataset, token} = client.config() const [history, setHistory] = useState([]) const queryParams = `tag=sanity.studio.tasks.history&effectFormat=mendoza&excludeContent=true&includeIdentifiedDocumentsOnly=true` - - const publishedIds = bundleDocumentsIds.map((id) => getPublishedId(id)).join(',') + const publishedIds = bundleDocumentsIds.map((id) => getVersionId(id, releaseId)).join(',') const transactionsUrl = client.getUrl( `/data/history/${dataset}/transactions/${publishedIds}?${queryParams}`, ) const fetchAndParseAll = useCallback(async () => { if (!publishedIds) return + if (!releaseId) return const transactions: TransactionLogEventWithEffects[] = [] const stream = await getJsonStream(transactionsUrl, token) const reader = stream.getReader() @@ -44,7 +47,7 @@ export function useReleaseHistory(bundleDocumentsIds: string[]): { transactions.push(result.value) } setHistory(transactions) - }, [publishedIds, transactionsUrl, token]) + }, [publishedIds, transactionsUrl, token, releaseId]) useEffect(() => { fetchAndParseAll() From 5cdee0bcd2f836791d51ab8058d38e44a5d6ae26 Mon Sep 17 00:00:00 2001 From: pedrobonamin Date: Wed, 4 Sep 2024 14:10:44 +0200 Subject: [PATCH 2/2] fix(core): rename publishedIds to versionIds in useReleaseHistory --- .../tool/detail/documentTable/useReleaseHistory.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/sanity/src/core/releases/tool/detail/documentTable/useReleaseHistory.ts b/packages/sanity/src/core/releases/tool/detail/documentTable/useReleaseHistory.ts index 0ceb7b9106d..07b71b4dce7 100644 --- a/packages/sanity/src/core/releases/tool/detail/documentTable/useReleaseHistory.ts +++ b/packages/sanity/src/core/releases/tool/detail/documentTable/useReleaseHistory.ts @@ -24,13 +24,13 @@ export function useReleaseHistory( const {dataset, token} = client.config() const [history, setHistory] = useState([]) const queryParams = `tag=sanity.studio.tasks.history&effectFormat=mendoza&excludeContent=true&includeIdentifiedDocumentsOnly=true` - const publishedIds = bundleDocumentsIds.map((id) => getVersionId(id, releaseId)).join(',') + const versionIds = bundleDocumentsIds.map((id) => getVersionId(id, releaseId)).join(',') const transactionsUrl = client.getUrl( - `/data/history/${dataset}/transactions/${publishedIds}?${queryParams}`, + `/data/history/${dataset}/transactions/${versionIds}?${queryParams}`, ) const fetchAndParseAll = useCallback(async () => { - if (!publishedIds) return + if (!versionIds) return if (!releaseId) return const transactions: TransactionLogEventWithEffects[] = [] const stream = await getJsonStream(transactionsUrl, token) @@ -47,7 +47,7 @@ export function useReleaseHistory( transactions.push(result.value) } setHistory(transactions) - }, [publishedIds, transactionsUrl, token, releaseId]) + }, [versionIds, transactionsUrl, token, releaseId]) useEffect(() => { fetchAndParseAll()