/* * @Author: ZhaoYing * @Date: 2026-02-03 18:32:35 * @Last Modified by: ZhaoYing * @Last Modified time: 2026-02-05 19:07:07 */ /** * Node Statistics Component * Displays memory node statistics by type with navigation to detail views */ import { type FC, useEffect, useState } from 'react' import clsx from 'clsx' import { useTranslation } from 'react-i18next' import { useParams, useNavigate } from 'react-router-dom' import { Skeleton, Flex, Divider } from 'antd'; import { getNodeStatistics, } from '@/api/memory' import type { NodeStatisticsItem } from '../types' /** Memory type configuration */ const typeList = [ { key: 'PERCEPTUAL_MEMORY', bg: 0 }, { key: 'WORKING_MEMORY', bg: 1 }, { key: 'EMOTIONAL_MEMORY', bg: 2 }, { key: 'SHORT_TERM_MEMORY', bg: 3 }, { key: 'FORGET_MEMORY', bg: 5 }, { key: 'LONG_TERM_MEMORY', bg: 4, children: [ { key: 'IMPLICIT_MEMORY' }, { key: 'EPISODIC_MEMORY' }, { key: 'EXPLICIT_MEMORY' } ] }, ] const NodeStatistics: FC = () => { const navigate = useNavigate(); const { t } = useTranslation() const { id } = useParams() const [loading, setLoading] = useState(false) const [data, setData] = useState([]) useEffect(() => { if (!id) return getData() }, [id]) /** Fetch node statistics */ const getData = () => { if (!id) return setLoading(true) getNodeStatistics(id).then((res) => { const response = res as NodeStatisticsItem[] setData(response) setLoading(false) }) .finally(() => { setLoading(false) }) } /** Navigate to detail page */ const handleViewDetail = (type: string) => { navigate(`/user-memory/detail/${id}/${type}`) } /** Render statistics card */ const renderCard = (key: string, isChild: boolean = false) => { const item = data.find((item) => item.type === key) return ( handleViewDetail(key)} >
{t(`userMemory.${key}`)}
{item?.count ?? 0}
) } return (
{loading ? :
{typeList.map((vo) => { if (!vo.children) { return
{renderCard(vo.key)}
} return (
{t(`userMemory.${vo.key}`)}
{vo.children.map((child, index) => {index > 0 && } {renderCard(child.key, true)} )}
) })}
}
) } export default NodeStatistics