Request For Comments on a new field type StateMachine:
StateMachine Field TypeThe StateMachine field type allows you specify a Finite State Machine to control the possible states and transitions between those states in a declarative syntax, ideal for setting up publishing workflows or user onboarding walkthroughs.
The StateMachine field type is powered by the xstate.js state chart library.
keystone.createList('Post', {
fields: {
name: { type: Text },
status: {
type: StateMachine,
defaultValue: 'draft',
states: {
draft: {
on: {
ready: [
{ target: 'ready', cond: 'isAdmin' },
{ target: 'ready', cond: 'isAuthor' },
],
},
},
ready: {
on: {
published: [{ target: 'published', cond: 'isAdmin' }],
rejected: [{ target: 'rejected', cond: 'isAdmin' }],
},
},
rejected: {
on: {
draft: [
{ target: 'draft', cond: 'isAdmin' },
{ target: 'draft', cond: 'isAuthor' },
],
},
},
published: {
on: {
draft: [{ target: 'draft', cond: 'isAdmin' }],
},
},
},
guards: {
isAdmin: ({ context }) => context.authedItem && context.authedItem.isAdmin,
isAuthor: ({ context, existingItem }) => context.authedItem && context.authedItem.id === existingItem.author,
},
},
},
});
The states and guards are passed straight to xstate.
See the equivalent xstate state machine here (try changing the values returned from isAdmin/isAuthor to see the different transitions which are enabled/disabled):

The AdminUI Field would display as a drop-down of the current state and any possible states which can be reached from there. Something like:

Whatchya think?
This will be really useful
It looks like there hasn't been any activity here in over 6 months. Sorry about that! We've flagged this issue for special attention. It wil be manually reviewed by maintainers, not automatically closed. If you have any additional information please leave us a comment. It really helps! Thank you for you contribution. :)
Like it :)
Is there any update?
Hey all, any updates on this? I think it sounds awesome and my project could really use this functionality as a replacement for the dependsOn feature that was in previous versions of Keystone.
Hi, everbody there is state machine library in javascript called xstate it might can be used for this use case
Most helpful comment
Is there any update?