Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workflows with XState #1019

Merged
merged 99 commits into from
Oct 29, 2024
Merged

Workflows with XState #1019

merged 99 commits into from
Oct 29, 2024

Conversation

FyreByrd
Copy link

Uses the XState library to create FSM instances that model the desired workflow behavior.

Features:

  • Persistence: Each instance has an associated DB record (in WorkflowInstances) that stores enough information to restore to the current state.
  • User Tasks: Each instance updates the UserTasks table with the appropriate information.
  • Product Transitions: Each instance updates the ProductTransitions table with the appropriate information.
  • Tasks: The appropriate actions are provided based on the user in the /tasks/[product_id] and are handled by the FSM.
  • Admin: A barebones table of instances is provided in /admin/workflows.
    • Clicking on an entry will take a user to a visualization in /admin/workflows/[product_id]
    • While in the visualization, a user can select a state node and then press a button in a menu to jump the machine state to the selected state

Future Priorities:

  • Hook actions into backend
  • Authentication
  • Republish and Rebuild workflows
  • Workflow instance filtering/sorting in /admin/workflows
  • Improve visualization (and visualization efficiency)

@FyreByrd FyreByrd marked this pull request as ready for review September 24, 2024 21:05
Copy link

@7dev7urandom 7dev7urandom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good; well done.

Here's a first-look review. I haven't reviewed the default-workflow.ts stuff at all, and I haven't tested anything, but here's some comments I have looking through it rather quickly. Some questions are probably somewhat ignorant because I'm not entirely clear what your goal is, but I think they'll be helpful.

One larger thing: you're handling the state machines with a lot of functional programming. You have a lot of functions that take WorkflowMachine or WorkflowContext as (often the first) argument, which makes me wonder if it could be done in a more object-oriented way, making things more intuitive to write.

@FyreByrd FyreByrd marked this pull request as draft September 25, 2024 20:44
@FyreByrd
Copy link
Author

I have created a wrapper class for DefaultWorkflow and have updated all the rest of the code in accordance with that change.
I have also fixed a few small things that I noticed while working on that change (they are related to workflow, so still valid for the PR).

@FyreByrd FyreByrd marked this pull request as ready for review September 27, 2024 17:47
Copy link

@7dev7urandom 7dev7urandom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, it does look a lot better and easier to use. Let me know what you think of my feedback.

@FyreByrd FyreByrd force-pushed the feature/svelte-workflows branch 2 times, most recently from 9047c04 to 3dd3423 Compare September 30, 2024 17:27
Copy link

@7dev7urandom 7dev7urandom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, let's try it out!

@FyreByrd FyreByrd force-pushed the feature/svelte-workflows branch from e3094e9 to 6f1e44c Compare October 4, 2024 13:24
@FyreByrd FyreByrd force-pushed the feature/svelte-workflows branch from 673a738 to 5458627 Compare October 16, 2024 16:21
Copy link
Author

@FyreByrd FyreByrd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switch to using svelte-kit superforms in a few pages

Why? The productId passed into the factory method should be the productId to use, regardless of what may be stored in the snapshot. Technically, the productId doesn't need to be stored in the snapshot; it's only in there because it's part of the state machine context. It also isn't used from the context either, but it will be in the future because it is necessary for the build engine hooks that will be added in a future PR.
Even better, just don't write the productId (or the other dynamically calculated fields) in the first place
There is no i18n yet for actions or individual instructions.
@FyreByrd FyreByrd force-pushed the feature/svelte-workflows branch from 7441cc0 to 5bc28bf Compare October 28, 2024 15:46
Copy link
Member

@chrisvire chrisvire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@FyreByrd FyreByrd merged commit 4b5884b into feature/svelte Oct 29, 2024
2 checks passed
@FyreByrd FyreByrd deleted the feature/svelte-workflows branch October 29, 2024 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants