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 unpublishing documents (#6094)
* feat(sanity): use Actions API when unpublishing documents * feat(core): set `skipCrossDatasetReferenceValidation` parameter when unpublishing documents
- Loading branch information
Showing
3 changed files
with
37 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
33 changes: 33 additions & 0 deletions
33
packages/sanity/src/core/store/_legacy/document/document-pair/serverOperations/unpublish.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,33 @@ | ||
import {type OperationImpl} from '../operations/types' | ||
import {isLiveEditEnabled} from '../utils/isLiveEditEnabled' | ||
|
||
type DisabledReason = 'LIVE_EDIT_ENABLED' | 'NOT_PUBLISHED' | ||
|
||
export const unpublish: OperationImpl<[], DisabledReason> = { | ||
disabled: ({schema, snapshots, typeName}) => { | ||
if (isLiveEditEnabled(schema, typeName)) { | ||
return 'LIVE_EDIT_ENABLED' | ||
} | ||
return snapshots.published ? false : 'NOT_PUBLISHED' | ||
}, | ||
execute: ({client: globalClient, idPair}) => { | ||
const vXClient = globalClient.withConfig({apiVersion: 'X'}) | ||
const {dataset} = globalClient.config() | ||
|
||
return vXClient.observable.request({ | ||
url: `/data/actions/${dataset}`, | ||
method: 'post', | ||
query: {skipCrossDatasetReferenceValidation: 'true'}, | ||
tag: 'document.unpublish', | ||
body: { | ||
actions: [ | ||
{ | ||
actionType: 'sanity.action.document.unpublish', | ||
draftId: idPair.draftId, | ||
publishedId: idPair.publishedId, | ||
}, | ||
], | ||
}, | ||
}) | ||
}, | ||
} |