From 1e282f76227533e605bd421dbddf9b04e2e6fcbf Mon Sep 17 00:00:00 2001 From: "coderhelm[bot]" <272032808+coderhelm[bot]@users.noreply.github.com> Date: Thu, 23 Jul 2026 05:02:19 +0000 Subject: [PATCH 1/2] #41: Add typed formatBytes utility function --- dashboard/src/lib/formatBytes.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 dashboard/src/lib/formatBytes.ts diff --git a/dashboard/src/lib/formatBytes.ts b/dashboard/src/lib/formatBytes.ts new file mode 100644 index 00000000..c194e67e --- /dev/null +++ b/dashboard/src/lib/formatBytes.ts @@ -0,0 +1,11 @@ +export function formatBytes(bytes: number, decimals: number = 1): string { + if (!Number.isFinite(bytes) || bytes < 0) return "N/A"; + if (bytes === 0) return "0 B"; + + const sizes: string[] = ["B", "KB", "MB", "GB", "TB", "PB"]; + const k: number = 1024; + const i: number = Math.min(Math.floor(Math.log(bytes) / Math.log(k)), sizes.length - 1); + const d: number = Math.min(Math.max(Math.floor(decimals), 0), 20); + + return `${(bytes / Math.pow(k, i)).toFixed(d)} ${sizes[i]}`; +} From ebbcfd5f993ac8bd863723684ed115ca0c66d534 Mon Sep 17 00:00:00 2001 From: "coderhelm[bot]" <272032808+coderhelm[bot]@users.noreply.github.com> Date: Thu, 23 Jul 2026 05:04:43 +0000 Subject: [PATCH 2/2] refactor: use shared formatBytes utility in aws settings page --- dashboard/src/app/settings/aws/page.tsx | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/dashboard/src/app/settings/aws/page.tsx b/dashboard/src/app/settings/aws/page.tsx index 608c3a76..58798cd0 100644 --- a/dashboard/src/app/settings/aws/page.tsx +++ b/dashboard/src/app/settings/aws/page.tsx @@ -5,6 +5,7 @@ import { useRouter } from "next/navigation"; import { api, type AwsConnection, type LogGroup, type Recommendation } from "@/lib/api"; import { useToast } from "@/components/toast"; import { RoleGuard } from "@/components/role-guard"; +import { formatBytes } from "@/lib/formatBytes"; const STATUS_STYLES: Record = { active: { bg: "bg-emerald-500/10", text: "text-emerald-400", dot: "bg-emerald-400" }, @@ -834,11 +835,3 @@ function AddConnectionModal({ ); } - -function formatBytes(bytes: number): string { - if (bytes === 0) return "0 B"; - const k = 1024; - const sizes = ["B", "KB", "MB", "GB", "TB"]; - const i = Math.floor(Math.log(bytes) / Math.log(k)); - return `${(bytes / Math.pow(k, i)).toFixed(1)} ${sizes[i]}`; -}