Skip to content
TypeScript

fix(web): show rounded diff counts as 1m instead of 1000k (#23723)

Victor Vogel456892da72ab
diff --git a/apps/web/src/components/chat/DiffStatLabel.test.ts b/apps/web/src/components/chat/DiffStatLabel.test.ts
new file mode 100644
index 00000000000..2ea8bcdb835
--- /dev/null
+++ b/apps/web/src/components/chat/DiffStatLabel.test.ts
@@ -0,0 +1,12 @@
+import { describe, expect, it } from "vite-plus/test";
+
+import { formatCompactDiffCount } from "./DiffStatLabel";
+
+describe("formatCompactDiffCount", () => {
+ it("promotes counts when rounding reaches the next suffix", () => {
+ expect(formatCompactDiffCount(999_499)).toBe("999k");
+ expect(formatCompactDiffCount(999_500)).toBe("1m");
+ expect(formatCompactDiffCount(999_499_999)).toBe("999m");
+ expect(formatCompactDiffCount(999_500_000)).toBe("1b");
+ });
+});
diff --git a/apps/web/src/components/chat/DiffStatLabel.tsx b/apps/web/src/components/chat/DiffStatLabel.tsx
index 9e4c0f7cef5..2b60c35723a 100644
--- a/apps/web/src/components/chat/DiffStatLabel.tsx
+++ b/apps/web/src/components/chat/DiffStatLabel.tsx
@@ -5,13 +5,13 @@ export function hasNonZeroStat(stat: { additions: number; deletions: number }):
return stat.additions > 0 || stat.deletions > 0;
}
-function formatCompactDiffCount(value: number): string {
+export function formatCompactDiffCount(value: number): string {
if (value < 1000) return String(value);
- if (value < 1_000_000) {
+ if (value < 999_500) {
const k = value / 1000;
return `${k < 10 ? k.toFixed(1).replace(/\.0$/, "") : Math.round(k)}k`;
}
- if (value < 1_000_000_000) {
+ if (value < 999_500_000) {
const m = value / 1_000_000;
return `${m < 10 ? m.toFixed(1).replace(/\.0$/, "") : Math.round(m)}m`;
}