-
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 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
40 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
36 changes: 36 additions & 0 deletions
36
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,36 @@ | ||
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', | ||
// this disables referential integrity for cross-dataset references. we | ||
// have this set because we warn against unpublishes in the `ConfirmDeleteDialog` | ||
// UI. This operation is run when "unpublish anyway" is clicked | ||
query: {skipCrossDatasetReferenceValidation: 'true'}, | ||
tag: 'document.unpublish', | ||
body: { | ||
actions: [ | ||
{ | ||
actionType: 'sanity.action.document.unpublish', | ||
draftId: idPair.draftId, | ||
publishedId: idPair.publishedId, | ||
}, | ||
], | ||
}, | ||
}) | ||
}, | ||
} |