Skip to content

Commit 34a4c33

Browse files
switch to using prettyBytes for repos table
1 parent a98db52 commit 34a4c33

3 files changed

Lines changed: 11 additions & 33 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"next": "14.2.10",
5353
"next-themes": "^0.3.0",
5454
"posthog-js": "^1.161.5",
55+
"pretty-bytes": "^6.1.1",
5556
"react": "^18",
5657
"react-dom": "^18",
5758
"react-hook-form": "^7.53.0",

src/app/repos/columns.tsx

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Button } from "@/components/ui/button";
44
import { getRepoCodeHostInfo } from "@/lib/utils";
55
import { Column, ColumnDef } from "@tanstack/react-table"
66
import { ArrowUpDown } from "lucide-react"
7+
import prettyBytes from "pretty-bytes";
78

89
export type RepositoryColumnInfo = {
910
name: string;
@@ -90,15 +91,15 @@ export const columns: ColumnDef<RepositoryColumnInfo>[] = [
9091
accessorKey: "indexSizeBytes",
9192
header: ({ column }) => createSortHeader("Index Size", column),
9293
cell: ({ row }) => {
93-
const size = getFormattedSizeString(row.original.indexSizeBytes);
94+
const size = prettyBytes(row.original.indexSizeBytes);
9495
return <div className="text-right">{size}</div>;
9596
}
9697
},
9798
{
9899
accessorKey: "repoSizeBytes",
99100
header: ({ column }) => createSortHeader("Repository Size", column),
100101
cell: ({ row }) => {
101-
const size = getFormattedSizeString(row.original.repoSizeBytes);
102+
const size = prettyBytes(row.original.repoSizeBytes);
102103
return <div className="text-right">{size}</div>;
103104
}
104105
},
@@ -120,19 +121,6 @@ export const columns: ColumnDef<RepositoryColumnInfo>[] = [
120121
}
121122
]
122123

123-
const getFormattedSizeString = (bytes: number): string => {
124-
let size = bytes;
125-
const units = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB'];
126-
let unitIndex = 0;
127-
128-
while (size >= 1024 && unitIndex < units.length - 1) {
129-
size /= 1024;
130-
unitIndex++;
131-
}
132-
133-
return `${size.toFixed(2)} ${units[unitIndex]}`;
134-
}
135-
136124
const createSortHeader = (name: string, column: Column<RepositoryColumnInfo, unknown>) => {
137125
return (
138126
<Button

yarn.lock

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3314,6 +3314,11 @@ prelude-ls@^1.2.1:
33143314
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.2.1.tgz#debc6489d7a6e6b0e7611888cec880337d316396"
33153315
integrity sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==
33163316

3317+
pretty-bytes@^6.1.1:
3318+
version "6.1.1"
3319+
resolved "https://registry.yarnpkg.com/pretty-bytes/-/pretty-bytes-6.1.1.tgz#38cd6bb46f47afbf667c202cfc754bffd2016a3b"
3320+
integrity sha512-mQUvGU6aUFQ+rNvTIAcZuWGRT9a6f6Yrg9bHs4ImKF+HZCEK+plBvnAZYSIQztknZF2qnzNtr6F8s0+IuptdlQ==
3321+
33173322
prop-types@^15.8.1:
33183323
version "15.8.1"
33193324
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.8.1.tgz#67d87bf1a694f48435cf332c24af10214a3140b5"
@@ -3690,16 +3695,7 @@ streamsearch@^1.1.0:
36903695
resolved "https://registry.yarnpkg.com/streamsearch/-/streamsearch-1.1.0.tgz#404dd1e2247ca94af554e841a8ef0eaa238da764"
36913696
integrity sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==
36923697

3693-
"string-width-cjs@npm:string-width@^4.2.0":
3694-
version "4.2.3"
3695-
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
3696-
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
3697-
dependencies:
3698-
emoji-regex "^8.0.0"
3699-
is-fullwidth-code-point "^3.0.0"
3700-
strip-ansi "^6.0.1"
3701-
3702-
string-width@^4.1.0:
3698+
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0:
37033699
version "4.2.3"
37043700
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
37053701
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -3789,14 +3785,7 @@ string.prototype.trimstart@^1.0.8:
37893785
define-properties "^1.2.1"
37903786
es-object-atoms "^1.0.0"
37913787

3792-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
3793-
version "6.0.1"
3794-
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
3795-
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
3796-
dependencies:
3797-
ansi-regex "^5.0.1"
3798-
3799-
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
3788+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
38003789
version "6.0.1"
38013790
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
38023791
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==

0 commit comments

Comments
 (0)