-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sanity): use actions API when deleting documents (#6115)
* feat(sanity): use actions API when deleting documents * fix(sanity): add skipCrossDatasetReferenceValidation to delete action
- Loading branch information
Showing
1 changed file
with
16 additions
and
8 deletions.
There are no files selected for viewing
24 changes: 16 additions & 8 deletions
24
packages/sanity/src/core/store/_legacy/document/document-pair/operations/delete.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}, | ||
], | ||
}, | ||
}) | ||
}, | ||
} |