next-variable.tsx
Overview
next-variable.tsx is a React component file designed for managing dynamic input and output variables within a form context, specifically in the context of a RAG (Retrieval-Augmented Generation) flow or similar workflow system. This file provides UI components that allow users to add, remove, and edit variables dynamically, specifying their names and types. It leverages React Hook Form for form state management and i18next for translations.
The components in this file enable seamless integration of variable definitions into larger workflows, supporting both input and output variable configurations with appropriate UI controls and validation messages.
Components and Exports
TypeOptions
Type:
Array<{ label: string; value: string }>Description:
A predefined list of variable types used in the type selection dropdown. It includes common data types and array variants:String
Number
Boolean
Array
Array
Object
Usage Example:
Used as the options prop in a select component to allow users to choose a variable type.
DynamicVariableForm
Type: React Functional Component
Props:
interface IProps { node?: RAGFlowNodeType; // Optional node object from the flow, not directly used here but likely for future extensions name?: string; // Form field name prefix for the variables array, defaults to 'arguments' isOutputs: boolean; // Flag indicating whether the variables represent outputs (true) or inputs (false) }Purpose:
Renders a dynamic list of variable input fields, where each variable has a name and a type. Users can add new variables or remove existing ones.Key Functionalities:
Uses React Hook Form's
useFieldArrayto handle an array of variable fields.Renders an input field for the variable name.
Renders a type selector:
If
isOutputsistrue, the type selector uses a fixed set ofTypeOptions.If
isOutputsisfalse, the type selector offers a dynamic list of options fetched viauseBuildQueryVariableOptions().
Provides a button to remove a variable.
Provides a "Add Variable" button to append a new variable with default empty values.
Parameters:
name: string (default: 'arguments') — the form field name path for the array of variables.isOutputs: boolean — controls which type selector UI and options are shown.node: optional, currently unused internally.
Returns: JSX element rendering the dynamic variable form UI.
Usage Example:
<DynamicVariableForm name="inputs" isOutputs={false} />
VariableTitle
Type: React Functional Component
Props:
{ title: ReactNode }Purpose:
A simple presentational component to render a styled title above variable form sections.Returns: JSX element rendering the title in a stylized div.
Usage Example:
<VariableTitle title="Input Variables" />
DynamicInputVariable
Type: React Functional Component
Props:
IProps & { title: ReactNode }node?: RAGFlowNodeType— optional, passed down for potential future use.name?: string— form field name prefix.isOutputs?: boolean— defaults tofalse.title: ReactNode— title to display above the form.
Purpose:
CombinesVariableTitleandDynamicVariableFormwrapped inside aFormContainer. This creates a cohesive section for either input or output variables with a title.Returns: JSX section element containing the titled variable form.
Usage Example:
<DynamicInputVariable title="Output Variables" name="outputs" isOutputs={true} />
Implementation Details
Form Management:
Usesreact-hook-formto manage form state and validation. TheuseFieldArrayhook is critical here, enabling dynamic addition and removal of variable fields without losing form state.Internationalization:
All user-facing text placeholders and button labels are internationalized viauseTranslationfromreact-i18next.Custom UI Components:
Utilizes a suite of in-house UI components:FormContainer,FormControl,FormField,FormItem,FormMessage: Wrappers for form layout and validation.BlurInput: Input field with onBlur event handling.RAGFlowSelect: Custom select component for fixed type options.SelectWithSearch: Select component with search functionality for dynamic options.BlockButtonandButton: Styled buttons.Separator: Visual separator component.
Dynamic Type Options for Inputs:
For input variables (isOutputs === false), the type options come from a hookuseBuildQueryVariableOptions(), implying these options are context-sensitive or fetched dynamically, enhancing flexibility.Removal Functionality:
Each variable row has a ghost-style button with an "X" icon allowing the user to remove that variable from the list.
Interaction with Other Parts of the System
Form Context:
The components expect to be used inside areact-hook-formcontext (useFormContext). They rely on the form provider higher up in the component tree.Hooks:
useBuildQueryVariableOptionsis imported from a relative path and provides dynamic options for input variable types, likely fetching or computing these based on the current application state or backend data.
UI Components:
The file imports and composes many UI components from the local component library (@/components/uiand others), ensuring consistent styling and behavior across the app.RAGFlowNodeType:
Thenodeprop is typed withRAGFlowNodeTypeimported from the database flow interfaces, indicating this file is part of a larger workflow or flow-building module.
Visual Diagram
componentDiagram
component DynamicInputVariable {
+node?: RAGFlowNodeType
+name?: string
+isOutputs?: boolean
+title: ReactNode
---
Renders:
- VariableTitle
- FormContainer
- DynamicVariableForm
}
component DynamicVariableForm {
+node?: RAGFlowNodeType
+name?: string
+isOutputs: boolean
---
Uses:
- react-hook-form useFieldArray
- BlurInput (variable name input)
- RAGFlowSelect or SelectWithSearch (variable type select)
- BlockButton (add variable)
- Button (remove variable)
- useBuildQueryVariableOptions (for input variable types)
}
component VariableTitle {
+title: ReactNode
---
Renders a styled title text
}
DynamicInputVariable --> VariableTitle
DynamicInputVariable --> FormContainer
DynamicInputVariable --> DynamicVariableForm
Summary
next-variable.tsx is a specialized React component file that facilitates dynamic creation and management of variables within a form, supporting both input and output use cases in a RAG or workflow system. It integrates advanced form state management, internationalization, and custom UI components to deliver a user-friendly variable editing experience. Its modular design allows it to be embedded within larger forms and workflows seamlessly.
Additional Notes
The
nodeprop is currently not utilized inside the components but is available for future extensions or contextual logic.The file assumes a global form context (from
react-hook-form) is already established.The dynamic nature of input variable type options via
useBuildQueryVariableOptionssuggests the system is designed to adapt variable types based on upstream conditions or data models.