Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abbreviate big numbers (2100 -> 2.1K) #52

Merged
merged 2 commits into from Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions app/components/TableCard.tsx
Expand Up @@ -32,6 +32,8 @@
const barChartPercentages = calculateCountPercentages(
countByProperty as CountByProperty,
);

const countFormatter = Intl.NumberFormat("en", { notation: "compact" });
return (
<Card>
<Table>
Expand Down Expand Up @@ -63,12 +65,12 @@
</TableCell>

<TableCell className="text-right w-1/5">
{item[1]}
{countFormatter.format(item[1] as number)}
</TableCell>

{item.length > 2 && (
<TableCell className="text-right w-1/5">
{item[2]}
{countFormatter.format(item[2] as number)}

Check warning on line 73 in app/components/TableCard.tsx

View check run for this annotation

Codecov / codecov/patch

app/components/TableCard.tsx#L73

Added line #L73 was not covered by tests
</TableCell>
)}
</TableRow>
Expand Down
6 changes: 4 additions & 2 deletions app/routes/dashboard.test.tsx
Expand Up @@ -315,7 +315,7 @@ describe("Dashboard route", () => {
const defaultMockedLoaderJson = {
siteId: "example",
sites: ["example"],
views: 100,
views: 2133,
visits: 80,
visitors: 33,
countByPath: [
Expand Down Expand Up @@ -375,7 +375,9 @@ describe("Dashboard route", () => {
await waitFor(() => screen.findByText("Chrome"));

// assert some of the data we mocked actually rendered into the document
expect(screen.getByText("33")).toBeInTheDocument();
expect(screen.getByText("2.1K")).toBeInTheDocument(); // view count
expect(screen.getByText("33")).toBeInTheDocument(); // visitor count

expect(screen.getByText("/about")).toBeInTheDocument();
expect(screen.getByText("Chrome")).toBeInTheDocument();
expect(screen.getByText("google.com")).toBeInTheDocument();
Expand Down
14 changes: 11 additions & 3 deletions app/routes/dashboard.tsx
Expand Up @@ -179,6 +179,8 @@ export default function Dashboard() {

const countByCountryName = convertCountryCodesToNames(data.countByCountry);

const countFormatter = Intl.NumberFormat("en", { notation: "compact" });

return (
<div style={{ fontFamily: "system-ui, sans-serif", lineHeight: "1.8" }}>
<div className="w-full mb-4 flex gap-4">
Expand Down Expand Up @@ -228,17 +230,23 @@ export default function Dashboard() {
<div className="grid grid-cols-3 gap-10 items-end">
<div>
<div className="text-sm sm:text-lg">Views</div>
<div className="text-4xl">{data.views}</div>
<div className="text-4xl">
{countFormatter.format(data.views)}
</div>
</div>
<div>
<div className="text-sm sm:text-lg">Visits</div>
<div className="text-4xl">{data.visits}</div>
<div className="text-4xl">
{countFormatter.format(data.visits)}
</div>
</div>
<div>
<div className="text-sm sm:text-lg">
Visitors
</div>
<div className="text-4xl">{data.visitors}</div>
<div className="text-4xl">
{countFormatter.format(data.visitors)}
</div>
</div>
</div>
</CardContent>
Expand Down