Variable Set Settings
This node allows users to define or modify variables within different scopes: the temporary flowContext (for the current execution) or persistently in the selectedEnvironment.
This node is fundamental for managing state, passing data between non-adjacent nodes, or storing configuration values that can be used throughout the flow or across multiple flow runs if saved to an environment.
Features
- Node Label Configuration: Allows users to set a custom label for the Set Variable node.
- / Variable Target Selection: Users can choose where to save the variable:
- Flow Context (Temporary): Variable exists only for the duration of the current flow execution. Represented with a icon.
- Selected Environment (Persistent): Variable is saved in the currently active environment and persists across flow runs. Represented with a icon.
- Variable Name Input: Field to specify the name of the variable.
- Variable Value Input: A textarea to set the value of the variable. This can be a static value or include references (e.g.,
{{env.API_KEY}},{{context.anotherVar}}) that will be resolved before setting. - Mark as Secret: If the target is
selectedEnvironment, an option (checkbox) appears to store the variable value as a secret (encrypted). - Theming: Adapts its appearance based on the current theme (dark/light).
- Helper Texts: Provides contextual help for variable naming and target implications (e.g., "Access using
{{context.variableName}}.").
Component Structure
The component relies on the following key parts:
VariableSetNodeDataInterface: Defines thedataobject for the node:label?: stringvariableName?: stringvariableValue?: stringtarget?: 'flowContext' | 'selectedEnvironment'markAsSecret?: boolean
-
State and Hooks:
useFlowStore: To getupdateNodeData.useTheme: For theme-based styling.useStateforlabel,variableName,variableValue,target, andmarkAsSecret.useEffect: To synchronize local state withnode.datawhen it changes or on mount.
Configuration Sections
The panel is organized into the following sections for user interaction:
- Node Label: Text input for the node label. Saves on blur.
- Save Variable To (Target): A
Selectcomponent to choose between "Flow Context" and "Selected Environment". - Changing the target to
flowContextautomatically unchecks and disablesmarkAsSecret. - Variable Name: Text input for the variable's name. Saves on blur.
- Value to Set: A
Textareafor the variable's value. Saves on blur. - Mark as Secret: A
Checkboxthat is only visible iftargetisselectedEnvironment. Allows marking the environment variable as encrypted.
Styling
- Uses
cnutility for conditional class names. - Inputs, Textarea, Select, and Checkbox components are styled for dark/light themes using
cartoonBorder,cartoonSection,cartoonLabel,cartoonHelpwhich apply theme-specific background, border, and text colors. shadow-cartoonis used for a consistent shadow style.- Select items use icons ( ) for visual distinction.
Key Functionalities and Logic
- State Synchronization:
useEffectkeeps the panel's local state in sync with thenode.datafrom the store. - Data Persistence: Input field changes are typically saved on
onBlurevents by callingupdateNodeDataif the value has actually changed. handleLabelBlur,handleNameBlur,handleValueBlur.- Target Change Logic (
handleTargetChange): When the target is changed: - Updates the
targetin the node data. - If the new target is
flowContext, it automatically setsmarkAsSecrettofalseand updates this in the node data, as secrets are only applicable to environment variables. - Mark as Secret Logic (
handleMarkAsSecretChange): Updates themarkAsSecretboolean in the node data. - Input Interaction:
onMouseDown=e => e.stopPropagation()on inputs/textarea prevents node dragging.
Props
| Prop Name | Type | Description |
|---|---|---|
| node | Node<VariableSetNodeData> | The React Flow node object (required). |
Variable Usage
- Flow Context Variables: Useful for temporary data storage within a single execution. Accessed like
{{context.yourVariableName}}in other nodes. - Environment Variables: Ideal for storing API keys, configuration settings, or any data that needs to persist and be available across different flows or flow runs within that environment. Accessed like
{{env.yourVariableName}}.
Security for Secrets
When markAsSecret is checked for an environment variable, the value should be encrypted at rest by the backend. The UI itself only flags it; actual encryption is a backend responsibility.
This panel provides a comprehensive interface for managing variables, which are essential for creating dynamic and configurable data flows.