frontend_nyla/src/components/Dashboard/DashboardChat
2025-08-06 15:39:16 +02:00
..
DashboardChatAreaStyles working on new frontend and backend integration 2025-08-06 15:39:16 +02:00
DashboardChat.tsx working on new frontend and backend integration 2025-08-06 15:39:16 +02:00
DashboardChatArea.tsx working on new frontend and backend integration 2025-08-06 15:39:16 +02:00
DashboardChatAreaConnectedFiles.tsx working on new frontend and backend integration 2025-08-06 15:39:16 +02:00
DashboardChatAreaFilePreview.tsx working on new frontend and backend integration 2025-08-06 15:39:16 +02:00
DashboardChatAreaInput.tsx working on new frontend and backend integration 2025-08-06 15:39:16 +02:00
DashboardChatAreaMessageItem.tsx working on new frontend and backend integration 2025-08-06 15:39:16 +02:00
DashboardChatAreaMessageList.tsx working on new frontend and backend integration 2025-08-06 15:39:16 +02:00
dashboardChatAreaTypes.ts working on new frontend and backend integration 2025-08-06 15:39:16 +02:00
FileAttachmentPopup.tsx working on new frontend and backend integration 2025-08-06 15:39:16 +02:00
index.ts working on new frontend and backend integration 2025-08-06 15:39:16 +02:00
README.md working on new frontend and backend integration 2025-08-06 15:39:16 +02:00

DashboardChatArea - Modular Structure

This directory contains the refactored DashboardChatArea component, broken down into manageable modules for better maintainability and separation of concerns.

File Structure

DashboardChatArea/
├── index.ts                    # Main export file
├── types.ts                    # TypeScript interfaces and types
├── DashboardChatArea.tsx       # Main orchestrating component
├── useChatLogic.ts            # Custom hook with all business logic
├── MessageList.tsx            # Component for displaying messages
├── MessageItem.tsx            # Individual message component
├── ChatInput.tsx              # Input field and send button component
├── WorkflowStatusDisplay.tsx  # Workflow status and completion UI
├── DashboardChatArea.module.css # Shared styles
└── README.md                  # This documentation

Component Responsibilities

DashboardChatArea.tsx (Main Component)

  • Purpose: Orchestrates all child components
  • Responsibilities:
    • Uses the useChatLogic hook
    • Renders MessageList and ChatInput components
    • Passes props between components
  • Size: ~73 lines (reduced from 278 lines)

useChatLogic.ts (Custom Hook)

  • Purpose: Contains all business logic and state management
  • Responsibilities:
    • State management (input value, workflow ID, completion status)
    • Effects for polling, auto-scroll, prompt handling
    • Workflow operations (send messages, start workflows)
    • Event handlers
  • Size: ~196 lines

MessageList.tsx (Message Display)

  • Purpose: Handles the display of all messages and status indicators
  • Responsibilities:
    • Renders loading and error states
    • Maps through messages using MessageItem
    • Includes WorkflowStatusDisplay
    • Handles auto-scroll reference
  • Size: ~73 lines

MessageItem.tsx (Individual Message)

  • Purpose: Renders a single message
  • Responsibilities:
    • Message content display
    • Role-based styling
    • Timestamp formatting
  • Size: ~32 lines

ChatInput.tsx (Input Interface)

  • Purpose: Handles user input and send functionality
  • Responsibilities:
    • Input field with ref handling
    • Send button with animations
    • Keyboard event handling
    • Disabled states
  • Size: ~46 lines

WorkflowStatusDisplay.tsx (Status UI)

  • Purpose: Shows workflow status and completion states
  • Responsibilities:
    • Running workflow status
    • Completion message
    • "Start New Workflow" button
  • Size: ~38 lines

types.ts (Type Definitions)

  • Purpose: Centralized TypeScript interfaces
  • Responsibilities:
    • Component prop interfaces
    • Data structure types
    • Shared type definitions
  • Size: ~50 lines

Benefits of This Structure

  1. Separation of Concerns: Each file has a single, clear responsibility
  2. Reusability: Components can be easily reused or tested independently
  3. Maintainability: Easier to locate and modify specific functionality
  4. Readability: Smaller files are easier to understand and navigate
  5. Testing: Individual components can be unit tested in isolation
  6. Type Safety: Centralized types ensure consistency across components

Usage

Import the main component as before:

import DashboardChatArea from './DashboardChatArea';
// or
import DashboardChatArea, { DashboardChatAreaProps } from './DashboardChatArea';

The API remains exactly the same - this refactoring is purely internal and doesn't affect how the component is used by parent components.

Development Guidelines

  • Adding new features: Consider which component/file is most appropriate
  • State changes: Most state logic should go in useChatLogic.ts
  • UI changes: Modify the relevant component file
  • New types: Add to types.ts
  • Styling: All styles remain in DashboardChatArea.module.css