agent-template-modal.tsx


Overview

agent-template-modal.tsx defines a React functional component named AgentTemplateModal, which provides a user interface modal dialog for creating new "agents" (or flows) based on existing flow templates. This modal presents a list of flow templates in a card grid format, allowing users to preview and select a template to create a new agent. Once a template is selected, a secondary modal (CreateAgentModal) is displayed to capture additional input (such as naming the new agent) before finalizing the creation process.

This component integrates localization, safe HTML rendering, and modal state management. It is designed to be part of a larger workflow/agent management system where users manage flow-based processes or automations.


Detailed Explanation

Component: AgentTemplateModal

Purpose

To display a modal window that lists available flow templates for the user to select from, and to handle the creation of new agents based on the selected template.

Props (IProps)

Prop Name

Type

Description

visible

boolean

Controls the visibility of the modal.

hideModal

() => void

Callback to hide/close the modal.

loading

boolean

Indicates loading state, typically during agent creation.

onOk

[(name: string, templateId: string) => void \

Promise](/projects/311/72190)

showModal?

() => void (optional)

Optional method to show the modal externally.

templateList

IFlowTemplate[]

Array of flow templates to display in the list. Each template includes metadata such as title, description, and avatar.

Internal State

Hooks Used

Rendered UI Elements

Key Methods

Usage Example

<AgentTemplateModal
  visible={isModalVisible}
  hideModal={() => setModalVisible(false)}
  loading={isCreating}
  onOk={async (name, templateId) => {
    await createAgent(name, templateId);
    setModalVisible(false);
  }}
  templateList={flowTemplates}
/>

Important Implementation Details


Interaction With Other Parts of the Application


Visual Diagram

componentDiagram
    direction LR
    AgentTemplateModal --|> React.Component
    AgentTemplateModal --> Modal : renders
    AgentTemplateModal --> List : renders template cards
    List --> Card : multiple cards for templates
    Card --> GraphAvatar : displays avatar
    Card --> Button : "Use Template" button (conditional)
    AgentTemplateModal --> CreateAgentModal : nested modal for creation input
    AgentTemplateModal ..> useSelectItem : manages selection state
    AgentTemplateModal ..> useSetModalState : manages nested modal visibility
    AgentTemplateModal ..> useTranslate : localization
    Card --> DOMPurify : sanitizes description HTML

Summary

agent-template-modal.tsx is a React component that allows users to select a flow template from a list and create a new agent based on that template. It features a clean and interactive UI using Ant Design components, integrates localization, safe HTML rendering, and modal state management hooks, and connects to other components like CreateAgentModal and GraphAvatar to provide a cohesive user experience in the agent creation workflow.