use-show-drawer.tsx


Overview

The use-show-drawer.tsx file provides a set of React hooks designed to manage the visibility and interactions of various drawers (modal panels) within a graph-based UI application. These drawers include:

This file orchestrates the display logic, user interactions (like node clicks), and modal state transitions in a cohesive manner, enabling a smooth user experience when interacting with graph nodes and their associated functionalities.


Detailed Explanation of Components

1. useShowFormDrawer

Purpose

Manages the state and behavior of the form drawer which shows details of a selected graph node.

Returns

{
  formDrawerVisible: boolean;       // Whether the form drawer is visible
  hideFormDrawer: () => void;       // Function to hide the form drawer
  showFormDrawer: (node: Node) => void; // Function to show the form drawer for a given node
  clickedNode: Node | undefined;    // The currently selected node
}

Usage

const { formDrawerVisible, showFormDrawer, hideFormDrawer, clickedNode } = useShowFormDrawer();

// Show drawer when a node is clicked
showFormDrawer(node);

// Hide drawer
hideFormDrawer();

Implementation Details


2. useShowSingleDebugDrawer

Purpose

Controls the visibility and logic for the single debug drawer, which is used to debug individual nodes.

Returns

{
  singleDebugDrawerVisible: boolean; // Whether the single debug drawer is visible
  showSingleDebugDrawer: () => Promise<void>; // Function to save the graph and then show debug drawer
  hideSingleDebugDrawer: () => void;          // Function to hide the debug drawer
}

Usage

const { singleDebugDrawerVisible, showSingleDebugDrawer, hideSingleDebugDrawer } = useShowSingleDebugDrawer();

// Show debug drawer after saving graph
await showSingleDebugDrawer();

Implementation Details


3. useShowDrawer

Purpose

The primary hook that integrates and manages multiple drawers' visibility and interactions within the graph UI. It handles:

Parameters

{
  drawerVisible: boolean; // Controls whether the overall drawer area is visible
  hideDrawer: () => void; // Function to hide the drawer area
}

Returns

{
  chatVisible: boolean;               // Visibility of chat drawer
  runVisible: boolean;                // Visibility of run drawer
  onPaneClick: () => void;            // Handler for clicking on the graph pane (background)
  singleDebugDrawerVisible: boolean; // Visibility of single debug drawer
  showSingleDebugDrawer: () => Promise<void>; // Show single debug drawer
  hideSingleDebugDrawer: () => void;          // Hide single debug drawer
  formDrawerVisible: boolean;         // Visibility of form drawer
  showFormDrawer: (node: Node) => void;       // Show form drawer for node
  clickedNode: Node | undefined;      // Currently clicked node
  onNodeClick: NodeMouseHandler;      // Handler for clicking on a node
  hideFormDrawer: () => void;          // Hide form drawer
  hideRunOrChatDrawer: () => void;     // Hide run and chat drawers and overall drawer
  showChatModal: () => void;            // Show chat drawer
}

Usage Example

const {
  chatVisible,
  runVisible,
  onPaneClick,
  singleDebugDrawerVisible,
  showSingleDebugDrawer,
  hideSingleDebugDrawer,
  formDrawerVisible,
  showFormDrawer,
  clickedNode,
  onNodeClick,
  hideFormDrawer,
  hideRunOrChatDrawer,
  showChatModal,
} = useShowDrawer({
  drawerVisible: isDrawerOpen,
  hideDrawer: () => setDrawerOpen(false),
});

Implementation Details


Important Implementation Details and Algorithms


Interaction with Other Parts of the System


Visual Diagram

componentDiagram
    component useShowDrawer {
        +chatVisible: boolean
        +runVisible: boolean
        +onPaneClick(): void
        +singleDebugDrawerVisible: boolean
        +showSingleDebugDrawer(): Promise<void>
        +hideSingleDebugDrawer(): void
        +formDrawerVisible: boolean
        +showFormDrawer(node: Node): void
        +clickedNode: Node | undefined
        +onNodeClick(e, node): void
        +hideFormDrawer(): void
        +hideRunOrChatDrawer(): void
        +showChatModal(): void
    }

    component useShowFormDrawer {
        +formDrawerVisible: boolean
        +hideFormDrawer(): void
        +showFormDrawer(node: Node): void
        +clickedNode: Node | undefined
    }

    component useShowSingleDebugDrawer {
        +singleDebugDrawerVisible: boolean
        +showSingleDebugDrawer(): Promise<void>
        +hideSingleDebugDrawer(): void
    }

    useShowDrawer --> useShowFormDrawer : uses
    useShowDrawer --> useShowSingleDebugDrawer : uses
    useShowDrawer --> useSetModalState : multiple instances
    useShowFormDrawer --> useGraphStore : gets/sets clickedNodeId
    useShowSingleDebugDrawer --> useSaveGraph : calls saveGraph()

Summary

The use-show-drawer.tsx file is a critical module for managing UI drawer components in a graph-based React application. It provides reusable hooks to:

By encapsulating drawer logic, state management, and interaction handlers, it enables a modular and maintainable way to control complex UI modal behaviors around graph nodes.