Skip to content

Commit

Permalink
feat(sanity): use actions API when deleting documents (#6115)
Browse files Browse the repository at this point in the history
* feat(sanity): use actions API when deleting documents
* fix(sanity): add skipCrossDatasetReferenceValidation to delete action
  • Loading branch information
bjoerge committed Apr 8, 2024
1 parent b7e1783 commit eeafe54
Showing 1 changed file with 16 additions and 8 deletions.
@@ -1,21 +1,29 @@
import {isLiveEditEnabled} from '../utils/isLiveEditEnabled'
import {type OperationImpl} from './types'

export const del: OperationImpl<[], 'NOTHING_TO_DELETE'> = {
disabled: ({snapshots}) => (snapshots.draft || snapshots.published ? false : 'NOTHING_TO_DELETE'),
execute: ({client, schema, idPair, typeName}) => {
const tx = client.observable.transaction().delete(idPair.publishedId)
execute: ({client: globalClient, schema, idPair, typeName}) => {
const vXClient = globalClient.withConfig({apiVersion: 'X'})

if (isLiveEditEnabled(schema, typeName)) {
return tx.commit({tag: 'document.delete'})
}
const {dataset} = globalClient.config()

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

0 comments on commit eeafe54

Please sign in to comment.