Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions dashboard/src/app/settings/aws/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, { bg: string; text: string; dot: string }> = {
active: { bg: "bg-emerald-500/10", text: "text-emerald-400", dot: "bg-emerald-400" },
Expand Down Expand Up @@ -834,11 +835,3 @@ function AddConnectionModal({
</div>
);
}

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]}`;
}
11 changes: 11 additions & 0 deletions dashboard/src/lib/formatBytes.ts
Original file line number Diff line number Diff line change
@@ -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]}`;
}
Loading