dynamic-input-variable.tsx


Overview

dynamic-input-variable.tsx is a React functional component module designed to enable dynamic, user-configurable input variables within a form context. It is used primarily in a flow-based UI system where nodes may have variable inputs that are either references to other components or free-text inputs. This file provides an interactive UI for adding, editing, and removing such variables dynamically, integrating with Ant Design's form system and UI components.

The main functionality includes:


Detailed Explanation

Interfaces & Types

IProps

interface IProps {
  node?: RAGFlowNodeType;
}

VariableType (enum)

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

Utility Function

getVariableName

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

Components

DynamicVariableForm

const DynamicVariableForm = ({ node }: IProps) => { ... }

FormCollapse

export function FormCollapse({
  children,
  title,
}: PropsWithChildren<{ title: string }>) { ... }

DynamicInputVariable

const DynamicInputVariable = ({ node }: IProps) => { ... }

Important Implementation Details


Interaction with Other Parts of the System


Visual Diagram

classDiagram
    class DynamicInputVariable {
        +node?: RAGFlowNodeType
        +render()
    }
    class FormCollapse {
        +title: string
        +children: ReactNode
        +render()
    }
    class DynamicVariableForm {
        +node?: RAGFlowNodeType
        +render()
        -handleTypeChange(name: number): void
        -getVariableName(type: string): string
    }

    DynamicInputVariable --> FormCollapse : uses
    FormCollapse --> DynamicVariableForm : wraps

Summary

dynamic-input-variable.tsx is a well-structured React component file that provides a dynamic form UI to handle input variables of two types: references to other components and plain text inputs. It leverages Ant Design for UI and form management and hooks into the application's flow system via the node prop and a custom hook for options. The file is internationalization-ready and styled using CSS modules. It serves as a reusable UI piece for managing dynamic input variables in flow nodes.


Example Usage in Application

import { Form } from 'antd';
import DynamicInputVariable from './dynamic-input-variable';

// Inside some parent component rendering a flow node form
const FlowNodeEditor = ({ node }) => {
  const [form] = Form.useForm();

  return (
    <Form form={form} initialValues={{ query: [] }}>
      {/* Other form items */}
      <DynamicInputVariable node={node} />
      {/* Submit button etc. */}
    </Form>
  );
};

This snippet shows how the component fits into a larger form for editing flow nodes, enabling users to dynamically add and configure input variables tied to that node.