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

fix(structure): add support to force a version for the pane provider #8176

Merged
merged 1 commit into from
Jan 3, 2025
Merged
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,3 +1,4 @@
import {type ReleaseId} from '@sanity/client'
import {useMemo} from 'react'
import {
EventsProvider,
Expand All @@ -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 (
Expand Down Expand Up @@ -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 (
<EventsProvider value={value}>
<DocumentPaneProvider {...props} historyStore={historyStoreProps} />
<DocumentPaneProvider
{...props}
historyStore={historyStoreProps}
forcedVersion={forcedProviderVersion}
/>
</EventsProvider>
)
}
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand All @@ -139,8 +126,7 @@ export const DocumentPaneProvider = memo((props: DocumentPaneProviderProps) => {
: false,
}
}, [
matchGlobalVersion,
params.historyVersion,
forcedVersion,
perspective.selectedPerspectiveName,
perspective.selectedReleaseId,
perspective.selectedPerspective,
Expand Down
12 changes: 9 additions & 3 deletions packages/sanity/src/structure/panes/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {type ReleaseId} from '@sanity/client'

import {type PaneNode} from '../types'

export interface BaseStructureToolPaneProps<T extends PaneNode['type']> {
Expand All @@ -9,8 +11,12 @@ export interface BaseStructureToolPaneProps<T extends PaneNode['type']> {
isActive?: boolean
pane: Extract<PaneNode, {type: T}>
/**
* 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
}
}
Loading