Skip to content

Commit cd3d5e6

Browse files
fix(dashboard): render Ki-range sizes as Ki, not raw bytes
humanizeBytes branched on Ti/Gi/Mi and then fell through to a raw byte count, so every value between 1KiB and 1MiB printed as e.g. "524288B" instead of "512Ki". Add the missing Ki branch, formatted without decimals like the Mi branch above it. Fixes #3105 Signed-off-by: Myasnikov Daniil <[email protected]>
1 parent 02c6942 commit cd3d5e6

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

‎packages/system/dashboard/images/console/apps/console/src/lib/k8s-quantity.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ describe("humanizeBytes", () => {
101101
expect(humanizeBytes(1023)).toBe("1023B")
102102
})
103103

104+
it("formats kilobytes as Ki without decimals", () => {
105+
expect(humanizeBytes(1024)).toBe("1Ki")
106+
expect(humanizeBytes(512 * 1024)).toBe("512Ki")
107+
})
108+
104109
it("formats megabytes as Mi without decimals", () => {
105110
expect(humanizeBytes(1024 ** 2)).toBe("1Mi")
106111
})

‎packages/system/dashboard/images/console/apps/console/src/lib/k8s-quantity.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export function humanizeBytes(bytes: number): string {
3333
if (bytes >= 1024 ** 4) return `${(bytes / 1024 ** 4).toFixed(1)}Ti`
3434
if (bytes >= 1024 ** 3) return `${(bytes / 1024 ** 3).toFixed(1)}Gi`
3535
if (bytes >= 1024 ** 2) return `${(bytes / 1024 ** 2).toFixed(0)}Mi`
36+
if (bytes >= 1024) return `${(bytes / 1024).toFixed(0)}Ki`
3637
return `${bytes}B`
3738
}
3839

0 commit comments

Comments
 (0)