-
Notifications
You must be signed in to change notification settings - Fork 430
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 discarding drafts
- Loading branch information
1 parent
1f6b8a8
commit c1755d1
Showing
3 changed files
with
38 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
34 changes: 34 additions & 0 deletions
34
...s/sanity/src/core/store/_legacy/document/document-pair/serverOperations/discardChanges.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,34 @@ | ||
import {type OperationImpl} from '../operations/types' | ||
|
||
type DisabledReason = 'NO_CHANGES' | 'NOT_PUBLISHED' | ||
|
||
export const discardChanges: OperationImpl<[], DisabledReason> = { | ||
disabled: ({snapshots}) => { | ||
if (!snapshots.draft) { | ||
return 'NO_CHANGES' | ||
} | ||
if (!snapshots.published) { | ||
return 'NOT_PUBLISHED' | ||
} | ||
return false | ||
}, | ||
execute: ({client: globalClient, idPair}) => { | ||
const vXClient = globalClient.withConfig({apiVersion: 'X'}) | ||
const {dataset} = globalClient.config() | ||
|
||
return vXClient.observable.request({ | ||
url: `/data/actions/${dataset}`, | ||
method: 'post', | ||
tag: 'document.discard-changes', | ||
body: { | ||
actions: [ | ||
{ | ||
actionType: 'sanity.action.document.discard', | ||
draftId: idPair.draftId, | ||
publishedId: idPair.publishedId, | ||
}, | ||
], | ||
}, | ||
}) | ||
}, | ||
} |