email-node.tsx
Overview
The email-node.tsx file defines a React functional component used within a visual flow editor (likely built on @xyflow/react) to represent and configure an "Email" node. This node is part of a flow or workflow system where nodes represent discrete units of functionality or processing steps.
The component visually displays SMTP email configuration details and allows toggling additional information on expected input JSON format. It provides connection handles on both sides for linking this node to others within a flow graph.
Key features:
Displays SMTP server, port, and sender email.
Toggleable detailed view showing a sample JSON input.
Integration with the flow editor via connection handles.
Highlights selection state visually.
Memoized for performance optimization.
Classes, Functions, and Methods
InnerEmailNode Component
function InnerEmailNode({
id,
data,
isConnectable = true,
selected,
}: NodeProps<IEmailNode>): JSX.Element
Description
The main React functional component rendering the email node UI. It receives props from the flow editor and renders node handles, a header, SMTP configuration, and an expandable details section.
Parameters
id(string): Unique identifier for this node instance.data(IEmailNode): Node-specific data structure containing the email configuration and labels.isConnectable(boolean, optional, defaulttrue): Indicates if the node handles are connectable to other nodes.selected(boolean): Indicates if the node is currently selected/highlighted in the UI.
Return Value
A React JSX element representing the styled email node with connection handles and expandable details.
Usage Example
<InnerEmailNode
id="email-node-1"
data={{
name: "Send Email",
label: "Email Node",
form: {
smtp_server: "smtp.example.com",
smtp_port: 587,
email: "[email protected]",
},
}}
isConnectable={true}
selected={false}
/>
Implementation Details
Uses React
useStatehook to manage local UI stateshowDetailsfor toggling the JSON example.Applies conditional CSS classes for selection highlighting using
classnames.Renders two
Handlecomponents from@xyflow/reactas connection points on left and right sides.Uses
NodeHeadercomponent to display node title and label.Displays SMTP configuration fields and a clickable area toggling visibility of expected JSON input format.
Uses Ant Design's
Flexcomponent for layout with vertical stacking and spacing.Styles are imported from a local LESS stylesheet and applied via CSS modules.
EmailNode
const EmailNode = memo(InnerEmailNode);
Description
A memoized version of InnerEmailNode to optimize rendering performance by preventing unnecessary re-renders when props have not changed.
Usage
Use EmailNode in place of InnerEmailNode when rendering within the flow editor to benefit from React memoization.
Important Implementation Details / Algorithms
Connection Handles: The node exposes two connection handles (
Handle) using@xyflow/react:Left side handle with id
"c", type"source".Right side handle with id
"b", also type"source".
These handles enable flow connections for data or control flow between email nodes and other node types.
Toggle Details: The component uses local state
showDetailsto toggle the display of a JSON example snippet. This is a simple UI state toggle with no side effects.Styling and CSS Modules: CSS classes are conditionally applied using the
classnameslibrary to reflect the node's selected state. Styles are locally scoped through CSS modules (stylesimported fromindex.less).Performance Optimization: The component is wrapped in React's
memoto avoid re-rendering unless props change, which is crucial in complex flow diagrams with many nodes.
Interaction with Other System Components
Flow Editor Integration: This component is designed to work within a node-based flow editor powered by
@xyflow/react. It uses theHandlecomponent from this library to integrate into the flow graph's connection system.Data Interface (
IEmailNode): The node relies on the interfaceIEmailNodefrom the application's database flow interfaces, ensuring consistent data shape for the email node configuration.NodeHeader Component: It uses a sibling component
NodeHeader(imported locally) to display the node's name and label in a consistent header UI across node types.Custom Handle Styles: The handles use custom styles (
LeftHandleStyle,RightHandleStyle) defined in a sibling modulehandle-icon, likely providing custom icons or colors for handles.Styling: The component styling is managed via CSS modules from the local
index.lessstylesheet, ensuring encapsulated and theme-able styles.
Visual Diagram
componentDiagram
component EmailNode {
InnerEmailNode
memoized
}
component InnerEmailNode {
+useState(showDetails)
+Render Section (container)
+Two Handles (Left "c", Right "b")
+NodeHeader(id, name, label)
+Flex container
+SMTP Config display (clickable)
+Expandable JSON example display
}
EmailNode --> InnerEmailNode
InnerEmailNode --> Handle : left, right handles
InnerEmailNode --> NodeHeader : render header
InnerEmailNode --> useState : toggle showDetails
Summary
email-node.tsx is a React component file that defines a configurable email node for a visual flow editor. It presents SMTP email settings and a toggleable example input JSON format. The component integrates tightly with the flow editor's connection system and uses memoization for performance. It works with other UI components and styling modules to provide a cohesive, interactive node experience within the flow system.