Skip to content

Commit

Permalink
fix(core): update versionRevisionId when creating unpublish document …
Browse files Browse the repository at this point in the history
…event
  • Loading branch information
pedrobonamin committed Oct 2, 2024
1 parent b97e5ae commit da3a1e6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ describe('getDocumentEvents', () => {
timestamp: '2024-09-30T14:40:02.837538Z',
type: 'document.unpublish',
versionId: 'drafts.foo', // Is it correct to use the draft version id here, we are creating a draft by unpublishing the document.
versionRevisionId: 'publish-tx', //
versionRevisionId: 'unpublish-tx', //
},
{
type: 'document.publishVersion',
Expand Down Expand Up @@ -763,7 +763,7 @@ describe('getDocumentEvents', () => {
timestamp: '2024-09-30T15:04:37.077740Z',
author: 'p8xDvUMxC',
versionId: undefined, // Draft already exists, a new draft was not created from this tx
versionRevisionId: 'publish-draft-tx',
versionRevisionId: undefined, // Draft already exists, a new draft was not created from this tx, no revisionId to assign
releaseId: undefined,
},
{
Expand Down Expand Up @@ -1696,7 +1696,7 @@ describe('getDocumentEvents', () => {
author: 'p8xDvUMxC',
type: 'document.unpublish',
versionId: 'drafts.foo',
versionRevisionId: '7X3uqAgvtaInRcPnekXqDV',
versionRevisionId: 'Cs9MM9AmleFTukvUAmGEQ4',
},
{
timestamp: '2024-10-01T13:56:19.108493Z',
Expand Down
7 changes: 3 additions & 4 deletions packages/sanity/src/core/store/events/getDocumentEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,10 @@ function getEventFromTransaction(
transaction.documentIDs.length > 1 && transaction.documentIDs.includes(draftId)
? draftId
: undefined,
// TODO: Should this be the actual transaction id that created the draft document?
// The revision id of the last edit in the publish document
versionRevisionId:
previousTransactions.find((t) => t.documentIDs.includes(publishedId))?.id ||
'not-found',
transaction.documentIDs.length > 1 && transaction.documentIDs.includes(draftId)
? transaction.id
: undefined,
releaseId: getVersionFromId(documentId),
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/sanity/src/core/store/events/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ export interface UnpublishDocumentEvent extends BaseEvent {

/** The version that was created based on it */
versionId: string | undefined
versionRevisionId: string
versionRevisionId?: string
releaseId?: string
}

Expand Down

0 comments on commit da3a1e6

Please sign in to comment.