-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(e2e): ensure custom publish action can patch document before pub…
…lication Co-authored-by: Bjørge Næss <bjoerge@gmail.com>
- Loading branch information
Showing
4 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
dev/test-studio/documentActions/actions/createCustomPublishAction.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,19 @@ | ||
/* eslint-disable react-hooks/rules-of-hooks */ | ||
import {type DocumentActionComponent, type DocumentActionProps, useDocumentOperation} from 'sanity' | ||
|
||
export function createCustomPublishAction(originalAction: DocumentActionComponent) { | ||
return function CustomPublishAction(props: DocumentActionProps) { | ||
const defaultPublishAction = originalAction(props) | ||
const documentOperations = useDocumentOperation(props.id, props.type) | ||
|
||
return { | ||
...defaultPublishAction, | ||
label: 'Custom publish that sets publishedAt to now', | ||
onHandle: () => { | ||
documentOperations.patch.execute([{set: {publishedAt: new Date().toISOString()}}]) | ||
|
||
defaultPublishAction?.onHandle?.() | ||
}, | ||
} | ||
} | ||
} |
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
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