-
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
3 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
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
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
29 changes: 29 additions & 0 deletions
29
packages/sanity/src/core/store/_legacy/document/document-pair/serverOperations/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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import {type OperationImpl} from '../operations/types' | ||
|
||
export const del: OperationImpl<[], 'NOTHING_TO_DELETE'> = { | ||
disabled: ({snapshots}) => (snapshots.draft || snapshots.published ? false : 'NOTHING_TO_DELETE'), | ||
execute: ({client: globalClient, schema, idPair, typeName}) => { | ||
const vXClient = globalClient.withConfig({apiVersion: 'X'}) | ||
|
||
const {dataset} = globalClient.config() | ||
|
||
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 | ||
query: {skipCrossDatasetReferenceValidation: 'true'}, | ||
body: { | ||
actions: [ | ||
{ | ||
actionType: 'sanity.action.document.delete', | ||
draftId: idPair.draftId, | ||
publishedId: idPair.publishedId, | ||
}, | ||
], | ||
}, | ||
}) | ||
}, | ||
} |