import React from 'react'; import { useStore } from '../../store/useStore'; import type { TestCaseNode } from '../../store/useStore'; import { BarChart3, PieChart, TrendingUp, CheckCircle2, XCircle, AlertCircle } from 'lucide-react'; const DashboardView: React.FC = () => { const { spaceData, currentSpaceId, testTasks, setViewMode, setSelectedTaskId, currentUser } = useStore(); const testCases = spaceData[currentSpaceId] || []; const handleOpenTask = (taskId: string) => { setSelectedTaskId(taskId); setViewMode('execution'); }; // Simple aggregation logic const getStats = (nodes: TestCaseNode[]) => { let stats = { total: 0, P0: 0, P1: 0, P2: 0, P3: 0, pass: 0, fail: 0, untested: 0 }; const traverse = (items: TestCaseNode[]) => { items.forEach(node => { stats.total++; if (node.priority) stats[node.priority]++; if (node.executionStatus === 'PASS') stats.pass++; else if (node.executionStatus === 'FAIL') stats.fail++; else stats.untested++; if (node.children) traverse(node.children); }); }; traverse(nodes); return stats; }; const stats = getStats(testCases); const passRate = stats.total > 0 ? Math.round((stats.pass / stats.total) * 100) : 0; return (
总用例数
{stats.total}
较上周 +12%
通过率
{passRate}%
P0 核心用例
{stats.P0}

执行分布 (Execution Distribution)

已通过 (Pass)
0 ? (stats.pass/stats.total)*100 : 0}%` }}>
{stats.pass}
未通过 (Fail)
0 ? (stats.fail/stats.total)*100 : 0}%` }}>
{stats.fail}
未开始 (Untested)
0 ? (stats.untested/stats.total)*100 : 0}%` }}>
{stats.untested}

优先级分布 (Priority Analysis)

{['P0', 'P1', 'P2', 'P3'].map(p => { const count = stats[p as keyof typeof stats] as number; const percentage = stats.total > 0 ? (count / stats.total) * 100 : 0; return (
{count}
{p}
); })}

通过率概览 (Pass Rate Donut)

{passRate}% 通过
通过: {stats.pass}
失败: {stats.fail}
未执行: {stats.untested}

任务看板 (Task Board)

{testTasks.length === 0 ? (
暂无执行任务
) : ( testTasks.map(task => (
handleOpenTask(task.id)} >
{task.name} {((task.assignee && task.assignee.startsWith('ou_')) || !task.assignee) ? (currentUser?.name || '未知用户') : task.assignee} · {task.createdAt?.split('T')[0]}
{task.status === 'RUNNING' && '运行中'} {task.status === 'PENDING' && '未运行'} {task.status === 'COMPLETED' && '已完成'}
)) )}
); }; export default DashboardView;