All files / apps/chatbot/src/components/MessageList/blocks index.tsx

100% Statements 9/9
100% Branches 7/7
100% Functions 1/1
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58                                                2x               16x   1x   2x   1x   9x                   1x   1x   1x      
import React from "react";
 
import { Block } from "@/types/chat";
 
import { ConfirmationBlock } from "./ConfirmationBlock";
import { ErrorBlock } from "./ErrorBlock";
import { StatusBlock } from "./StatusBlock";
import { TableBlock } from "./TableBlock";
import { TextBlock } from "./TextBlock";
 
export interface ChatBlockProps {
  block: Block;
  msgId: string;
  pendingAction: any;
  isActionProcessing?: boolean;
  onReset: () => void;
  handleAction: (msgId: string, actionId: string, type: "confirm" | "cancel") => void;
}
 
/**
 * Renders one block of an agent turn. Suggestion blocks are deliberately not
 * rendered here — the composer owns them, so they stay pinned above the input
 * instead of scrolling away with the message.
 */
export const ChatBlock = ({
  block,
  msgId,
  pendingAction,
  isActionProcessing,
  onReset,
  handleAction,
}: ChatBlockProps) => {
  switch (block.type) {
    case "text":
      return <TextBlock block={block} />;
    case "suggestions":
      return null;
    case "table":
      return <TableBlock block={block} />;
    case "confirmation":
      return (
        <ConfirmationBlock
          block={block}
          msgId={msgId}
          pendingAction={pendingAction}
          isActionProcessing={isActionProcessing}
          handleAction={handleAction}
        />
      );
    case "status":
      return <StatusBlock block={block} />;
    case "error":
      return <ErrorBlock block={block} onReset={onReset} />;
    default:
      return null;
  }
};