Skip to content

Commit

Permalink
feat(sanity): use Actions API when unpublishing documents (#6094)
Browse files Browse the repository at this point in the history
* feat(sanity): use Actions API when unpublishing documents

* feat(core): set `skipCrossDatasetReferenceValidation` parameter when unpublishing documents
  • Loading branch information
juice49 committed Apr 8, 2024
1 parent 128a569 commit 3d156cf
Showing 1 changed file with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import {omit} from 'lodash'

import {isLiveEditEnabled} from '../utils/isLiveEditEnabled'
import {type OperationImpl} from './types'

Expand All @@ -12,24 +10,24 @@ export const unpublish: OperationImpl<[], DisabledReason> = {
}
return snapshots.published ? false : 'NOT_PUBLISHED'
},
execute: ({client, idPair, snapshots}) => {
let tx = client.observable.transaction().delete(idPair.publishedId)

if (snapshots.published) {
tx = tx.createIfNotExists({
...omit(snapshots.published, '_updatedAt'),
_id: idPair.draftId,
_type: snapshots.published._type,
})
}
execute: ({client: globalClient, idPair}) => {
const vXClient = globalClient.withConfig({apiVersion: 'X'})
const {dataset} = globalClient.config()

return tx.commit({
return vXClient.observable.request({
url: `/data/actions/${dataset}`,
method: 'post',
query: {skipCrossDatasetReferenceValidation: 'true'},
tag: 'document.unpublish',
visibility: 'async',
// this disables referential integrity for cross-dataset references. we
// have this set because we warn against unpublishes in the `ConfirmDeleteDialog`
// UI. This operation is run when "unpublish anyway" is clicked
skipCrossDatasetReferenceValidation: true,
body: {
actions: [
{
actionType: 'sanity.action.document.unpublish',
draftId: idPair.draftId,
publishedId: idPair.publishedId,
},
],
},
})
},
}

0 comments on commit 3d156cf

Please sign in to comment.