invoke-node.tsx
Overview
The invoke-node.tsx file defines a React functional component named InvokeNode that represents a specialized node within a graphical flow-based editor, likely built on top of the @xyflow/react library. This component visually models an "invoke" operation, displaying its name, label, and a URL associated with it.
Key functionalities include:
Rendering node handles on the left and right sides to allow connections with other nodes.
Displaying a header with node metadata.
Showing a URL extracted from the node's data.
Supporting theme-based styling (dark/light mode).
Highlighting the node when selected.
Internationalizing UI text using
react-i18next.
Overall, this component is a UI building block used in a node-based flow editor, providing an interactive and styled visualization of an "invoke" node with connection points and metadata display.
Detailed Explanation
Imports
useTheme(custom hook): Provides current UI theme info (dark or light).IInvokeNode(interface): Type definition for the node data structure.Handle,NodeProps, Position from@xyflow/react: Components and types for creating nodes and connection handles.Flexfromantd: Layout utility for vertical stacking.classNames: Utility for conditional CSS class names.getfromlodash: Safe object property accessor.useTranslationfromreact-i18next: Internationalization hook.LeftHandleStyle,RightHandleStyle: Inline style objects for connection handles.stylesfrom CSS module: Local scoped CSS.NodeHeader: Child component rendering node header information.
InvokeNode Component
export function InvokeNode({
id,
data,
isConnectable = true,
selected,
}: NodeProps<IInvokeNode>) { ... }
Description
InvokeNode is a React functional component designed to render a node of type IInvokeNode in a flow editor. It provides visual elements for node interaction and display, including connection handles, header, and node-specific data.
Parameters
id: string
Unique identifier of the node instance.data: IInvokeNode
The node's data payload, conforming to theIInvokeNodeinterface. Contains fields likename,label, and nestedform.url.isConnectable?: boolean(default:true)
Flag indicating whether the node’s handles can be connected to other nodes.selected?: boolean
Indicates if this node is currently selected in the UI, affecting styling.
Return Value
Returns JSX rendering a styled section element representing the node, including connection handles, a header, and URL display.
Usage Example
<InvokeNode
id="node-1"
data={{
name: "Invoke API",
label: "API Call",
form: { url: "https://api.example.com/endpoint" }
}}
isConnectable={true}
selected={false}
/>
Implementation Details
Theming: The component uses a custom hook
useThemeto get the current theme ('dark'or default). It applies CSS classes conditionally to adjust appearance.Internationalization: The
tfunction fromuseTranslation()is used to render the label for the URL field (t('flow.url')), supporting multiple languages.Connection Handles:
TwoHandlecomponents are placed on the left and right sides of the node:Left handle (
id="c") of type"source", positioned on the left.Right handle (
id="b") of type"source", positioned on the right.
Both handles use custom styles (
LeftHandleStyle,RightHandleStyle), and their connectability depends on theisConnectableprop.Node Header:
TheNodeHeadercomponent displays the node'snameandlabel. It receives theidand CSS class for styling.Data Extraction:
Uses lodash'sgetfunction to safely extract the URL from nesteddata.form.url.Layout:
Uses Ant Design'sFlexcomponent withverticalprop for stacking the URL label and its value vertically.
Interaction with Other System Parts
Flow Editor Core (
@xyflow/react):
The node integrates with the flow editor framework, leveragingHandlecomponents for visual connection points and conforming toNodePropstype.Theme Provider (
useTheme):
Adapts to the global theme context, enabling consistent theming across nodes and UI components.Internationalization Setup:
Relies onreact-i18nextfor localized strings, which implies centralized i18n configuration elsewhere in the app.NodeHeader Component:
Delegates part of its rendering toNodeHeader, which likely handles consistent header rendering across different node types.CSS Modules:
Uses scoped styles fromindex.lessto ensure styles do not leak or conflict with other components.
Visual Diagram
componentDiagram
component InvokeNode {
+id: string
+data: IInvokeNode
+isConnectable: boolean
+selected: boolean
+Render(): JSX.Element
}
component Handle_Left {
<<Handle>>
+id="c"
+type="source"
+position=Left
+isConnectable
+style=LeftHandleStyle
}
component Handle_Right {
<<Handle>>
+id="b"
+type="source"
+position=Right
+isConnectable
+style=RightHandleStyle
}
component NodeHeader {
+id: string
+name: string
+label: string
}
InvokeNode --> Handle_Left : renders
InvokeNode --> Handle_Right : renders
InvokeNode --> NodeHeader : includes
Summary
invoke-node.tsx provides a reusable, themed, and internationalized React component that visually represents an "invoke" node in a flow editor. It includes connection handles for building node graphs, a header for metadata, and a display of a URL property. The component is designed to integrate tightly with the flow framework, theme provider, and translation infrastructure.
This modular design promotes consistency and extensibility in the node-based UI, making it easier to manage and visualize invocation steps within complex workflows.