diff --git a/app/components/TableCard.tsx b/app/components/TableCard.tsx index 6ef5dfe..7fffb42 100644 --- a/app/components/TableCard.tsx +++ b/app/components/TableCard.tsx @@ -32,6 +32,8 @@ export default function TableCard({ const barChartPercentages = calculateCountPercentages( countByProperty as CountByProperty, ); + + const countFormatter = Intl.NumberFormat("en", { notation: "compact" }); return ( @@ -63,12 +65,12 @@ export default function TableCard({ - {item[1]} + {countFormatter.format(item[1] as number)} {item.length > 2 && ( - {item[2]} + {countFormatter.format(item[2] as number)} )} diff --git a/app/routes/dashboard.test.tsx b/app/routes/dashboard.test.tsx index 4f97411..e63b95e 100644 --- a/app/routes/dashboard.test.tsx +++ b/app/routes/dashboard.test.tsx @@ -315,7 +315,7 @@ describe("Dashboard route", () => { const defaultMockedLoaderJson = { siteId: "example", sites: ["example"], - views: 100, + views: 2133, visits: 80, visitors: 33, countByPath: [ @@ -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(); diff --git a/app/routes/dashboard.tsx b/app/routes/dashboard.tsx index abb9af2..09e8516 100644 --- a/app/routes/dashboard.tsx +++ b/app/routes/dashboard.tsx @@ -179,6 +179,8 @@ export default function Dashboard() { const countByCountryName = convertCountryCodesToNames(data.countByCountry); + const countFormatter = Intl.NumberFormat("en", { notation: "compact" }); + return (
@@ -228,17 +230,23 @@ export default function Dashboard() {
Views
-
{data.views}
+
+ {countFormatter.format(data.views)} +
Visits
-
{data.visits}
+
+ {countFormatter.format(data.visits)} +
Visitors
-
{data.visitors}
+
+ {countFormatter.format(data.visitors)} +