Overview
Screen steps are user interface components that allow human interaction within a workflow. They are implemented as React components that use theuseScreenFunctions
hook to interact with the workflow system.
Basic Concepts
Screen steps work by:- Pausing the workflow when the step is reached
- Rendering a React component to collect user input
- Collecting the user’s response through the React component
- Resuming the workflow with the collected data
Creating Your First Screen Step
Let’s start with a simple screen that greets a user and collects their confirmation:./src/screens/greeting-screen.tsx
Adding Screen Steps to Workflows
Once you’ve created a screen component, add it to your workflow definition:./src/workflow.py
get_props
function. In this example, the name
prop comes from the user_name
field returned by the "prepare-greeting"
step.
The useScreenFunctions Hook
Screen components interact with the workflow system using theuseScreenFunctions
hook, which provides two essential functions:
handleComplete({ result: data })
- Completes the screen step and passesdata
to the workflow. The workflow continues to the next step.handleCancel()
- Cancels the screen step and stops workflow execution.
Screen Step Data Flow
Understanding how data flows through screen steps is crucial:- Input Data: Screen components receive props from the previous workflow step’s output
- User Interaction: Users interact with the screen interface to provide input
- Completion Data: When
handleComplete()
is called, the data passed becomes the step’s output - Next Step Access: Subsequent steps can access this data using
ctx.get_step_result("step-id")
Advanced Example: Document Upload Screen
Here’s a more complex example that demonstrates form handling and file uploads:./src/screens/document-upload-screen.tsx
- Renders a form with document upload and text input fields
- Validates required fields before submission
- Structures the output data for easy access by subsequent workflow steps
- Provides a cancel option for users
Best Practices
Design Clear Interfaces
- Use descriptive labels and helpful descriptions for form fields
- Provide clear instructions about what input is expected
- Include visual feedback for loading states and form validation
Handle Errors Gracefully
- Validate user input before calling
handleComplete()
- Display clear error messages for invalid inputs
- Provide users with actionable guidance to resolve issues
Structure Output Data
- Use consistent naming conventions for output data
- Group related data into objects for easier access
- Include all necessary information for downstream workflow steps
Consider User Experience
- Keep forms focused and avoid overwhelming users with too many fields
- Provide progress indicators for multi-step processes
- Allow users to save drafts or return to previous steps when appropriate
Screen ordering
By default, Sample will try to navigate to the screen that’s most relevant to the user. In practice, this means navigating to the screen that’s the closest next step. To override this behavior, you can set apriority
option on a ScreenStep like so:
Events functionality requires workflows-py >= 0.1.22.