index.tsx
Overview
This file defines a React functional component named FlowCard that renders a card UI element representing a "flow" entity. The card displays details such as the flow's title, description, last update time, and associated user avatar. It also provides interactive features including navigation to the flow's detail page and an operation dropdown menu for managing the flow (e.g., deleting it). The component integrates with hooks for user information fetching and flow deletion, and uses Ant Design components for UI elements and styling.
Component: FlowCard
Description
FlowCard is a presentational and interactive component that:
Shows the flow’s avatar, title, description, and last updated time.
Highlights the flow owner with a badge ribbon.
Allows users to navigate to a detailed view of the flow by clicking the card.
Provides an operations dropdown menu to delete the flow.
Styles and organizes information using Ant Design (
antd) components and custom CSS modules.
Props
Prop | Type | Required | Description |
|---|---|---|---|
|
| Yes | The flow object to be displayed in the card. |
| No | Optional callback triggered when the flow is deleted. |
Interfaces
IFlow(imported) represents the flow data structure, expected to have fields such asid,title,description,nickname,avatar,update_time, andpermission.
Internal Hooks and Utilities
useNavigate(fromumi): for programmatic navigation.useDeleteFlow: custom hook providingdeleteFlowmethod to delete flows.useFetchUserInfo: custom hook fetching current user information.formatDate: utility function formatting date strings.classNames: utility to conditionally join CSS classes.
Methods
removeFlow
Type:
() => Promise<void>Description: Invokes the
deleteFlowmethod with the current flow's ID to delete it.Usage: Passed to the
OperateDropdowncomponent as the delete handler.
handleCardClick
Type:
() => voidDescription: Navigates the user to the detailed flow page at
/flow/{flowId}when the card is clicked.
Rendered Elements
Badge.Ribbon: Wraps the card; shows the flow owner's nickname as a ribbon. The ribbon color depends on whether the flow owner matches the current user.
Card: The main container clickable area for the flow.
GraphAvatar: Displays the flow's avatar.
OperateDropdown: Dropdown menu with operation options, including delete.
Typography.Title: Displays the flow title with ellipsis and tooltip.
Description paragraph: Shows the flow description with truncation and tooltip.
Footer: Shows last updated time with calendar icon.
Usage Example
import FlowCard from './index';
import { IFlow } from '@/interfaces/database/flow';
const flowExample: IFlow = {
id: '123',
title: 'My Flow',
description: 'This is a sample flow description.',
nickname: 'Alice',
avatar: 'https://example.com/avatar.png',
update_time: '2024-06-01T12:34:56Z',
permission: 'team',
};
const onDeleteHandler = (id: string) => {
console.log(`Flow with id ${id} deleted`);
};
<FlowCard item={flowExample} onDelete={onDeleteHandler} />;
Implementation Details
Conditional Ribbon Color: The ribbon color is blue (
#1677ff) if the flow's owner matches the current user, otherwise pink.Ribbon Visibility: The ribbon is hidden if the flow's permission is not
'team'.Navigation: Uses
useNavigatefromumito change routes on card click.Deletion: Uses a custom hook
useDeleteFlowto delete the flow asynchronously.Styling: Uses CSS modules (
index.less) for scoped styling. TheclassNameslibrary helps conditionally apply classes.Performance:
removeFlowis memoized withuseCallbackto avoid unnecessary re-renders.Accessibility: Uses tooltips for truncated text to improve usability.
Interaction with Other System Parts
Hooks:
useDeleteFlowmanages deletion logic possibly involving API calls and cache updates.useFetchUserInfofetches the logged-in user data to customize UI.
Components:
OperateDropdownprovides UI for flow operations.GraphAvatarshows the flow's avatar image.
Utilities:
formatDateformats timestamps for display.
Routing:
Navigates to
/flow/{flowId}, linking this UI component to the flow detail page in the application.
Styling:
Uses a local CSS module for component-specific styles.
Icons:
Uses Ant Design's
CalendarOutlinedicon to visually indicate update date.
Mermaid Diagram: Component Structure and Interaction
componentDiagram
FlowCard <|-- GraphAvatar
FlowCard <|-- OperateDropdown
FlowCard o-- Badge.Ribbon
FlowCard o-- Card
FlowCard o-- Typography.Title
FlowCard o-- CalendarOutlined
FlowCard ..> useNavigate : navigation
FlowCard ..> useDeleteFlow : deleteFlow()
FlowCard ..> useFetchUserInfo : userInfo
FlowCard ..> formatDate : format update_time
FlowCard ..> classNames : conditional styling
GraphAvatar : Displays avatar image
OperateDropdown : Provides flow operations (delete)
Badge.Ribbon : Shows nickname ribbon
Typography.Title : Shows flow title with tooltip
CalendarOutlined : Icon for update time
Summary
The index.tsx file provides a reusable, interactive card component (FlowCard) to display flow information in a visually appealing and user-friendly manner. It leverages React hooks, Ant Design UI components, and custom utilities to integrate seamlessly with the application’s data management and navigation systems. This modular design facilitates consistent display and management of flow entities throughout the app.