From e9a5002c70dee7d575cf85867d80feb23c74c69a Mon Sep 17 00:00:00 2001 From: Pedro Bonamin <46196328+pedrobonamin@users.noreply.github.com> Date: Fri, 3 Jan 2025 17:11:45 +0100 Subject: [PATCH] fix(structure): add support to force a version for the pane provider (#8176) --- .../panes/document/DocumentEventsPane.tsx | 21 ++++++++++++++++-- .../panes/document/DocumentPaneProvider.tsx | 22 ++++--------------- packages/sanity/src/structure/panes/types.ts | 12 +++++++--- 3 files changed, 32 insertions(+), 23 deletions(-) diff --git a/packages/sanity/src/structure/panes/document/DocumentEventsPane.tsx b/packages/sanity/src/structure/panes/document/DocumentEventsPane.tsx index 2a3e4afaa90..d2c632911cc 100644 --- a/packages/sanity/src/structure/panes/document/DocumentEventsPane.tsx +++ b/packages/sanity/src/structure/panes/document/DocumentEventsPane.tsx @@ -1,3 +1,4 @@ +import {type ReleaseId} from '@sanity/client' import {useMemo} from 'react' import { EventsProvider, @@ -24,7 +25,8 @@ export const DocumentEventsPane = (props: DocumentPaneProviderProps) => { const {selectedPerspectiveName} = usePerspective() const {archivedReleases} = useReleases() - const {rev, since, historyVersion} = params + const {rev, since} = params + const historyVersion = params.historyVersion as ReleaseId | undefined const documentId = useMemo(() => { if ( @@ -69,9 +71,24 @@ export const DocumentEventsPane = (props: DocumentPaneProviderProps) => { const value = useMemo(() => eventsStore, [eventsStore]) + const forcedProviderVersion = useMemo(() => { + if (historyVersion) { + return { + selectedPerspectiveName: historyVersion, + selectedReleaseId: historyVersion, + isReleaseLocked: true, + } + } + return undefined + }, [historyVersion]) + return ( - + ) } diff --git a/packages/sanity/src/structure/panes/document/DocumentPaneProvider.tsx b/packages/sanity/src/structure/panes/document/DocumentPaneProvider.tsx index c06645bf480..48f21c94cbc 100644 --- a/packages/sanity/src/structure/panes/document/DocumentPaneProvider.tsx +++ b/packages/sanity/src/structure/panes/document/DocumentPaneProvider.tsx @@ -1,5 +1,4 @@ /* eslint-disable camelcase */ -import {type ReleaseId} from '@sanity/client' import {isActionEnabled} from '@sanity/schema/_internal' import {useTelemetry} from '@sanity/telemetry/react' import { @@ -81,7 +80,7 @@ interface DocumentPaneProviderProps extends DocumentPaneProviderWrapperProps { */ // eslint-disable-next-line complexity, max-statements export const DocumentPaneProvider = memo((props: DocumentPaneProviderProps) => { - const {children, index, pane, paneKey, onFocusPath, matchGlobalVersion = true} = props + const {children, index, pane, paneKey, onFocusPath, forcedVersion} = props const schema = useSchema() const templates = useTemplates() const {setDocumentMeta} = useCopyPaste() @@ -116,20 +115,8 @@ export const DocumentPaneProvider = memo((props: DocumentPaneProviderProps) => { const perspective = usePerspective() const {isReleaseLocked, selectedReleaseId, selectedPerspectiveName} = useMemo(() => { - if (!matchGlobalVersion) { - return { - selectedPerspectiveName: undefined, - isReleaseLocked: false, - selectedReleaseId: undefined, - } - } - const historyVersion = params.historyVersion as ReleaseId | undefined - if (historyVersion) { - return { - selectedPerspectiveName: historyVersion, - selectedReleaseId: historyVersion, - isReleaseLocked: true, - } + if (forcedVersion) { + return forcedVersion } return { selectedPerspectiveName: perspective.selectedPerspectiveName, @@ -139,8 +126,7 @@ export const DocumentPaneProvider = memo((props: DocumentPaneProviderProps) => { : false, } }, [ - matchGlobalVersion, - params.historyVersion, + forcedVersion, perspective.selectedPerspectiveName, perspective.selectedReleaseId, perspective.selectedPerspective, diff --git a/packages/sanity/src/structure/panes/types.ts b/packages/sanity/src/structure/panes/types.ts index 6870e94abef..29f8d478489 100644 --- a/packages/sanity/src/structure/panes/types.ts +++ b/packages/sanity/src/structure/panes/types.ts @@ -1,3 +1,5 @@ +import {type ReleaseId} from '@sanity/client' + import {type PaneNode} from '../types' export interface BaseStructureToolPaneProps { @@ -9,8 +11,12 @@ export interface BaseStructureToolPaneProps { isActive?: boolean pane: Extract /** - * Decides if the pane should check for the global version when determining the document id. - * default: true + * Allows to override the global version with a specific version or release. + * @beta */ - matchGlobalVersion?: boolean + forcedVersion?: { + selectedPerspectiveName: ReleaseId | 'published' | undefined + isReleaseLocked: boolean + selectedReleaseId: ReleaseId | undefined + } }