next-variable.tsx
Overview
The next-variable.tsx file provides React components to manage dynamic variables in a form interface, particularly in the context of defining inputs or outputs for a node within a RAG (Retrieval-Augmented Generation) flow system. It leverages React Hook Form for form state management, integrates internationalization support via react-i18next, and uses custom UI components for a consistent user experience.
This file is primarily concerned with rendering a dynamic list of variable entries, each consisting of a name and a type, allowing users to add, edit, or remove variables interactively. It differentiates between input and output variables, adjusting the type selection UI accordingly.
Exports and Components
1. TypeOptions: Array<{label: string; value: string}>
Description:
A predefined list of variable type options available for output variables.Values:
String
Number
Boolean
Array
Array
Object
Usage Example:
<RAGFlowSelect options={TypeOptions} />
2. DynamicVariableForm
function DynamicVariableForm({
name = 'arguments',
isOutputs,
node,
}: IProps): JSX.Element
Description:
A form component that renders a dynamic list of variables, each with a name and type field. Supports adding new variables and removing existing ones.Props:
node?: RAGFlowNodeType– Optional node data (not directly used in the current implementation but reserved for future enhancements or context).name?: string– The base name/path in the form state where variables are stored (default:'arguments').isOutputs: boolean– Flag indicating whether the variables are outputs or inputs, affecting the type selection options.
Functionality:
Uses
useFormContextanduseFieldArrayfrom React Hook Form to manage form fields dynamically.Renders each variable with two inputs:
Name: Text input with placeholder "Please input".
Type: Select input that changes based on
isOutputs:If
true: uses a fixed set of type options (TypeOptions) withRAGFlowSelect.If
false: uses options fetched viauseBuildQueryVariableOptionshook withSelectWithSearch.
Provides a button to remove individual variables.
Provides a button to append new empty variables with default values.
Return:
JSX element rendering the dynamic variable form UI.Usage Example:
<DynamicVariableForm name="inputs" isOutputs={false} />
3. VariableTitle
function VariableTitle({ title }: { title: ReactNode }): JSX.Element
Description:
A simple presentational component that renders a title for variable sections.Props:
title: ReactNode– The title content to display above the variable form.
Return:
JSX element wrapping the title in styled div.Usage Example:
<VariableTitle title="Input Variables" />
4. DynamicInputVariable
function DynamicInputVariable({
node,
name,
title,
isOutputs = false,
}: IProps & { title: ReactNode }): JSX.Element
Description:
Composite component that combines a title and theDynamicVariableForminside aFormContainer. This is a higher-level component intended for rendering a titled section of dynamic variables.Props:
node?: RAGFlowNodeType– Optional node data.name?: string– Form path for variables.title: ReactNode– Section title.isOutputs?: boolean– Whether the variables are outputs (defaultfalse).
Return:
JSX element containing a titled section with the dynamic variable form.Usage Example:
<DynamicInputVariable title="Output Variables" name="outputs" isOutputs={true} />
Important Implementation Details
Dynamic Form Management:
UsesuseFieldArrayfrom React Hook Form to dynamically add/remove variable entries, managing form state in a scalable way.Conditional Rendering:
The type selector changes based on theisOutputsflag:Outputs use a static list of types (
TypeOptions).Inputs use options fetched via
useBuildQueryVariableOptions, which likely queries available variables or types dynamically from the system.
Localization:
Text placeholders and button labels use thetfunction fromreact-i18nextfor internationalization support.Custom UI Components:
The file uses several custom UI components (BlurInput,RAGFlowSelect,SelectWithSearch,Button,BlockButton,Separator,FormField,FormControl,FormItem,FormMessage) to maintain consistent styling and behavior across the application.
Interaction with Other Parts of the System
Hooks:
useBuildQueryVariableOptions: Fetches variable type options dynamically for input variables.useFormContextanduseFieldArray: Integrate with the higher-level form context and state management.
Interfaces:
RAGFlowNodeTypeimported from@/interfaces/database/flowrepresents node data in the RAG flow system, allowing this form to be context-aware.
UI Components:
Imported from project-specific UI libraries (
@/components/ui/and@/components/originui/), these components provide input fields, selects, buttons, and layout containers.
Icons:
Xfromlucide-reactis used as a delete icon.
Visual Diagram
classDiagram
class DynamicVariableForm {
+name: string
+isOutputs: boolean
+node?: RAGFlowNodeType
+render()
}
class VariableTitle {
+title: ReactNode
+render()
}
class DynamicInputVariable {
+node?: RAGFlowNodeType
+name?: string
+title: ReactNode
+isOutputs: boolean
+render()
}
DynamicInputVariable "1" --> "1" VariableTitle : uses
DynamicInputVariable "1" --> "1" DynamicVariableForm : uses
Summary
The next-variable.tsx file is a UI-centric React module that facilitates the dynamic management of variables (inputs or outputs) within a form. It integrates tightly with React Hook Form for dynamic field arrays, provides flexible type selection based on context, and supports internationalization. It is designed to be reusable and composable, fitting into a larger RAG flow system where nodes have variable inputs and outputs.
This module depends on other UI and hook components in the system and is intended to be embedded within a larger form or workflow editor interface.