diff --git a/package.json b/package.json index 722f651f..26432314 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "next": "14.2.10", "next-themes": "^0.3.0", "posthog-js": "^1.161.5", + "pretty-bytes": "^6.1.1", "react": "^18", "react-dom": "^18", "react-hook-form": "^7.53.0", diff --git a/src/app/repos/columns.tsx b/src/app/repos/columns.tsx index a9b9fdd5..d0477e44 100644 --- a/src/app/repos/columns.tsx +++ b/src/app/repos/columns.tsx @@ -4,6 +4,7 @@ import { Button } from "@/components/ui/button"; import { getRepoCodeHostInfo } from "@/lib/utils"; import { Column, ColumnDef } from "@tanstack/react-table" import { ArrowUpDown } from "lucide-react" +import prettyBytes from "pretty-bytes"; export type RepositoryColumnInfo = { name: string; @@ -90,7 +91,7 @@ export const columns: ColumnDef[] = [ accessorKey: "indexSizeBytes", header: ({ column }) => createSortHeader("Index Size", column), cell: ({ row }) => { - const size = getFormattedSizeString(row.original.indexSizeBytes); + const size = prettyBytes(row.original.indexSizeBytes); return
{size}
; } }, @@ -98,7 +99,7 @@ export const columns: ColumnDef[] = [ accessorKey: "repoSizeBytes", header: ({ column }) => createSortHeader("Repository Size", column), cell: ({ row }) => { - const size = getFormattedSizeString(row.original.repoSizeBytes); + const size = prettyBytes(row.original.repoSizeBytes); return
{size}
; } }, @@ -120,19 +121,6 @@ export const columns: ColumnDef[] = [ } ] -const getFormattedSizeString = (bytes: number): string => { - let size = bytes; - const units = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB']; - let unitIndex = 0; - - while (size >= 1024 && unitIndex < units.length - 1) { - size /= 1024; - unitIndex++; - } - - return `${size.toFixed(2)} ${units[unitIndex]}`; -} - const createSortHeader = (name: string, column: Column) => { return (