Skip to content

Commit ccb2a4f

Browse files
authored
fix(core): show accurate history for live-edit documents (#8497)
1 parent 2d2df51 commit ccb2a4f

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

packages/sanity/src/structure/panes/document/DocumentEventsPane.tsx

+27-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {type ReleaseId} from '@sanity/client'
2+
import {type ObjectSchemaType} from '@sanity/types'
23
import {useMemo} from 'react'
34
import {
45
EMPTY_ARRAY,
@@ -11,8 +12,10 @@ import {
1112
isDeleteDocumentVersionEvent,
1213
PerspectiveProvider,
1314
useArchivedReleases,
15+
useEditState,
1416
useEventsStore,
1517
usePerspective,
18+
useSchema,
1619
} from 'sanity'
1720

1821
import {usePaneRouter} from '../../components'
@@ -24,14 +27,28 @@ import {type DocumentPaneProviderProps} from './types'
2427
export const DocumentEventsPane = (props: DocumentPaneProviderProps) => {
2528
const {params = EMPTY_PARAMS} = usePaneRouter()
2629
const options = usePaneOptions(props.pane.options, params)
30+
const schema = useSchema()
31+
const documentType = options.type
32+
const schemaType = schema.get(options.type) as ObjectSchemaType | undefined
33+
const liveEdit = Boolean(schemaType?.liveEdit)
2734

28-
const {selectedPerspectiveName} = usePerspective()
35+
const {selectedPerspectiveName, selectedReleaseId, selectedPerspective} = usePerspective()
2936
const {data: archivedReleases} = useArchivedReleases()
37+
const editState = useEditState(
38+
getPublishedId(options.id),
39+
documentType,
40+
'default',
41+
selectedReleaseId,
42+
)
3043

44+
const showingPublishedOnDraft = liveEdit && selectedPerspective === 'drafts' && !editState?.draft
3145
const {rev, since} = params
3246
const historyVersion = params.historyVersion as ReleaseId | undefined
3347

3448
const documentId = useMemo(() => {
49+
if (showingPublishedOnDraft) {
50+
return getPublishedId(options.id)
51+
}
3552
if (
3653
historyVersion &&
3754
archivedReleases.some(
@@ -47,11 +64,18 @@ export const DocumentEventsPane = (props: DocumentPaneProviderProps) => {
4764
if (selectedPerspectiveName === 'published') {
4865
return getPublishedId(options.id)
4966
}
50-
if (selectedPerspectiveName.startsWith('r')) {
67+
if (selectedReleaseId) {
5168
return getVersionId(options.id, selectedPerspectiveName)
5269
}
5370
return options.id
54-
}, [archivedReleases, historyVersion, selectedPerspectiveName, options.id])
71+
}, [
72+
archivedReleases,
73+
historyVersion,
74+
selectedPerspectiveName,
75+
options.id,
76+
showingPublishedOnDraft,
77+
selectedReleaseId,
78+
])
5579

5680
const eventsStore = useEventsStore({documentId, documentType: options.type, rev, since})
5781

0 commit comments

Comments
 (0)