From f0b69f5768abd14efbc1e277cf5bf783484f7cc9 Mon Sep 17 00:00:00 2001 From: cfngc4594 Date: Tue, 19 May 2026 16:49:12 +0800 Subject: [PATCH] fix(student-dashboard): handle empty pie chart data states gracefully --- .../dashboard/student/dashboard/page.tsx | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/app/(protected)/dashboard/student/dashboard/page.tsx b/src/app/(protected)/dashboard/student/dashboard/page.tsx index 2db7818..4c90a1a 100644 --- a/src/app/(protected)/dashboard/student/dashboard/page.tsx +++ b/src/app/(protected)/dashboard/student/dashboard/page.tsx @@ -94,6 +94,12 @@ export default function StudentDashboard() { errorPieChartData, } = data; const COLORS = ["#4CAF50", "#FFC107"]; + const EMPTY_CHART_COLOR = "#E5E7EB"; + const hasCompletionRecord = completionData.completed > 0; + const hasErrorChartData = errorPieChartData.some((item) => item.value > 0); + const normalizedErrorPieChartData = hasErrorChartData + ? errorPieChartData + : [{ name: "暂无数据", value: 1 }]; return (
@@ -144,6 +150,11 @@ export default function StudentDashboard() {
+ {!hasCompletionRecord && ( +
+ 暂无完成记录 +
+ )} @@ -166,7 +177,7 @@ export default function StudentDashboard() { - {errorPieChartData.map( + {normalizedErrorPieChartData.map( ( entry: { name: string; value: number }, index: number ) => ( ) )} @@ -190,6 +205,11 @@ export default function StudentDashboard() { + {!hasErrorChartData && ( +
+ 暂无作答数据 +
+ )}