diff --git a/packages/sanity/src/core/store/_legacy/history/createHistoryStore.ts b/packages/sanity/src/core/store/_legacy/history/createHistoryStore.ts index 16b3c2d2bd4..c3221725415 100644 --- a/packages/sanity/src/core/store/_legacy/history/createHistoryStore.ts +++ b/packages/sanity/src/core/store/_legacy/history/createHistoryStore.ts @@ -112,7 +112,7 @@ const getTimelineController = ({ }): TimelineController => { const timeline = new Timeline({ enableTrace: isDev, - publishedId: documentId, + documentId, }) return new TimelineController({ client, diff --git a/packages/sanity/src/core/store/_legacy/history/history/Aligner.ts b/packages/sanity/src/core/store/_legacy/history/history/Aligner.ts index d02e6e589f0..4a5d89e660c 100644 --- a/packages/sanity/src/core/store/_legacy/history/history/Aligner.ts +++ b/packages/sanity/src/core/store/_legacy/history/history/Aligner.ts @@ -90,7 +90,7 @@ export class Aligner { constructor(timeline: Timeline) { this.timeline = timeline this._states = { - draft: emptyVersionState(timeline.draftId), + draft: emptyVersionState(timeline.versionId), published: emptyVersionState(timeline.publishedId), } } diff --git a/packages/sanity/src/core/store/_legacy/history/history/Timeline.ts b/packages/sanity/src/core/store/_legacy/history/history/Timeline.ts index 59d7cfa44f4..e91fd2c1dff 100644 --- a/packages/sanity/src/core/store/_legacy/history/history/Timeline.ts +++ b/packages/sanity/src/core/store/_legacy/history/history/Timeline.ts @@ -1,6 +1,7 @@ import {type Diff} from '@sanity/diff' import {type TransactionLogEventWithEffects} from '@sanity/types' import {applyPatch, incremental} from 'mendoza' +import {isVersionId} from 'sanity' import {type Annotation, type Chunk} from '../../../../field' import {chunkFromTransaction, mergeChunk} from './chunker' @@ -23,7 +24,7 @@ export type ParsedTimeRef = Chunk | 'loading' | 'invalid' * @hidden * @beta */ export interface TimelineOptions { - publishedId: string + documentId: string enableTrace?: boolean } @@ -43,7 +44,7 @@ export class Timeline { reachedEarliestEntry = false publishedId: string - draftId: string + versionId: string private _transactions = new TwoEndedArray() private _chunks = new TwoEndedArray() @@ -58,15 +59,15 @@ export class Timeline { private _recreateTransactionsFrom?: number private _trace?: TraceEvent[] - constructor(opts: TimelineOptions) { - this.publishedId = opts.publishedId - this.draftId = `drafts.${opts.publishedId}` + constructor({documentId, enableTrace}: TimelineOptions) { + this.publishedId = documentId + this.versionId = isVersionId(documentId) ? documentId : `drafts.${documentId}` - if (opts.enableTrace) { + if (enableTrace) { this._trace = [] this._trace.push({ type: 'initial', - publishedId: opts.publishedId, + publishedId: documentId, }) ;(window as any).__sanityTimelineTrace = this._trace } @@ -122,7 +123,7 @@ export class Timeline { } if (entry.version === 'draft') { - transaction.draftEffect = entry.effects as any + transaction.versionEffect = entry.effects as any } else { transaction.publishedEffect = entry.effects as any } @@ -147,7 +148,7 @@ export class Timeline { id: event.id, author: event.author, timestamp: event.timestamp, - draftEffect: event.effects[this.draftId], + versionEffect: event.effects[this.versionId], publishedEffect: event.effects[this.publishedId], }) } @@ -330,8 +331,8 @@ export class Timeline { for (let idx = lastIdx; idx >= firstIdx; idx--) { const transaction = this._transactions.get(idx) - if (transaction.draftEffect) { - draft = applyPatch(draft, transaction.draftEffect.revert) + if (transaction.versionEffect) { + draft = applyPatch(draft, transaction.versionEffect.revert) } if (transaction.publishedEffect) { @@ -375,8 +376,8 @@ export class Timeline { const preDraftValue = draftValue const prePublishedValue = publishedValue - if (transaction.draftEffect) { - draftValue = incremental.applyPatch(draftValue, transaction.draftEffect.apply, meta) + if (transaction.versionEffect) { + draftValue = incremental.applyPatch(draftValue, transaction.versionEffect.apply, meta) } if (transaction.publishedEffect) { diff --git a/packages/sanity/src/core/store/_legacy/history/history/TimelineController.ts b/packages/sanity/src/core/store/_legacy/history/history/TimelineController.ts index 6b854286c1c..b9717ef8a01 100644 --- a/packages/sanity/src/core/store/_legacy/history/history/TimelineController.ts +++ b/packages/sanity/src/core/store/_legacy/history/history/TimelineController.ts @@ -274,7 +274,7 @@ export class TimelineController { private async fetchMoreTransactions() { const publishedId = this.timeline.publishedId - const draftId = this.timeline.draftId + const versionId = this.timeline.versionId const clientConfig = this.client.config() const limit = TRANSLOG_ENTRY_LIMIT @@ -285,7 +285,7 @@ export class TimelineController { } const transactionsUrl = this.client.getUrl( - `/data/history/${clientConfig.dataset}/transactions/${publishedId},${draftId}?${queryParams}`, + `/data/history/${clientConfig.dataset}/transactions/${publishedId},${versionId}?${queryParams}`, ) const stream = await getJsonStream(transactionsUrl, clientConfig.token) const reader = stream.getReader() diff --git a/packages/sanity/src/core/store/_legacy/history/history/chunker.ts b/packages/sanity/src/core/store/_legacy/history/history/chunker.ts index 4c3866cc478..436da3f4d5f 100644 --- a/packages/sanity/src/core/store/_legacy/history/history/chunker.ts +++ b/packages/sanity/src/core/store/_legacy/history/history/chunker.ts @@ -90,7 +90,7 @@ function getChunkState(effect?: MendozaEffectPair): ChunkState { * | published upsert | liveEdit | publish | liveEdit | */ function getChunkType(transaction: Transaction): ChunkType { - const draftState = getChunkState(transaction.draftEffect) + const draftState = getChunkState(transaction.versionEffect) const publishedState = getChunkState(transaction.publishedEffect) if (publishedState === 'unedited') { @@ -125,10 +125,10 @@ function getChunkType(transaction: Transaction): ChunkType { } export function chunkFromTransaction(transaction: Transaction): Chunk { - const modifiedDraft = Boolean(transaction.draftEffect) + const modifiedDraft = Boolean(transaction.versionEffect) const modifiedPublished = Boolean(transaction.publishedEffect) - const draftDeleted = transaction.draftEffect && isDeletePatch(transaction.draftEffect.apply) + const draftDeleted = transaction.versionEffect && isDeletePatch(transaction.versionEffect.apply) const publishedDeleted = transaction.publishedEffect && isDeletePatch(transaction.publishedEffect.apply) diff --git a/packages/sanity/src/core/store/_legacy/history/history/replay.ts b/packages/sanity/src/core/store/_legacy/history/history/replay.ts index af5ef1d6a0c..a22291e98f9 100644 --- a/packages/sanity/src/core/store/_legacy/history/history/replay.ts +++ b/packages/sanity/src/core/store/_legacy/history/history/replay.ts @@ -18,7 +18,7 @@ export function replay(events: TraceEvent[]): Timeline { if (fst?.type !== 'initial') throw new Error('no initial event') const timeline = new Timeline({ - publishedId: fst.publishedId, + documentId: fst.publishedId, }) /* eslint-disable no-console */ diff --git a/packages/sanity/src/core/store/_legacy/history/history/types.ts b/packages/sanity/src/core/store/_legacy/history/history/types.ts index a06eace7969..6daff9304f9 100644 --- a/packages/sanity/src/core/store/_legacy/history/history/types.ts +++ b/packages/sanity/src/core/store/_legacy/history/history/types.ts @@ -26,6 +26,6 @@ export interface Transaction { id: string author: string timestamp: string - draftEffect?: MendozaEffectPair + versionEffect?: MendozaEffectPair publishedEffect?: MendozaEffectPair } diff --git a/packages/sanity/src/core/store/_legacy/history/useTimelineStore.ts b/packages/sanity/src/core/store/_legacy/history/useTimelineStore.ts index 07c34cf1fbb..160c1364d02 100644 --- a/packages/sanity/src/core/store/_legacy/history/useTimelineStore.ts +++ b/packages/sanity/src/core/store/_legacy/history/useTimelineStore.ts @@ -18,7 +18,6 @@ import { type Chunk, DRAFTS_FOLDER, getVersionId, - isVersionId, remoteSnapshots, type RemoteSnapshotVersionEvent, type SelectionState, @@ -119,8 +118,7 @@ export function useTimelineStore({ () => historyStore.getTimelineController({ client, - documentId: - isVersionId(documentId) && version ? getVersionId(documentId, version) : documentId, + documentId: version ? getVersionId(documentId, version) : documentId, documentType, }), [client, documentId, documentType, historyStore, version],