From fa3db545b9393ee7128b7e5901d8cfd2cb4091b0 Mon Sep 17 00:00:00 2001 From: Myasnikov Daniil Date: Sat, 15 Aug 2026 15:30:31 +0500 Subject: [PATCH] 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 --- .../images/console/apps/console/src/lib/k8s-quantity.test.ts | 5 +++++ .../images/console/apps/console/src/lib/k8s-quantity.ts | 1 + 2 files changed, 6 insertions(+) diff --git a/packages/system/dashboard/images/console/apps/console/src/lib/k8s-quantity.test.ts b/packages/system/dashboard/images/console/apps/console/src/lib/k8s-quantity.test.ts index f8e688b63..064ed2857 100644 --- a/packages/system/dashboard/images/console/apps/console/src/lib/k8s-quantity.test.ts +++ b/packages/system/dashboard/images/console/apps/console/src/lib/k8s-quantity.test.ts @@ -101,6 +101,11 @@ describe("humanizeBytes", () => { expect(humanizeBytes(1023)).toBe("1023B") }) + it("formats kilobytes as Ki without decimals", () => { + expect(humanizeBytes(1024)).toBe("1Ki") + expect(humanizeBytes(512 * 1024)).toBe("512Ki") + }) + it("formats megabytes as Mi without decimals", () => { expect(humanizeBytes(1024 ** 2)).toBe("1Mi") }) diff --git a/packages/system/dashboard/images/console/apps/console/src/lib/k8s-quantity.ts b/packages/system/dashboard/images/console/apps/console/src/lib/k8s-quantity.ts index cee1693ef..8ed3a512e 100644 --- a/packages/system/dashboard/images/console/apps/console/src/lib/k8s-quantity.ts +++ b/packages/system/dashboard/images/console/apps/console/src/lib/k8s-quantity.ts @@ -33,6 +33,7 @@ export function humanizeBytes(bytes: number): string { if (bytes >= 1024 ** 4) return `${(bytes / 1024 ** 4).toFixed(1)}Ti` if (bytes >= 1024 ** 3) return `${(bytes / 1024 ** 3).toFixed(1)}Gi` if (bytes >= 1024 ** 2) return `${(bytes / 1024 ** 2).toFixed(0)}Mi` + if (bytes >= 1024) return `${(bytes / 1024).toFixed(0)}Ki` return `${bytes}B` }