dynamic-parameters.tsx
Overview
dynamic-parameters.tsx is a React functional component designed to render and manage a dynamic table of parameters associated with a given flow node (RAGFlowNodeType). It provides an editable interface where users can add, modify, and remove key-value pairs, where keys are editable strings and values are selectable component IDs. The component leverages Ant Design UI components and custom hooks for state management and localization.
This file primarily enables dynamic configuration of parameters tied to flow nodes, facilitating user interaction within a broader application flow management system.
Component: DynamicParameters
Description
The DynamicParameters component displays a table of parameters related to a specific flow node. Each parameter consists of a key and a value, where:
Key: Editable text field.
Value: Select dropdown populated with component IDs relevant to the node context.
Operation: Delete icon to remove the parameter.
Users can add new parameters, edit existing ones, or remove them. Changes are handled via custom hooks to update the underlying data model.
Props
Prop Name | Type | Description |
|---|---|---|
|
| The flow node whose parameters are being edited. Optional. |
Usage Example
import DynamicParameters from './dynamic-parameters';
import { RAGFlowNodeType } from '@/interfaces/database/flow';
const nodeExample: RAGFlowNodeType = {
id: 'node-123',
parentId: 'parent-456',
// ...other node properties
};
<DynamicParameters node={nodeExample} />;
Internal Workflow and Logic
Initialization:
Extracts
nodeIdfrom the passednodeprop.Uses the
useTranslatehook to fetch localized strings for UI labels.Calls
useBuildComponentIdSelectOptionswithnodeIdandparentIdto generate dropdown options for the "value" field.Uses
useHandleOperateParametershook withnodeIdto manage parameter data and handlers:dataSource: Current list of parameters.handleAdd: Adds a new empty parameter row.handleRemove: Removes parameter by ID.handleSave: Saves edits to a parameter.handleComponentIdChange: Updates the selected component ID for a parameter.
Table Configuration:
Columns defined as:
Key: Editable cell using
EditableCellcomponent.Value: Select dropdown listing component IDs.
Operation: Delete action icon (
DeleteOutlined).
Rendering:
A button to add new parameters.
An Ant Design
Tablewith custom editable rows and cells.Proper styling and scroll handling.
Detailed Explanation of Key Elements
Imports and Dependencies
EditableRow and EditableCell: Custom components supporting inline editing of table rows and cells.
useTranslate: Hook for internationalization/localization.
RAGFlowNodeType: Interface defining shape of flow nodes.
Ant Design Components: Button, Flex (from
antdor a wrapper), Select, Table, and icons.Custom Hooks:
useBuildComponentIdSelectOptions: Builds select options based on node context.useHandleOperateParameters: Provides parameter data and CRUD operation handlers.
Interface: IProps
Defines the props passed to the component:
interface IProps {
node?: RAGFlowNodeType;
}
Optional node prop allows this component to be used flexibly.
Constants
components:
const components = {
body: {
row: EditableRow,
cell: EditableCell,
},
};
Overrides Ant Design Table body components to enable inline editing.
Functions inside DynamicParameters
handleAdd: Adds a new parameter row.handleRemove: Deletes a parameter by itsid.handleSave: Saves changes to the parameter key.handleComponentIdChange: Updates the selected component ID for a parameter.
These functions come from useHandleOperateParameters and manage state and side effects related to parameter operations.
Columns Definition
An array defining table columns with the following properties:
Column Title | Data Index | Key | Width | Additional Notes |
|---|---|---|---|---|
Key |
|
| 40% | Editable cell, saves via |
Value |
|
| 40% | Select dropdown, options from |
Operation |
|
| 20 | Delete icon triggers |
Important Implementation Details
Editable Table Rows and Cells: Uses custom components
EditableRowandEditableCellfor inline editing, enabling a smooth user experience.Dynamic Select Options: Select options for component IDs are dynamically built based on the current node and its parent, ensuring contextually relevant choices.
State Management via Hooks: All data operations (add, remove, save, change) are encapsulated inside the
useHandleOperateParametershook, isolating logic from UI.Localization: All UI labels (
key,value,operation,add) are localized using theuseTranslatehook scoped to 'flow'.Styling and Layout: Uses
Flexto align the "Add" button, and a CSS module (index.less) for table and row styling.
Interaction with Other System Parts
Flow Nodes (
RAGFlowNodeType): This component depends on receiving a flow node object and manages parameters related to it.Custom Hooks:
useBuildComponentIdSelectOptionslikely interacts with data stores or APIs to fetch components available for selection.useHandleOperateParametershandles CRUD operations, probably updating global or context state related to flow node parameters.
Editable Cells: The
EditableRowandEditableCellcomponents are shared UI primitives used elsewhere for inline editing.Localization System:
useTranslateconnects to the app's i18n system for multilingual support.Ant Design: Relies heavily on Ant Design components and icons for UI consistency.
Mermaid Diagram: Component Structure and Interaction
componentDiagram
component DynamicParameters {
+props: { node?: RAGFlowNodeType }
+render()
}
component EditableRow
component EditableCell
component Table
component Button
component Select
component useTranslate
component useBuildComponentIdSelectOptions
component useHandleOperateParameters
DynamicParameters --> EditableRow : uses for table row
DynamicParameters --> EditableCell : uses for table cell
DynamicParameters --> Table : renders parameter table
DynamicParameters --> Button : "Add" button
DynamicParameters --> Select : dropdown for component_id
DynamicParameters --> useTranslate : fetch localized strings
DynamicParameters --> useBuildComponentIdSelectOptions : get select options
DynamicParameters --> useHandleOperateParameters : manage parameter state
Summary
The dynamic-parameters.tsx file exports a fully interactive, editable table React component tailored for managing parameters associated with flow nodes. It integrates editable cells, dynamic select options, and localized UI text. State management and business logic are handled cleanly via custom hooks, promoting separation of concerns and maintainability.
This component is a key UI element within a flow management system, enabling users to configure parameters dynamically and intuitively.