agent-card.tsx


Overview

The agent-card.tsx file defines a React functional component named AgentCard that renders a card UI element representing an agent or flow entity. This card is designed to be displayed on a home or dashboard screen, providing a concise snapshot of agent data with interaction options like navigation, renaming, and additional actions via a dropdown menu.

The component leverages other UI components (HomeCard, MoreButton, SharedBadge, AgentDropdown) and hooks (useNavigatePage, useRenameAgent) to encapsulate its functionality. It receives an agent data object and a function to trigger an agent rename modal, then renders a card with agent details, a shared badge, and a dropdown menu for further options.


Detailed Explanation

Imports


Types

DatasetCardProps

export type DatasetCardProps = {
  data: IFlow;
} & Pick<ReturnType<typeof useRenameAgent>, 'showAgentRenameModal'>;

Component: AgentCard

export function AgentCard({ data, showAgentRenameModal }: DatasetCardProps) { 
  const { navigateToAgent } = useNavigatePage();

  return (
    <HomeCard
      data={{ ...data, name: data.title, description: data.description || '' }}
      moreDropdown={
        <AgentDropdown showAgentRenameModal={showAgentRenameModal} agent={data}>
          <MoreButton></MoreButton>
        </AgentDropdown>
      }
      sharedBadge={<SharedBadge>{data.nickname}</SharedBadge>}
      onClick={navigateToAgent(data?.id)}
    />
  );
}

Description

AgentCard is a presentational component that displays an agent's information on a card with interactive elements.

Parameters

Return Value

Usage Example

import { useRenameAgent } from './use-rename-agent';
import { AgentCard } from './agent-card';

function AgentsList({ agents }) {
  const { showAgentRenameModal } = useRenameAgent();

  return (
    <div>
      {agents.map(agent => (
        <AgentCard key={agent.id} data={agent} showAgentRenameModal={showAgentRenameModal} />
      ))}
    </div>
  );
}

Implementation Details


Interaction with Other Parts of the System


Visual Diagram

The following Mermaid component diagram illustrates how the AgentCard component composes and interacts with other UI components and hooks:

componentDiagram
    AgentCard <|-- HomeCard
    AgentCard o-- AgentDropdown
    AgentDropdown *-- MoreButton
    AgentCard o-- SharedBadge
    AgentCard ..> useNavigatePage : uses
    AgentCard ..> useRenameAgent : uses (showAgentRenameModal)

Summary

agent-card.tsx provides a reusable, interactive card component that encapsulates agent data presentation and user interactions such as navigation and renaming. It composes several smaller UI components and hooks to provide a modular and maintainable design, fitting seamlessly into a dashboard or home screen listing of agents. This file plays a pivotal role in bridging agent data and user actions within the application UI.