Skip to content

Commit 456892d

Browse files
only21milcodexmaria-rcks
authored
fix(web): show rounded diff counts as 1m instead of 1000k (pingdotgg#23723)
Co-authored-by: GPT-6.1 Sol <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent 67afdd5 commit 456892d

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { describe, expect, it } from "vite-plus/test";
2+
3+
import { formatCompactDiffCount } from "./DiffStatLabel";
4+
5+
describe("formatCompactDiffCount", () => {
6+
it("promotes counts when rounding reaches the next suffix", () => {
7+
expect(formatCompactDiffCount(999_499)).toBe("999k");
8+
expect(formatCompactDiffCount(999_500)).toBe("1m");
9+
expect(formatCompactDiffCount(999_499_999)).toBe("999m");
10+
expect(formatCompactDiffCount(999_500_000)).toBe("1b");
11+
});
12+
});

‎apps/web/src/components/chat/DiffStatLabel.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ export function hasNonZeroStat(stat: { additions: number; deletions: number }):
55
return stat.additions > 0 || stat.deletions > 0;
66
}
77

8-
function formatCompactDiffCount(value: number): string {
8+
export function formatCompactDiffCount(value: number): string {
99
if (value < 1000) return String(value);
10-
if (value < 1_000_000) {
10+
if (value < 999_500) {
1111
const k = value / 1000;
1212
return `${k < 10 ? k.toFixed(1).replace(/\.0$/, "") : Math.round(k)}k`;
1313
}
14-
if (value < 1_000_000_000) {
14+
if (value < 999_500_000) {
1515
const m = value / 1_000_000;
1616
return `${m < 10 ? m.toFixed(1).replace(/\.0$/, "") : Math.round(m)}m`;
1717
}

0 commit comments

Comments
 (0)