next-dynamic-input-variable.tsx


Overview

This file defines React components for dynamically managing input variables within a flow-based system, likely part of a complex UI workflow editor or builder. It provides a form interface to add, remove, and configure variables that can be either references to other components or direct user inputs.

The main functionalities include:

This file heavily utilizes the React Hook Form library for form state management and i18next for internationalization. It also integrates with custom UI components and hooks from the application ecosystem.


Detailed Explanation

Interfaces and Enums

IProps

interface IProps {
  node?: RAGFlowNodeType;
}

Enum: VariableType

enum VariableType {
  Reference = 'reference',
  Input = 'input',
}

Function: getVariableName

const getVariableName = (type: string) =>
  type === VariableType.Reference ? 'component_id' : 'value';

Component: DynamicVariableForm

export function DynamicVariableForm({ node }: IProps) { ... }

Purpose

Renders a dynamic form interface to manage a list of variables associated with a flow node. Each variable can be either a reference or an input. Users can add new variables or remove existing ones.

Implementation Details

Props

Return

Usage Example

<DynamicVariableForm node={someNodeObject} />

Component: DynamicInputVariable

export function DynamicInputVariable({ node }: IProps) { ... }

Purpose

Wraps the DynamicVariableForm inside a collapsible UI component for better UX, allowing users to expand or collapse the input variables section.

Implementation Details

Props

Return

Usage Example

<DynamicInputVariable node={someNodeObject} />

Important Implementation Details and Algorithms


Interaction With Other Parts of the System


Mermaid Component Diagram

componentDiagram
    component DynamicInputVariable {
        +props: IProps
        +renders Collapsible
        +contains DynamicVariableForm
    }
    component DynamicVariableForm {
        +props: IProps
        +uses useFormContext, useFieldArray
        +renders variable list UI
        +handles add/remove variable
        +renders variable type selector (RAGFlowSelect)
        +renders variable value input (Input or RAGFlowSelect)
    }
    component useBuildVariableOptions {
        +input: node.id, node.parentId
        +output: options for reference variables
    }
    DynamicInputVariable --> DynamicVariableForm
    DynamicVariableForm --> useBuildVariableOptions

Summary

This file provides a sophisticated UI for managing dynamic input variables within a flow node context. It leverages modern React form management, custom UI components, and contextual hooks to provide a flexible, localized, and user-friendly interface for variable configuration. The main components are DynamicVariableForm (the core form) and DynamicInputVariable (a collapsible wrapper). The file is part of a larger system managing flow nodes and their data dependencies.