From 973c6f8b9c8d1ebcaeca7abc6c34a3436e3e04cb Mon Sep 17 00:00:00 2001 From: Ash Date: Thu, 18 Jul 2024 12:33:52 +0100 Subject: [PATCH] Revert "wip: allow pairs to include multiple drafts" This reverts commit 92a4c43e1dbee29cfe68040da0cd8b65e448662c. --- .../core/form/studio/formBuilderValueStore.ts | 6 ++-- .../document/document-pair/checkoutPair.ts | 28 ++++++------------- .../document-pair/consistencyStatus.ts | 7 ++--- .../document/document-pair/documentEvents.ts | 4 +-- .../document/document-pair/editState.ts | 5 +--- .../document/document-pair/operationArgs.ts | 6 ++-- .../document-pair/operations/delete.ts | 4 +-- .../operations/discardChanges.ts | 4 +-- .../document-pair/operations/patch.ts | 4 +-- .../document-pair/operations/publish.ts | 4 +-- .../document-pair/operations/restore.ts | 6 +--- .../document-pair/operations/unpublish.ts | 4 +-- .../document/document-pair/remoteSnapshots.ts | 4 +-- .../document-pair/serverOperations/delete.ts | 8 +++--- .../serverOperations/discardChanges.ts | 6 ++-- .../document-pair/serverOperations/patch.ts | 9 ++---- .../document-pair/serverOperations/publish.ts | 5 +--- .../document-pair/serverOperations/restore.ts | 8 +----- .../serverOperations/unpublish.ts | 12 +++----- .../document/document-pair/snapshotPair.ts | 7 ++--- .../document/document-pair/validation.ts | 4 +-- .../store/_legacy/document/document-store.ts | 2 +- .../store/_legacy/document/getPairListener.ts | 12 ++++---- .../src/core/store/_legacy/document/types.ts | 4 +-- .../_legacy/grants/documentPairPermissions.ts | 7 ++--- .../store/_legacy/history/useTimelineStore.ts | 2 +- 26 files changed, 54 insertions(+), 118 deletions(-) diff --git a/packages/sanity/src/core/form/studio/formBuilderValueStore.ts b/packages/sanity/src/core/form/studio/formBuilderValueStore.ts index 1916cd6702c..7b487ef3d22 100644 --- a/packages/sanity/src/core/form/studio/formBuilderValueStore.ts +++ b/packages/sanity/src/core/form/studio/formBuilderValueStore.ts @@ -81,7 +81,6 @@ function wrap(document: DocumentVersion) { } let hasWarned = false -// TODO: Rename -> `checkoutBundle` export function checkoutPair(documentStore: DocumentStore, idPair: IdPair) { if (!hasWarned) { // eslint-disable-next-line no-console @@ -91,11 +90,10 @@ export function checkoutPair(documentStore: DocumentStore, idPair: IdPair) { hasWarned = true } - const {drafts, published} = documentStore.checkoutPair(idPair) + const {draft, published} = documentStore.checkoutPair(idPair) return { - drafts: drafts.map(wrap), - // TODO: Rename -> `public` + draft: wrap(draft), published: wrap(published), } } diff --git a/packages/sanity/src/core/store/_legacy/document/document-pair/checkoutPair.ts b/packages/sanity/src/core/store/_legacy/document/document-pair/checkoutPair.ts index 7501acaef02..72f788086a5 100644 --- a/packages/sanity/src/core/store/_legacy/document/document-pair/checkoutPair.ts +++ b/packages/sanity/src/core/store/_legacy/document/document-pair/checkoutPair.ts @@ -60,13 +60,11 @@ export interface DocumentVersion { /** * @hidden * @beta */ -// TODO: Rename -> `Bundle` export interface Pair { /** @internal */ transactionsPendingEvents$: Observable - // TODO: Rename -> `public` published: DocumentVersion - drafts: DocumentVersion[] + draft: DocumentVersion complete: () => void } @@ -116,12 +114,9 @@ function toActions(idPair: IdPair, mutationParams: Mutation['params']): Action[] } } if (mutations.patch) { - // TODO: Should be dynamic - const draftIndex = 0 return { actionType: 'sanity.action.document.edit', - draftId: idPair.draftIds[draftIndex], - // TODO: Rename -> `publicId` + draftId: idPair.draftId, publishedId: idPair.publishedId, patch: omit(mutations.patch, 'id'), } @@ -183,13 +178,12 @@ function submitCommitRequest( } /** @internal */ -// TODO: Rename -> `checkoutBundle` export function checkoutPair( client: SanityClient, idPair: IdPair, serverActionsEnabled: Observable, ): Pair { - const {publishedId, draftIds} = idPair + const {publishedId, draftId} = idPair const listenerEventsConnector = new Subject() const listenerEvents$ = getPairListener(client, idPair).pipe( @@ -200,11 +194,11 @@ export function checkoutPair( filter((ev) => ev.type === 'reconnect'), ) as Observable - const drafts = draftIds.map((draftId) => - createBufferedDocument(draftId, listenerEvents$.pipe(filter(isMutationEventForDocId(draftId)))), + const draft = createBufferedDocument( + draftId, + listenerEvents$.pipe(filter(isMutationEventForDocId(draftId))), ) - // TODO: Rename -> `public` const published = createBufferedDocument( publishedId, listenerEvents$.pipe(filter(isMutationEventForDocId(publishedId))), @@ -215,10 +209,7 @@ export function checkoutPair( filter((ev): ev is PendingMutationsEvent => ev.type === 'pending'), ) - const commits$ = merge( - ...drafts.map((draft) => draft.commitRequest$), - published.commitRequest$, - ).pipe( + const commits$ = merge(draft.commitRequest$, published.commitRequest$).pipe( mergeMap((commitRequest) => serverActionsEnabled.pipe( take(1), @@ -233,13 +224,12 @@ export function checkoutPair( return { transactionsPendingEvents$, - drafts: drafts.map((draft) => ({ + draft: { ...draft, events: merge(commits$, reconnect$, draft.events).pipe(map(setVersion('draft'))), consistency$: draft.consistency$, remoteSnapshot$: draft.remoteSnapshot$.pipe(map(setVersion('draft'))), - })), - // TODO: Rename -> `public` + }, published: { ...published, events: merge(commits$, reconnect$, published.events).pipe(map(setVersion('published'))), diff --git a/packages/sanity/src/core/store/_legacy/document/document-pair/consistencyStatus.ts b/packages/sanity/src/core/store/_legacy/document/document-pair/consistencyStatus.ts index 9b548785852..f101dc81c2f 100644 --- a/packages/sanity/src/core/store/_legacy/document/document-pair/consistencyStatus.ts +++ b/packages/sanity/src/core/store/_legacy/document/document-pair/consistencyStatus.ts @@ -21,12 +21,9 @@ export const consistencyStatus: ( typeName: string, serverActionsEnabled: Observable, ) => { - // TODO: Should be dynamic - const draftIndex = 0 - // TODO: Rename -> `memoizedBundle` return memoizedPair(client, idPair, typeName, serverActionsEnabled).pipe( - switchMap(({drafts, published}) => - combineLatest([drafts[draftIndex].consistency$, published.consistency$]), + switchMap(({draft, published}) => + combineLatest([draft.consistency$, published.consistency$]), ), map( ([draftIsConsistent, publishedIsConsistent]) => draftIsConsistent && publishedIsConsistent, diff --git a/packages/sanity/src/core/store/_legacy/document/document-pair/documentEvents.ts b/packages/sanity/src/core/store/_legacy/document/document-pair/documentEvents.ts index 3026b0edc4b..6e127a213cc 100644 --- a/packages/sanity/src/core/store/_legacy/document/document-pair/documentEvents.ts +++ b/packages/sanity/src/core/store/_legacy/document/document-pair/documentEvents.ts @@ -17,10 +17,8 @@ export const documentEvents = memoize( typeName: string, serverActionsEnabled: Observable, ): Observable => { - // TODO: Should be dynamic - const draftIndex = 0 return memoizedPair(client, idPair, typeName, serverActionsEnabled).pipe( - switchMap(({drafts, published}) => merge(drafts[draftIndex].events, published.events)), + switchMap(({draft, published}) => merge(draft.events, published.events)), ) }, memoizeKeyGen, diff --git a/packages/sanity/src/core/store/_legacy/document/document-pair/editState.ts b/packages/sanity/src/core/store/_legacy/document/document-pair/editState.ts index 14d09d8ec88..adba9e7588f 100644 --- a/packages/sanity/src/core/store/_legacy/document/document-pair/editState.ts +++ b/packages/sanity/src/core/store/_legacy/document/document-pair/editState.ts @@ -21,7 +21,6 @@ export interface EditStateFor { type: string transactionSyncLock: TransactionSyncLockState | null draft: SanityDocument | null - // TODO: Rename -> `public` published: SanityDocument | null liveEdit: boolean ready: boolean @@ -41,12 +40,10 @@ export const editState = memoize( typeName: string, ): Observable => { const liveEdit = isLiveEditEnabled(ctx.schema, typeName) - // TODO: Should be dynamic - const draftIndex = 0 return snapshotPair(ctx.client, idPair, typeName, ctx.serverActionsEnabled).pipe( switchMap((versions) => combineLatest([ - versions.drafts[draftIndex].snapshots$, + versions.draft.snapshots$, versions.published.snapshots$, versions.transactionsPendingEvents$.pipe( map((ev: PendingMutationsEvent) => (ev.phase === 'begin' ? LOCKED : NOT_LOCKED)), diff --git a/packages/sanity/src/core/store/_legacy/document/document-pair/operationArgs.ts b/packages/sanity/src/core/store/_legacy/document/document-pair/operationArgs.ts index b301fdc8412..de0b0b5ab29 100644 --- a/packages/sanity/src/core/store/_legacy/document/document-pair/operationArgs.ts +++ b/packages/sanity/src/core/store/_legacy/document/document-pair/operationArgs.ts @@ -24,12 +24,10 @@ export const operationArgs = memoize( idPair: IdPair, typeName: string, ): Observable => { - // TODO: Should be dynamic - const draftIndex = 0 return snapshotPair(ctx.client, idPair, typeName, ctx.serverActionsEnabled).pipe( switchMap((versions) => combineLatest([ - versions.drafts[draftIndex].snapshots$, + versions.draft.snapshots$, versions.published.snapshots$, ctx.serverActionsEnabled, ]).pipe( @@ -40,7 +38,7 @@ export const operationArgs = memoize( idPair, typeName, snapshots: {draft, published}, - draft: versions.drafts[draftIndex], + draft: versions.draft, published: versions.published, }), ), diff --git a/packages/sanity/src/core/store/_legacy/document/document-pair/operations/delete.ts b/packages/sanity/src/core/store/_legacy/document/document-pair/operations/delete.ts index 31dc7e18c99..f547d8e1c42 100644 --- a/packages/sanity/src/core/store/_legacy/document/document-pair/operations/delete.ts +++ b/packages/sanity/src/core/store/_legacy/document/document-pair/operations/delete.ts @@ -10,9 +10,7 @@ export const del: OperationImpl<[], 'NOTHING_TO_DELETE'> = { return tx.commit({tag: 'document.delete'}) } - idPair.draftIds.forEach((draftId) => tx.delete(draftId)) - - return tx.commit({ + return tx.delete(idPair.draftId).commit({ tag: 'document.delete', // this disables referential integrity for cross-dataset references. we // have this set because we warn against deletes in the `ConfirmDeleteDialog` diff --git a/packages/sanity/src/core/store/_legacy/document/document-pair/operations/discardChanges.ts b/packages/sanity/src/core/store/_legacy/document/document-pair/operations/discardChanges.ts index c6ef878ecb2..ac698ec3718 100644 --- a/packages/sanity/src/core/store/_legacy/document/document-pair/operations/discardChanges.ts +++ b/packages/sanity/src/core/store/_legacy/document/document-pair/operations/discardChanges.ts @@ -13,11 +13,9 @@ export const discardChanges: OperationImpl<[], DisabledReason> = { return false }, execute: ({client, idPair}) => { - // TODO: Should be dynamic - const draftIndex = 0 return client.observable .transaction() - .delete(idPair.draftIds[draftIndex]) + .delete(idPair.draftId) .commit({tag: 'document.discard-changes'}) }, } diff --git a/packages/sanity/src/core/store/_legacy/document/document-pair/operations/patch.ts b/packages/sanity/src/core/store/_legacy/document/document-pair/operations/patch.ts index 0d0d630627b..f67b96767ec 100644 --- a/packages/sanity/src/core/store/_legacy/document/document-pair/operations/patch.ts +++ b/packages/sanity/src/core/store/_legacy/document/document-pair/operations/patch.ts @@ -19,13 +19,11 @@ export const patch: OperationImpl<[patches: any[], initialDocument?: Record = { }) } - // TODO: Should be dynamic - const draftIndex = 0 - tx.delete(idPair.draftIds[draftIndex]) + tx.delete(idPair.draftId) return tx.commit({tag: 'document.publish', visibility: 'async'}) }, diff --git a/packages/sanity/src/core/store/_legacy/document/document-pair/operations/restore.ts b/packages/sanity/src/core/store/_legacy/document/document-pair/operations/restore.ts index 9df8ff6d4b5..224de4e1a8b 100644 --- a/packages/sanity/src/core/store/_legacy/document/document-pair/operations/restore.ts +++ b/packages/sanity/src/core/store/_legacy/document/document-pair/operations/restore.ts @@ -4,11 +4,7 @@ import {type OperationImpl} from './types' export const restore: OperationImpl<[fromRevision: string]> = { disabled: (): false => false, execute: ({historyStore, schema, idPair, typeName}, fromRevision: string) => { - // TODO: Should be dynamic - const draftIndex = 0 - const targetId = isLiveEditEnabled(schema, typeName) - ? idPair.publishedId - : idPair.draftIds[draftIndex] + const targetId = isLiveEditEnabled(schema, typeName) ? idPair.publishedId : idPair.draftId return historyStore.restore(idPair.publishedId, targetId, fromRevision) }, } diff --git a/packages/sanity/src/core/store/_legacy/document/document-pair/operations/unpublish.ts b/packages/sanity/src/core/store/_legacy/document/document-pair/operations/unpublish.ts index c670e05d17d..232d070d809 100644 --- a/packages/sanity/src/core/store/_legacy/document/document-pair/operations/unpublish.ts +++ b/packages/sanity/src/core/store/_legacy/document/document-pair/operations/unpublish.ts @@ -16,11 +16,9 @@ export const unpublish: OperationImpl<[], DisabledReason> = { let tx = client.observable.transaction().delete(idPair.publishedId) if (snapshots.published) { - // TODO: Should be dynamic - const draftIndex = 0 tx = tx.createIfNotExists({ ...omit(snapshots.published, '_updatedAt'), - _id: idPair.draftIds[draftIndex], + _id: idPair.draftId, _type: snapshots.published._type, }) } diff --git a/packages/sanity/src/core/store/_legacy/document/document-pair/remoteSnapshots.ts b/packages/sanity/src/core/store/_legacy/document/document-pair/remoteSnapshots.ts index dcb08ef24ba..91db8f91fde 100644 --- a/packages/sanity/src/core/store/_legacy/document/document-pair/remoteSnapshots.ts +++ b/packages/sanity/src/core/store/_legacy/document/document-pair/remoteSnapshots.ts @@ -17,9 +17,7 @@ export const remoteSnapshots = memoize( serverActionsEnabled: Observable, ): Observable => { return memoizedPair(client, idPair, typeName, serverActionsEnabled).pipe( - switchMap(({published, drafts}) => - merge(published.remoteSnapshot$, ...drafts.map((draft) => draft.remoteSnapshot$)), - ), + switchMap(({published, draft}) => merge(published.remoteSnapshot$, draft.remoteSnapshot$)), ) }, memoizeKeyGen, diff --git a/packages/sanity/src/core/store/_legacy/document/document-pair/serverOperations/delete.ts b/packages/sanity/src/core/store/_legacy/document/document-pair/serverOperations/delete.ts index f51b04be4a9..4cc1f1c4796 100644 --- a/packages/sanity/src/core/store/_legacy/document/document-pair/serverOperations/delete.ts +++ b/packages/sanity/src/core/store/_legacy/document/document-pair/serverOperations/delete.ts @@ -13,10 +13,10 @@ export const del: OperationImpl<[], 'NOTHING_TO_DELETE'> = { //the delete action requires a published doc -- discard if not present if (!snapshots.published) { return actionsApiClient(client).observable.action( - idPair.draftIds.map((draftId) => ({ + { actionType: 'sanity.action.document.discard', - draftId, - })), + draftId: idPair.draftId, + }, {tag: 'document.delete'}, ) } @@ -24,7 +24,7 @@ export const del: OperationImpl<[], 'NOTHING_TO_DELETE'> = { return actionsApiClient(client).observable.action( { actionType: 'sanity.action.document.delete', - includeDrafts: idPair.draftIds, + includeDrafts: snapshots.draft ? [idPair.draftId] : [], publishedId: idPair.publishedId, }, { diff --git a/packages/sanity/src/core/store/_legacy/document/document-pair/serverOperations/discardChanges.ts b/packages/sanity/src/core/store/_legacy/document/document-pair/serverOperations/discardChanges.ts index e2de59e8cd4..504c7db39a3 100644 --- a/packages/sanity/src/core/store/_legacy/document/document-pair/serverOperations/discardChanges.ts +++ b/packages/sanity/src/core/store/_legacy/document/document-pair/serverOperations/discardChanges.ts @@ -15,10 +15,10 @@ export const discardChanges: OperationImpl<[], DisabledReason> = { }, execute: ({client, idPair}) => { return actionsApiClient(client).observable.action( - idPair.draftIds.map((draftId) => ({ + { actionType: 'sanity.action.document.discard', - draftId, - })), + draftId: idPair.draftId, + }, {tag: 'document.discard-changes'}, ) }, diff --git a/packages/sanity/src/core/store/_legacy/document/document-pair/serverOperations/patch.ts b/packages/sanity/src/core/store/_legacy/document/document-pair/serverOperations/patch.ts index bb99184f957..4fce51f99a3 100644 --- a/packages/sanity/src/core/store/_legacy/document/document-pair/serverOperations/patch.ts +++ b/packages/sanity/src/core/store/_legacy/document/document-pair/serverOperations/patch.ts @@ -30,30 +30,25 @@ export const patch: OperationImpl<[patches: any[], initialDocument?: Record = { throw new Error('cannot execute "publish" when draft is missing') } - // TODO: Should be dynamic - const draftIndex = 0 - return actionsApiClient(client).observable.action( { actionType: 'sanity.action.document.publish', - draftId: idPair.draftIds[draftIndex], + draftId: idPair.draftId, publishedId: idPair.publishedId, // Optimistic locking using `ifPublishedRevisionId` ensures that concurrent publish action // invocations do not override each other. diff --git a/packages/sanity/src/core/store/_legacy/document/document-pair/serverOperations/restore.ts b/packages/sanity/src/core/store/_legacy/document/document-pair/serverOperations/restore.ts index 2657addbb5c..3ea6ec2d3f6 100644 --- a/packages/sanity/src/core/store/_legacy/document/document-pair/serverOperations/restore.ts +++ b/packages/sanity/src/core/store/_legacy/document/document-pair/serverOperations/restore.ts @@ -4,13 +4,7 @@ import {isLiveEditEnabled} from '../utils/isLiveEditEnabled' export const restore: OperationImpl<[fromRevision: string]> = { disabled: (): false => false, execute: ({snapshots, historyStore, schema, idPair, typeName}, fromRevision: string) => { - // TODO: Should be dynamic - const draftIndex = 0 - - const targetId = isLiveEditEnabled(schema, typeName) - ? idPair.publishedId - : idPair.draftIds[draftIndex] - + const targetId = isLiveEditEnabled(schema, typeName) ? idPair.publishedId : idPair.draftId return historyStore.restore(idPair.publishedId, targetId, fromRevision, { fromDeleted: !snapshots.draft && !snapshots.published, useServerDocumentActions: true, diff --git a/packages/sanity/src/core/store/_legacy/document/document-pair/serverOperations/unpublish.ts b/packages/sanity/src/core/store/_legacy/document/document-pair/serverOperations/unpublish.ts index 8a141446b25..f67ffe05104 100644 --- a/packages/sanity/src/core/store/_legacy/document/document-pair/serverOperations/unpublish.ts +++ b/packages/sanity/src/core/store/_legacy/document/document-pair/serverOperations/unpublish.ts @@ -11,15 +11,12 @@ export const unpublish: OperationImpl<[], DisabledReason> = { } return snapshots.published ? false : 'NOT_PUBLISHED' }, - execute: ({client, idPair}) => { - // TODO: Should be dynamic - const draftIndex = 0 - - return actionsApiClient(client).observable.action( + execute: ({client, idPair}) => + actionsApiClient(client).observable.action( { // This operation is run when "unpublish anyway" is clicked actionType: 'sanity.action.document.unpublish', - draftId: idPair.draftIds[draftIndex], + draftId: idPair.draftId, publishedId: idPair.publishedId, }, { @@ -29,6 +26,5 @@ export const unpublish: OperationImpl<[], DisabledReason> = { // UI. skipCrossDatasetReferenceValidation: true, }, - ) - }, + ), } diff --git a/packages/sanity/src/core/store/_legacy/document/document-pair/snapshotPair.ts b/packages/sanity/src/core/store/_legacy/document/document-pair/snapshotPair.ts index fb9120d72b4..0efc43a5461 100644 --- a/packages/sanity/src/core/store/_legacy/document/document-pair/snapshotPair.ts +++ b/packages/sanity/src/core/store/_legacy/document/document-pair/snapshotPair.ts @@ -53,10 +53,9 @@ export interface DocumentVersionSnapshots { } /** @internal */ -// TODO: Rename interface SnapshotPair { transactionsPendingEvents$: Observable - drafts: DocumentVersionSnapshots[] + draft: DocumentVersionSnapshots published: DocumentVersionSnapshots } @@ -69,11 +68,11 @@ export const snapshotPair = memoize( serverActionsEnabled: Observable, ): Observable => { return memoizedPair(client, idPair, typeName, serverActionsEnabled).pipe( - map(({published, drafts, transactionsPendingEvents$}): SnapshotPair => { + map(({published, draft, transactionsPendingEvents$}): SnapshotPair => { return { transactionsPendingEvents$, published: withSnapshots(published), - drafts: drafts.map(withSnapshots), + draft: withSnapshots(draft), } }), publishReplay(1), diff --git a/packages/sanity/src/core/store/_legacy/document/document-pair/validation.ts b/packages/sanity/src/core/store/_legacy/document/document-pair/validation.ts index 24c52c596a9..8cf895fe80a 100644 --- a/packages/sanity/src/core/store/_legacy/document/document-pair/validation.ts +++ b/packages/sanity/src/core/store/_legacy/document/document-pair/validation.ts @@ -32,10 +32,10 @@ export const validation = memoize( i18n: LocaleSource serverActionsEnabled: Observable }, - {draftIds, publishedId}: IdPair, + {draftId, publishedId}: IdPair, typeName: string, ): Observable => { - const document$ = editState(ctx, {draftIds, publishedId}, typeName).pipe( + const document$ = editState(ctx, {draftId, publishedId}, typeName).pipe( map(({draft, published}) => draft || published), throttleTime(DOC_UPDATE_DELAY, asyncScheduler, {trailing: true}), distinctUntilChanged((prev, next) => { diff --git a/packages/sanity/src/core/store/_legacy/document/document-store.ts b/packages/sanity/src/core/store/_legacy/document/document-store.ts index 9be214ad009..d40fba36ce4 100644 --- a/packages/sanity/src/core/store/_legacy/document/document-store.ts +++ b/packages/sanity/src/core/store/_legacy/document/document-store.ts @@ -38,7 +38,7 @@ function getIdPairFromPublished(publishedId: string): IdPair { throw new Error('editOpsOf does not expect a draft id.') } - return {publishedId, draftIds: [getDraftId(publishedId)]} + return {publishedId, draftId: getDraftId(publishedId)} } /** diff --git a/packages/sanity/src/core/store/_legacy/document/getPairListener.ts b/packages/sanity/src/core/store/_legacy/document/getPairListener.ts index aef4ef6eadd..aadbc5384c0 100644 --- a/packages/sanity/src/core/store/_legacy/document/getPairListener.ts +++ b/packages/sanity/src/core/store/_legacy/document/getPairListener.ts @@ -64,16 +64,14 @@ export function getPairListener( idPair: IdPair, options: PairListenerOptions = {}, ): Observable { - const {publishedId, draftIds} = idPair - // TODO: Should be dynamic - const draftIndex = 0 + const {publishedId, draftId} = idPair return defer( () => client.observable.listen( - `*[_id == $publishedId || _id in($draftIds)]`, + `*[_id == $publishedId || _id == $draftId]`, { publishedId, - draftIds, + draftId, }, { includeResult: false, @@ -87,7 +85,7 @@ export function getPairListener( event.type === 'welcome' ? fetchInitialDocumentSnapshots().pipe( concatMap((snapshots) => [ - createSnapshotEvent(draftIds[draftIndex], snapshots.draft), + createSnapshotEvent(draftId, snapshots.draft), createSnapshotEvent(publishedId, snapshots.published), ]), ) @@ -133,7 +131,7 @@ export function getPairListener( function fetchInitialDocumentSnapshots(): Observable { return client.observable - .getDocuments([...draftIds, publishedId], {tag: 'document.snapshots'}) + .getDocuments([draftId, publishedId], {tag: 'document.snapshots'}) .pipe( map(([draft, published]) => ({ draft, diff --git a/packages/sanity/src/core/store/_legacy/document/types.ts b/packages/sanity/src/core/store/_legacy/document/types.ts index 360720c6496..0ad2cf6e0a1 100644 --- a/packages/sanity/src/core/store/_legacy/document/types.ts +++ b/packages/sanity/src/core/store/_legacy/document/types.ts @@ -34,9 +34,7 @@ export interface PendingMutationsEvent { } /** @internal */ -// TODO: Rename -> `IdBundle` export interface IdPair { - draftIds: string[] - // TODO: Rename -> `publicId` + draftId: string publishedId: string } diff --git a/packages/sanity/src/core/store/_legacy/grants/documentPairPermissions.ts b/packages/sanity/src/core/store/_legacy/grants/documentPairPermissions.ts index cf1d8bc204a..5c84b123398 100644 --- a/packages/sanity/src/core/store/_legacy/grants/documentPairPermissions.ts +++ b/packages/sanity/src/core/store/_legacy/grants/documentPairPermissions.ts @@ -199,17 +199,14 @@ export function getDocumentPairPermissions({ const liveEdit = Boolean(getSchemaType(schema, type).liveEdit) - // TODO: Should be dynamic - const draftIndex = 0 - return snapshotPair( client, - {draftIds: [getDraftId(id)], publishedId: getPublishedId(id)}, + {draftId: getDraftId(id), publishedId: getPublishedId(id)}, type, serverActionsEnabled, ).pipe( switchMap((pair) => - combineLatest([pair.drafts[draftIndex].snapshots$, pair.published.snapshots$]).pipe( + combineLatest([pair.draft.snapshots$, pair.published.snapshots$]).pipe( map(([draft, published]) => ({draft, published})), ), ), diff --git a/packages/sanity/src/core/store/_legacy/history/useTimelineStore.ts b/packages/sanity/src/core/store/_legacy/history/useTimelineStore.ts index 42dfc39d239..403a755fbb7 100644 --- a/packages/sanity/src/core/store/_legacy/history/useTimelineStore.ts +++ b/packages/sanity/src/core/store/_legacy/history/useTimelineStore.ts @@ -173,7 +173,7 @@ export function useTimelineStore({ if (!snapshotsSubscriptionRef.current) { snapshotsSubscriptionRef.current = remoteSnapshots( client, - {draftIds: [`drafts.${documentId}`], publishedId: documentId}, + {draftId: `drafts.${documentId}`, publishedId: documentId}, documentType, serverActionsEnabled, ).subscribe((ev: RemoteSnapshotVersionEvent) => {