sanity
Version:
Sanity is a real-time content infrastructure with a scalable, hosted backend featuring a Graph Oriented Query Language (GROQ), asset pipelines and fast edge caches
23 lines (19 loc) • 702 B
text/typescript
import {type DocumentActionComponent, type DocumentActionsContext} from '../../../../config'
import {ScheduleAction} from './ScheduleAction'
type Action = DocumentActionComponent
export default function resolveDocumentActions(
existingActions: Action[],
context: DocumentActionsContext,
): Action[] {
if (context.versionType === 'published') {
return existingActions
}
// Add schedule action after default publish action
const index = existingActions.findIndex((a) => a.action === 'publish')
if (index < 0) {
return [ScheduleAction, ...existingActions]
}
return existingActions.flatMap((action) =>
action.action === 'publish' ? [action, ScheduleAction] : action,
)
}