switch to using prettyBytes for repos table

This commit is contained in:
bkellam 2024-09-26 13:03:23 -07:00
parent a98db52bf4
commit 34a4c336c7
3 changed files with 11 additions and 33 deletions

View file

@ -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",

View file

@ -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<RepositoryColumnInfo>[] = [
accessorKey: "indexSizeBytes",
header: ({ column }) => createSortHeader("Index Size", column),
cell: ({ row }) => {
const size = getFormattedSizeString(row.original.indexSizeBytes);
const size = prettyBytes(row.original.indexSizeBytes);
return <div className="text-right">{size}</div>;
}
},
@ -98,7 +99,7 @@ export const columns: ColumnDef<RepositoryColumnInfo>[] = [
accessorKey: "repoSizeBytes",
header: ({ column }) => createSortHeader("Repository Size", column),
cell: ({ row }) => {
const size = getFormattedSizeString(row.original.repoSizeBytes);
const size = prettyBytes(row.original.repoSizeBytes);
return <div className="text-right">{size}</div>;
}
},
@ -120,19 +121,6 @@ export const columns: ColumnDef<RepositoryColumnInfo>[] = [
}
]
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<RepositoryColumnInfo, unknown>) => {
return (
<Button

View file

@ -3314,6 +3314,11 @@ prelude-ls@^1.2.1:
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.2.1.tgz#debc6489d7a6e6b0e7611888cec880337d316396"
integrity sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==
pretty-bytes@^6.1.1:
version "6.1.1"
resolved "https://registry.yarnpkg.com/pretty-bytes/-/pretty-bytes-6.1.1.tgz#38cd6bb46f47afbf667c202cfc754bffd2016a3b"
integrity sha512-mQUvGU6aUFQ+rNvTIAcZuWGRT9a6f6Yrg9bHs4ImKF+HZCEK+plBvnAZYSIQztknZF2qnzNtr6F8s0+IuptdlQ==
prop-types@^15.8.1:
version "15.8.1"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.8.1.tgz#67d87bf1a694f48435cf332c24af10214a3140b5"
@ -3690,16 +3695,7 @@ streamsearch@^1.1.0:
resolved "https://registry.yarnpkg.com/streamsearch/-/streamsearch-1.1.0.tgz#404dd1e2247ca94af554e841a8ef0eaa238da764"
integrity sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==
"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"
string-width@^4.1.0:
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@ -3789,14 +3785,7 @@ string.prototype.trimstart@^1.0.8:
define-properties "^1.2.1"
es-object-atoms "^1.0.0"
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==