diff --git a/frontend/src/app/data/page.tsx b/frontend/src/app/data/page.tsx index 04943c991a..b4969e4ec9 100644 --- a/frontend/src/app/data/page.tsx +++ b/frontend/src/app/data/page.tsx @@ -11,18 +11,16 @@ import { Trophy, XCircle, } from "lucide-react"; -import { - Bar, - BarChart, - CartesianGrid, - Cell, - LabelList, - XAxis, -} from "recharts"; -import React, { useEffect, useMemo, useState } from "react"; +import { useEffect, useMemo, useState } from "react"; +import { Bar, BarChart, CartesianGrid, Cell, LabelList, XAxis } from "recharts"; import type { ChartConfig } from "@/components/ui/chart"; +import { formattedBadge } from "@/components/command-menu"; +import { Badge } from "@/components/ui/badge"; +import { Button } from "@/components/ui/button"; +import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; +import { ChartContainer, ChartTooltip, ChartTooltipContent } from "@/components/ui/chart"; import { Dialog, DialogContent, @@ -31,37 +29,10 @@ import { DialogTitle, DialogTrigger, } from "@/components/ui/dialog"; -import { - Table, - TableBody, - TableCell, - TableHead, - TableHeader, - TableRow, -} from "@/components/ui/table"; -import { - Select, - SelectContent, - SelectItem, - SelectTrigger, - SelectValue, -} from "@/components/ui/select"; -import { - Card, - CardContent, - CardDescription, - CardHeader, - CardTitle, -} from "@/components/ui/card"; -import { - ChartContainer, - ChartTooltip, - ChartTooltipContent, -} from "@/components/ui/chart"; -import { formattedBadge } from "@/components/command-menu"; import { ScrollArea } from "@/components/ui/scroll-area"; -import { Button } from "@/components/ui/button"; -import { Badge } from "@/components/ui/badge"; +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; +import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; +import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"; type DataModel = { id: number; @@ -141,7 +112,8 @@ export default function DataPage() { const [summaryRes, dataRes] = await Promise.all([ fetch("https://api.htl-braunau.at/data/summary"), fetch( - `https://api.htl-braunau.at/data/paginated?page=${currentPage}&limit=${itemsPerPage === 0 ? "" : itemsPerPage + `https://api.htl-braunau.at/data/paginated?page=${currentPage}&limit=${ + itemsPerPage === 0 ? "" : itemsPerPage }`, ), ]); @@ -158,11 +130,9 @@ export default function DataPage() { setSummary(summaryData); setData(pageData); - } - catch (err) { + } catch (err) { setError((err as Error).message); - } - finally { + } finally { setLoading(false); } }; @@ -171,8 +141,7 @@ export default function DataPage() { }, [currentPage, itemsPerPage]); const sortedData = useMemo(() => { - if (!sortConfig) - return data; + if (!sortConfig) return data; return [...data].sort((a, b) => { if (a[sortConfig.key] < b[sortConfig.key]) { return sortConfig.direction === "ascending" ? -1 : 1; @@ -186,11 +155,7 @@ export default function DataPage() { const requestSort = (key: string) => { let direction: "ascending" | "descending" = "ascending"; - if ( - sortConfig - && sortConfig.key === key - && sortConfig.direction === "ascending" - ) { + if (sortConfig && sortConfig.key === key && sortConfig.direction === "ascending") { direction = "descending"; } setSortConfig({ key, direction }); @@ -205,10 +170,8 @@ export default function DataPage() { }; const getTypeBadge = (type: string) => { - if (type === "lxc") - return formattedBadge("ct"); - if (type === "vm") - return formattedBadge("vm"); + if (type === "lxc") return formattedBadge("ct"); + if (type === "vm") return formattedBadge("vm"); return null; }; @@ -219,8 +182,7 @@ export default function DataPage() { const successRate = totalCount > 0 ? (successCount / totalCount) * 100 : 0; const allApps = useMemo(() => { - if (!summary?.nsapp_count) - return []; + if (!summary?.nsapp_count) return []; return Object.entries(summary.nsapp_count).sort(([, a], [, b]) => b - a); }, [summary]); @@ -255,9 +217,7 @@ export default function DataPage() { {/* Header */}

Analytics

-

- Overview of container installations and system statistics. -

+

Overview of container installations and system statistics.

{/* Widgets */} @@ -269,9 +229,7 @@ export default function DataPage() {
{nf.format(totalCount)}
-

- Total LXC/VM entries found -

+

Total LXC/VM entries found

@@ -281,15 +239,8 @@ export default function DataPage() { -
- {successRate.toFixed(1)} - % -
-

- {nf.format(successCount)} - {" "} - successful installations -

+
{successRate.toFixed(1)}%
+

{nf.format(successCount)} successful installations

@@ -300,9 +251,7 @@ export default function DataPage() {
{nf.format(failureCount)}
-

- Installations encountered errors -

+

Installations encountered errors

@@ -312,13 +261,9 @@ export default function DataPage() { -
- {mostPopularApp ? mostPopularApp[0] : "N/A"} -
+
{mostPopularApp ? mostPopularApp[0] : "N/A"}

- {mostPopularApp ? nf.format(mostPopularApp[1]) : 0} - {" "} - installations + {mostPopularApp ? nf.format(mostPopularApp[1]) : 0} installations

@@ -329,9 +274,7 @@ export default function DataPage() {
Top Applications - - The most frequently installed applications. - + The most frequently installed applications.
@@ -343,26 +286,14 @@ export default function DataPage() { Application Statistics - - Installation counts for all - {" "} - {allApps.length} - {" "} - applications. - + Installation counts for all {allApps.length} applications.
{allApps.map(([name, count], index) => ( -
+
- - {index + 1} - . - + {index + 1}. {name}
{nf.format(count)} @@ -375,47 +306,37 @@ export default function DataPage() {
- {loading - ? ( -
- -
- ) - : ( - - - - (value.length > 8 ? `${value.slice(0, 8)}...` : value)} - /> - } - /> - - {appsChartData.map((entry, index) => ( - - ))} - - - - - )} + {loading ? ( +
+ +
+ ) : ( + + + + (value.length > 8 ? `${value.slice(0, 8)}...` : value)} + /> + } /> + + {appsChartData.map((entry, index) => ( + + ))} + + + + + )}
@@ -425,15 +346,10 @@ export default function DataPage() {
Installation Log - - Detailed records of all container creation attempts. - + Detailed records of all container creation attempts.
- setItemsPerPage(Number(val))}> @@ -451,161 +367,108 @@ export default function DataPage() { - requestSort("status")} - > + requestSort("status")}> Status - {sortConfig?.key === "status" && ( - - )} + {sortConfig?.key === "status" && } - requestSort("type")} - > + requestSort("type")}> Type - {sortConfig?.key === "type" && ( - - )} + {sortConfig?.key === "type" && } - requestSort("nsapp")} - > + requestSort("nsapp")}> Application - {sortConfig?.key === "nsapp" && ( - - )} + {sortConfig?.key === "nsapp" && } - requestSort("os_type")} - > + requestSort("os_type")}> OS - {sortConfig?.key === "os_type" && ( - - )} + {sortConfig?.key === "os_type" && } requestSort("disk_size")} > Disk Size - {sortConfig?.key === "disk_size" && ( - - )} + {sortConfig?.key === "disk_size" && } requestSort("core_count")} > Core Count - {sortConfig?.key === "core_count" && ( - - )} + {sortConfig?.key === "core_count" && } requestSort("ram_size")} > RAM Size - {sortConfig?.key === "ram_size" && ( - - )} + {sortConfig?.key === "ram_size" && } - requestSort("created_at")} - > + requestSort("created_at")}> Created At - {sortConfig?.key === "created_at" && ( - - )} + {sortConfig?.key === "created_at" && } - {loading - ? ( - - -
- - {" "} - Loading data... -
-
-
- ) - : sortedData.length > 0 - ? ( - sortedData.map((item, idx) => ( - - - {item.status === "done" - ? ( - - Success - - ) - : item.status === "failed" - ? ( - - Failed - - ) - : item.status === "installing" - ? ( - - Installing - - ) - : ( - - {item.status} - - )} - - - {getTypeBadge(item.type) || ( - - {item.type} - - )} - - - {item.nsapp} - - - {item.os_type} - {" "} - {item.os_version} - - - {item.disk_size} - MB - - - {item.core_count} - - - {item.ram_size} - MB - - - {formatDate(item.created_at)} - - - )) - ) - : ( - - - No results found. - - - )} + {loading ? ( + + +
+ Loading data... +
+
+
+ ) : sortedData.length > 0 ? ( + sortedData.map((item, idx) => ( + + + {item.status === "done" ? ( + Success + ) : item.status === "failed" ? ( + + + + Failed + + +

Error:

+

{item.error || "Unknown error"}

+
+
+
+ ) : item.status === "installing" ? ( + Installing + ) : ( + {item.status} + )} +
+ + {getTypeBadge(item.type) || {item.type}} + + {item.nsapp} + + {item.os_type} {item.os_version} + + + {item.disk_size} + GB + + {item.core_count} + + {item.ram_size} + MB + + {formatDate(item.created_at)} +
+ )) + ) : ( + + + No results found. + + + )}
@@ -614,21 +477,17 @@ export default function DataPage() { -
- Page - {" "} - {currentPage} -
+
Page {currentPage}