Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sanity): use Actions API when unpublishing documents #6094

Merged
merged 2 commits into from
Apr 8, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,25 @@ 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',
//@todo awaiting backend support for this
// query: {skipCrossDatasetReferenceValidation: 'true'},
tag: 'document.unpublish',
juice49 marked this conversation as resolved.
Show resolved Hide resolved
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,
},
],
},
})
},
}
Loading