diff --git a/dev/test-studio/documentActions/actions/createCustomPublishAction.ts b/dev/test-studio/documentActions/actions/createCustomPublishAction.ts index 52ab480f3e6..b7e31ad2ea1 100644 --- a/dev/test-studio/documentActions/actions/createCustomPublishAction.ts +++ b/dev/test-studio/documentActions/actions/createCustomPublishAction.ts @@ -1,7 +1,9 @@ /* eslint-disable react-hooks/rules-of-hooks */ import {type DocumentActionComponent, type DocumentActionProps, useDocumentOperation} from 'sanity' -export function createCustomPublishAction(originalAction: DocumentActionComponent) { +export function createCustomPublishAction( + originalAction: DocumentActionComponent, +): DocumentActionComponent { return function CustomPublishAction(props: DocumentActionProps) { const defaultPublishAction = originalAction(props) const documentOperations = useDocumentOperation(props.id, props.type) @@ -11,7 +13,24 @@ export function createCustomPublishAction(originalAction: DocumentActionComponen label: 'Custom publish that sets publishedAt to now', onHandle: () => { documentOperations.patch.execute([{set: {publishedAt: new Date().toISOString()}}]) + defaultPublishAction?.onHandle?.() + }, + } + } +} +export function createNoopPatchPublishAction( + originalAction: DocumentActionComponent, +): DocumentActionComponent { + return function NoopPatchPublishAction(props) { + const defaultPublishAction = originalAction(props) + const documentOperations = useDocumentOperation(props.id, props.type) + + return { + ...defaultPublishAction, + label: 'Custom publish that sets someBoolean to true', + onHandle: () => { + documentOperations.patch.execute([{set: {someBoolean: true}}]) defaultPublishAction?.onHandle?.() }, } diff --git a/dev/test-studio/documentActions/index.ts b/dev/test-studio/documentActions/index.ts index 9e6ec576dfb..6227d6dda40 100644 --- a/dev/test-studio/documentActions/index.ts +++ b/dev/test-studio/documentActions/index.ts @@ -1,6 +1,9 @@ import {type DocumentActionsResolver} from 'sanity' -import {createCustomPublishAction} from './actions/createCustomPublishAction' +import { + createCustomPublishAction, + createNoopPatchPublishAction, +} from './actions/createCustomPublishAction' import {TestConfirmDialogAction} from './actions/TestConfirmDialogAction' import {TestCustomComponentAction} from './actions/TestCustomComponentAction' import {TestCustomRestoreAction} from './actions/TestCustomRestoreAction' @@ -15,12 +18,12 @@ export const resolveDocumentActions: DocumentActionsResolver = (prev, {schemaTyp TestPopoverDialogAction, TestCustomComponentAction, ...prev, - ].map((action) => { + ].flatMap((action) => { if (action.action === 'restore') { return TestCustomRestoreAction(action) } if (action.action === 'publish') { - return createCustomPublishAction(action) + return [createCustomPublishAction(action), createNoopPatchPublishAction(action)] } return action }) diff --git a/dev/test-studio/schema/debug/documentActions.js b/dev/test-studio/schema/debug/documentActions.js index eb5a3f80bd3..ae00b2a278f 100644 --- a/dev/test-studio/schema/debug/documentActions.js +++ b/dev/test-studio/schema/debug/documentActions.js @@ -9,5 +9,10 @@ export default { title: 'Title', }, {type: 'datetime', name: 'publishedAt', title: 'Published at'}, + { + name: 'someBoolean', + title: 'Some Boolean', + type: 'boolean', + }, ], }