index.tsx


Overview

index.tsx defines a React functional component ButtonEdge that renders a customized edge (connection) between two nodes in a graph visualization. It leverages the @xyflow/react library for rendering graph edges and integrates with the application's global graph state for edge deletion functionality. The component also visually highlights edges that lie on a specific workflow path fetched via a custom hook. The edge includes an interactive button allowing users to delete the edge on click.

This file primarily focuses on enhancing the UI/UX of graph edges by providing:


Component: ButtonEdge

Purpose

Renders an interactive edge between two nodes with visual cues for selection and workflow path highlighting, including a button to delete the edge.

Props

The component accepts all props defined by EdgeProps from @xyflow/react, which include (but are not limited to):

Prop Name

Type

Description

id

string

Unique identifier for the edge.

sourceX

number

X-coordinate of the source node connection point.

sourceY

number

Y-coordinate of the source node connection point.

targetX

number

X-coordinate of the target node connection point.

targetY

number

Y-coordinate of the target node connection point.

sourcePosition

string (enum)

Position of the source connection relative to the source node (e.g., top, bottom).

targetPosition

string (enum)

Position of the target connection relative to the target node.

source

string

ID of the source node.

target

string

ID of the target node.

style

React.CSSProperties (optional)

Custom CSS styles applied to the edge. Defaults to empty object.

markerEnd

string (optional)

SVG marker (arrowhead) applied at the end of the edge path.

selected

boolean (optional)

Whether the edge is currently selected. Defaults to false.

Returns

A JSX fragment rendering:

Usage Example

import { ButtonEdge } from './index';

// Within a ReactFlow or XYFlow graph render context:
<ButtonEdge
  id="edge-1"
  sourceX={100}
  sourceY={100}
  targetX={200}
  targetY={200}
  sourcePosition="right"
  targetPosition="left"
  source="node-1"
  target="node-2"
  selected={true}
  markerEnd="url(#arrowhead)"
/>

Detailed Explanation

Internal Hooks and State Usage

Core Logic

  1. Bezier Path Calculation

    Using getBezierPath from @xyflow/react, the component calculates the SVG path string for a smooth curved edge between the source and target coordinates, respecting their connection positions.

  2. Edge Styling

    • Selected Edge: If the edge is selected (selected === true), it is styled with a blue stroke of width 2.

    • Highlighting Workflow Path:

      • The component inspects the workflow path from the fetched flow detail.

      • It determines if this edge (from source to target) lies on the current or previous workflow path.

      • If so, it highlights the edge with a red stroke of width 2.

  3. Delete Button

    • Positioned at the midpoint of the edge path using coordinates labelX and labelY.

    • Styled differently based on the theme.

    • Clicking the button triggers deleteEdgeById(id) to remove the edge from the graph.

Styling


Important Implementation Details


Interaction with Other System Parts

This component is likely used inside a graph rendering context (e.g., a ReactFlow or XYFlow canvas) where edges are rendered dynamically between nodes.


Visual Diagram

componentDiagram
    component ButtonEdge {
      +EdgeProps props
      +deleteEdgeById(id)
      +getBezierPath()
      +useTheme()
      +useFetchFlow()
      +useMemo()
      +onEdgeClick()
      +render()
    }

    component BaseEdge {
      +path: string
      +markerEnd: string
      +style: CSSProperties
    }

    component EdgeLabelRenderer {
      +children: ReactNode
    }

    ButtonEdge --> BaseEdge : renders edge path
    ButtonEdge --> EdgeLabelRenderer : renders delete button
    ButtonEdge --> useGraphStore : calls deleteEdgeById()
    ButtonEdge --> useTheme : gets theme
    ButtonEdge --> useFetchFlow : fetches flow data
    ButtonEdge --> getBezierPath : computes edge SVG path

Summary

The index.tsx file provides a specialized React component ButtonEdge that:

This component enhances the interactivity and visual clarity of graph edges within the broader graph visualization system.