From ddcabac564bf173a907f14700ae74eb61757b4c4 Mon Sep 17 00:00:00 2001 From: Tola Leng Date: Sun, 15 Jun 2025 21:27:58 +0800 Subject: [PATCH] Fix: Syntax errors in public status page --- .../public/OverallUptimeSection.tsx | 172 ++++++++++++++++-- 1 file changed, 160 insertions(+), 12 deletions(-) diff --git a/application/src/components/public/OverallUptimeSection.tsx b/application/src/components/public/OverallUptimeSection.tsx index 9387f1b..2cf8f6c 100644 --- a/application/src/components/public/OverallUptimeSection.tsx +++ b/application/src/components/public/OverallUptimeSection.tsx @@ -1,5 +1,7 @@ import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; +import { Badge } from '@/components/ui/badge'; +import { TrendingUp, Calendar, BarChart3 } from 'lucide-react'; import { UptimeData } from '@/types/service.types'; import { UptimeHistoryRenderer } from './UptimeHistoryRenderer'; @@ -24,24 +26,170 @@ export const OverallUptimeSection = ({ uptimeData }: OverallUptimeSectionProps) return Math.round((upRecords / totalRecords) * 100 * 100) / 100; }; + const getUptimeTrend = () => { + const uptime = getOverallUptime(); + if (uptime >= 99.9) return 'excellent'; + if (uptime >= 99.5) return 'good'; + if (uptime >= 95) return 'fair'; + return 'poor'; + }; + + const getIncidentCount = () => { + const allHistories = Object.values(uptimeData); + let incidents = 0; + + allHistories.forEach(history => { + let wasDown = false; + history.forEach(record => { + if (record.status === 'down' && !wasDown) { + incidents++; + wasDown = true; + } else if (record.status === 'up') { + wasDown = false; + } + }); + }); + + return incidents; + }; + + const getBadgeClassName = (trend: string) => { + switch (trend) { + case 'excellent': + return 'bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200'; + case 'good': + return 'bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200'; + case 'fair': + return 'bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-200'; + default: + return 'bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200'; + } + }; + + const getTrendText = (trend: string) => { + switch (trend) { + case 'excellent': + return 'Excellent'; + case 'good': + return 'Good'; + case 'fair': + return 'Fair'; + default: + return 'Needs Improvement'; + } + }; + + const getStatusMessage = (uptime: number) => { + if (uptime >= 99.9) { + return "All systems are performing excellently with minimal downtime."; + } else if (uptime >= 99.5) { + return "Systems are performing well with occasional minor issues."; + } else if (uptime >= 95) { + return "We're working to improve system reliability and reduce incidents."; + } else { + return "We apologize for recent service disruptions and are actively working on improvements."; + } + }; + + const overallUptime = getOverallUptime(); + const trend = getUptimeTrend(); + const incidentCount = getIncidentCount(); + return ( - Overall Uptime History (Last 90 days) + + + Performance Metrics (Last 90 Days) + +

+ Historical performance and reliability statistics +

- -
- {Object.keys(uptimeData).length > 0 ? - : - } + +
+
+
+
+ + Overall Uptime +
+ + {getTrendText(trend)} + +
+
{overallUptime}%
+
+ Target: 99.9% +
+
+ +
+
+ + Incidents +
+
{incidentCount}
+
+ Last 90 days +
+
+ +
+
+ + Avg Response +
+
100ms
+
+ Response time +
+
-
- 90 days ago - Today + +
+
+

Uptime History

+
+
+
+ Operational +
+
+
+ Degraded +
+
+
+ Down +
+
+
+ +
+ {Object.keys(uptimeData).length > 0 ? ( + + ) : ( +
+
+ {Array.from({ length: 90 }, (_, i) => ( +
+ ))} +
+
+ )} +
+ +
+ 90 days ago + Today +
-
-
{getOverallUptime()}%
-
Overall uptime
+ +
+
+ {getStatusMessage(overallUptime)} +