template-card.tsx


Overview

template-card.tsx defines a React functional component named TemplateCard that visually represents a flow template in a card format. This component is part of a UI library for displaying flow templates with localized titles and descriptions, an avatar, and an interactive button to trigger actions such as using or creating a flow based on the template.

The component is designed to be reusable within a larger application that manages or displays flow templates (likely a workflow or automation system). It handles localization, user interaction, and UI presentation cohesively.


Detailed Explanation

Component: TemplateCard

Purpose

TemplateCard displays information for a single flow template (IFlowTemplate). It shows an avatar, localized title and description, and a button that when clicked, triggers a modal to use or create a flow from this template.

Props

Prop Name

Type

Description

data

IFlowTemplate

The flow template data object containing avatar, title, description, etc.

isCreate

boolean (optional)

(Not currently used in this component, reserved for future use)

showModal

(record: IFlowTemplate) => void

Callback function to open a modal with the selected template data

Internal Hooks & Variables

JSX Structure

Usage Example

import { TemplateCard } from './template-card';
import { IFlowTemplate } from '@/interfaces/database/flow';

const template: IFlowTemplate = {
  id: 'template1',
  avatar: 'https://example.com/avatar.png',
  title: { en: 'My Template', zh: '我的模板' },
  description: { en: 'A description in English.', zh: '中文描述。' },
  // other properties...
};

function onShowModal(template: IFlowTemplate) {
  console.log('Open modal for template:', template);
}

<TemplateCard data={template} showModal={onShowModal} />;

Implementation Details and Algorithms


Interaction with Other Parts of the System


Visual Diagram

componentDiagram
    direction TB
    TemplateCard <|-- Card
    TemplateCard <|-- CardContent
    TemplateCard <|-- RAGFlowAvatar
    TemplateCard <|-- Button

    Card -- contains --> CardContent
    CardContent -- contains --> RAGFlowAvatar
    CardContent -- contains --> Title & Description Text
    CardContent -- contains --> OverlayButton

    RAGFlowAvatar : props.avatar
    RAGFlowAvatar : props.name

    Button : onClick = handleClick
    Button : label = t('flow.useTemplate')

    TemplateCard : props.data (IFlowTemplate)
    TemplateCard : props.showModal(record)

    note right of TemplateCard
      - Uses i18n.language for localization
      - Calls showModal(data) on button click
    end note

Summary

This file is primarily a presentational and interaction component within the flow template management UI.