index.tsx


Overview

index.tsx defines a React functional component named TimelineDataFlow that renders a customizable horizontal timeline UI component representing distinct stages in a data processing workflow. The timeline visually conveys progress through predefined steps such as "Begin," "Parser," "Chunker," "Indexer," and "Complete." Each step is represented by a node with a corresponding icon and title.

This file imports UI components and iconography, constructs timeline nodes from a static configuration object, manages active step highlighting, and handles user interaction by notifying parent components of step changes via callbacks.


Exported Members

1. TimelineNodeObj

An object representing the predefined timeline nodes used in the timeline. Each key corresponds to a step/stage in the workflow, holding properties such as node ID, title, icon, and clickability.

Properties

Property

Type

Description

begin

object

Node representing the "Begin" stage.

parser

object

Node representing the "Parser" stage.

chunker

object

Node representing the "Chunker" stage.

indexer

object

Node representing the "Indexer" stage.

complete

object

Node representing the "Complete" stage.

Node Object Structure

Example

{
  id: 1,
  title: 'Begin',
  icon: <PlayIcon size={13} />,
  clickable: false,
}

2. TimelineDataFlow (Default Export)

A React functional component that renders the timeline UI and manages active step selection.

Props (TimelineDataFlowProps)

Prop

Type

Description

activeId

`number \

string`

activeFunc

`(id: number \

string) => void`

Functionality

Usage Example

import TimelineDataFlow from './index';

function ParentComponent() {
  const [activeStepId, setActiveStepId] = React.useState(1);

  return (
    <TimelineDataFlow
      activeId={activeStepId}
      activeFunc={(id) => setActiveStepId(id)}
    />
  );
}

Implementation Details

  1. Node Construction with useMemo
    The timelineNodes array is memoized using React's useMemo hook to avoid unnecessary recalculations on re-renders. It iterates over the keys of the TimelineNodeObj object, copying each node's properties and augmenting with fixed CSS class and completed: false state.

  2. Active Step Calculation
    The active step index (activeStep) is computed by finding the position of the node whose id matches the activeId prop. It returns the index + 1 because the timeline component appears to expect 1-based indexing for active steps.

  3. Step Change Handling
    When a timeline node is clicked or selected, handleStepChange is called with the step index and node ID. This function calls the external activeFunc callback to notify the parent component about the change. It also logs the step and ID to the console for debugging.

  4. Styling and Customization of Timeline
    The CustomTimeline component is customized with props controlling:

    • orientation: Horizontal layout.

    • lineStyle: Solid line between nodes.

    • nodeSize: Normal nodes are 24px; active node size is increased to 30px.

    • activeStyle: Custom colors for icon and text on the active node, using CSS variables.


Interaction with Other Parts of the System


Visual Diagram

componentDiagram
    component TimelineDataFlow {
        +props: TimelineDataFlowProps
        +timelineNodes: TimelineNode[]
        +activeStep: number
        +handleStepChange(step: number, id: string | number): void
        +render()
    }
    component CustomTimeline {
        +nodes: TimelineNode[]
        +activeStep: number
        +onStepChange(step: number, id: string | number): void
        +orientation: string
        +lineStyle: string
        +nodeSize: number
        +activeStyle: object
        +render()
    }
    TimelineDataFlow --> CustomTimeline : renders
    TimelineDataFlow --> "TimelineNodeObj" : uses static nodes
    TimelineDataFlow ..> "lucide-react Icons" : uses icons
    TimelineDataFlow ..> "Parent Component" : activeFunc callback

Summary

This file is a central piece in representing and controlling workflow state visually within the application.