Track HiveGrid Cloud planning reference

This commit is contained in:
david committed 2026-06-26 20:48:01 +02:00
1 parent b3d5ea6764
commit e341c5938a
5784 files changed
+1104929 -3

No files matched your search

@@ -0,0 +1,55 @@
import "@testing-library/jest-dom";
import { render, screen, within } from "@testing-library/react";
import { MemoryRouter } from "react-router";
import { describe, expect, it, vi } from "vitest";
import { DashboardStats } from "./DashboardStats";
vi.mock("react-i18next", () => ({
useTranslation: () => ({
t: (key: string, options?: Record<string, string>) => {
if (key === "shared.statComparison") {
return `translated from ${options?.[0]}`;
}
return key;
},
}),
}));
function renderDashboardStats() {
return render(
<MemoryRouter>
<DashboardStats
items={[
{
name: "admin.kpi.accounts.name",
hint: "admin.kpi.accounts.hint",
stat: "12",
previousStat: "9",
},
{
name: "admin.kpi.activeUsers.name",
hint: "admin.kpi.activeUsers.hint",
stat: "48",
},
]}
/>
</MemoryRouter>
);
}
describe("DashboardStats", () => {
it("renders translated comparison copy when previousStat is present", () => {
renderDashboardStats();
expect(screen.getByText("translated from 9")).toBeInTheDocument();
});
it("does not render comparison copy for cards without previousStat", () => {
renderDashboardStats();
const activeUsersCard = screen.getByText("admin.kpi.activeUsers.name").closest(".truncate")?.parentElement;
expect(activeUsersCard).not.toBeNull();
expect(within(activeUsersCard as HTMLElement).queryByText(/translated from/i)).not.toBeInTheDocument();
});
});
@@ -0,0 +1,101 @@
import clsx from "clsx";
import { useTranslation } from "react-i18next";
import { Link } from "react-router";
import { Stat } from "~/application/dtos/stats/Stat";
import { StatChange } from "~/application/dtos/stats/StatChange";
import { Fragment } from "react";
import { TrendingUpIcon, TrendingDownIcon } from "~/components/ui/icons/vendor";
interface Props {
items: Stat[];
}
export function DashboardStats({ items }: Props) {
return (
<div>
<div
className={clsx(
"grid grid-cols-2 gap-4 overflow-hidden rounded-lg sm:grid-cols-3",
items.length === 1 && "md:grid-cols-1",
items.length === 2 && "md:grid-cols-2",
items.length === 3 && "md:grid-cols-3",
items.length === 4 && "md:grid-cols-4",
items.length === 5 && "md:grid-cols-4 lg:grid-cols-5",
items.length === 6 && "md:grid-cols-4 lg:grid-cols-6"
)}
>
{items.map((item, idx) => (
<Fragment key={idx}>
{item.path ? (
<Link to={item.path}>
{/* Subframe StatsCard layout: rounded-md, px-4 py-4, hover shadow */}
<DashboardStat
item={item}
className="hover:shadow-lg border-border-default bg-surface-neutral-primary flex cursor-pointer justify-between space-x-1 truncate rounded-md border px-4 py-4"
/>
</Link>
) : (
<DashboardStat className="border-border-default bg-surface-neutral-primary flex justify-between space-x-1 truncate rounded-md border px-4 py-4" item={item} />
)}
</Fragment>
))}
</div>
</div>
);
}
function DashboardStat({ item, loading = false, className }: { item: Stat; loading?: boolean; className?: string }) {
const { t } = useTranslation();
return (
<div key={item.name} className={className}>
<div className="truncate">
{/* Subframe StatsCard typo: body-default label, subtitle value, body-small comparison */}
<div className="text-text-neutral-secondary text-body-default-regular-0 font-body-default-regular-0 flex items-baseline space-x-2">
<div>{t(item.name)}</div>
{item.hint && <div className="text-text-neutral-tertiary text-body-small-regular-0 font-body-small-regular-0 hidden xl:block">({t(item.hint)})</div>}
</div>
<div className="text-text-neutral-primary text-subtitle-0 font-subtitle-0 flex items-baseline space-x-2">
<div>{loading ? "..." : item.stat}</div>
{item.previousStat !== undefined && (
<span className="text-text-neutral-tertiary text-body-small-regular-0 font-body-small-regular-0 ml-2 hidden xl:block">
{!loading && <span>{t("shared.statComparison", { 0: item.previousStat })}</span>}
</span>
)}
</div>
</div>
{item.changeType === StatChange.Increase ? (
<div className="mt-1 flex shrink-0 gap-1 truncate text-green-700">
{loading ? (
"..."
) : (
<>
<TrendingUpIcon className="h-4 w-4" />
<div className="text-body-small-regular-0 font-body-small-regular-0 flex gap-2">
<span className="font-medium">
<div>{item.change}</div>
</span>
</div>
</>
)}
</div>
) : item.changeType === StatChange.Decrease ? (
<div className="mt-1 flex gap-1 text-red-600">
{loading ? (
"..."
) : (
<>
<TrendingDownIcon className="h-4 w-4" />
<p className="text-body-small-regular-0 font-body-small-regular-0 flex gap-2">
<span className="font-medium">
<div>{item.change}</div>
</span>
</p>
</>
)}
</div>
) : null}
</div>
);
}
@@ -0,0 +1,83 @@
import { useNavigation } from "react-router";
import clsx from "clsx";
import { useTranslation } from "react-i18next";
import { Stat } from "~/application/dtos/stats/Stat";
import { StatChange } from "~/application/dtos/stats/StatChange";
import { ArrowUpIcon, ArrowDownIcon } from "~/components/ui/icons/vendor";
interface Props {
items: Stat[];
}
function getStatChangeScreenReaderKey(changeType: StatChange | undefined) {
if (changeType === StatChange.Increase) {
return "components.stats.change.increasedBy";
}
if (changeType === StatChange.Decrease) {
return "components.stats.change.decreasedBy";
}
return "components.stats.change.noChange";
}
export function EntitiesStats({ items }: Props) {
const { t } = useTranslation();
const navigation = useNavigation();
const loading = navigation.state === "loading";
return (
<div>
<h3 className="text-text-neutral-primary leading-4 font-medium">{t("app.shared.periods.LAST_30_DAYS")}</h3>
<dl
className={clsx(
// Subframe StatsCard layout: rounded-md container (divided-panel structure kept)
"divide-border-default bg-surface-neutral-primary mt-3 grid grid-cols-1 divide-y overflow-hidden rounded-md shadow-xs md:divide-x md:divide-y-0",
items.length === 1 && "md:grid-cols-1",
items.length === 2 && "md:grid-cols-2",
items.length === 3 && "md:grid-cols-3",
items.length === 4 && "md:grid-cols-4",
items.length === 5 && "md:grid-cols-5",
items.length === 6 && "md:grid-cols-6"
)}
>
{items.map((item) => (
// Subframe StatsCard layout: px-4 py-4 cell padding, body-default label, subtitle value
<span key={item.name} className="px-4 py-4">
<dt className="text-text-neutral-primary text-body-default-regular-0 font-body-default-regular-0 flex items-baseline space-x-1">
<div>{t(item.name)}</div>
{item.hint && <div className="text-text-neutral-tertiary text-body-small-regular-0 font-body-small-regular-0 hidden xl:block">({t(item.hint)})</div>}
</dt>
<dd className="mt-1 flex items-baseline justify-between md:block lg:flex">
<div className="text-text-neutral-primary text-subtitle-0 font-subtitle-0 flex items-baseline">
<div>{loading ? "..." : item.stat}</div>
<span className="text-text-neutral-tertiary text-body-small-regular-0 font-body-small-regular-0 ml-2 hidden xl:block">
{!loading && item.previousStat !== undefined && <span>{t("shared.statComparison", { 0: item.previousStat })}</span>}
</span>
</div>
{!loading && (
<div
className={clsx(
item.changeType === StatChange.Increase && "text-teal-800",
item.changeType === StatChange.Decrease && "text-rose-800",
item.changeType === StatChange.Equal && "text-text-neutral-tertiary",
"text-body-small-regular-0 font-body-small-regular-0 inline-flex items-baseline rounded-full px-2.5 py-0.5 md:mt-2 lg:mt-0"
)}
>
{item.changeType === StatChange.Increase ? (
<ArrowUpIcon className="mr-0.5 -ml-1 h-5 w-5 shrink-0 self-center text-teal-500" />
) : item.changeType === StatChange.Decrease ? (
<ArrowDownIcon className="mr-0.5 -ml-1 h-5 w-5 shrink-0 self-center text-rose-500" />
) : (
<div className="text-text-neutral-tertiary">-</div>
)}
<span className="sr-only">{t(getStatChangeScreenReaderKey(item.changeType))}</span>
{item.change}
</div>
)}
</dd>
</span>
))}
</dl>
</div>
);
}
@@ -0,0 +1,33 @@
import clsx from "clsx";
interface Props {
items: {
name: string;
stat: string;
hint?: string;
}[];
}
export default function SimpleStats({ items }: Props) {
return (
<div>
<dl
className={clsx(
"grid grid-cols-1 gap-3",
items.length === 1 && "md:grid-cols-1",
items.length === 2 && "grid-cols-2",
items.length === 3 && "md:grid-cols-3"
)}
>
{items.map((item) => (
// Subframe StatsCard layout: rounded-md, px-4 py-4, gap-3, body-default label / subtitle value
<div key={item.name} className="bg-surface-neutral-primary flex flex-col gap-3 overflow-hidden rounded-md px-4 py-4 shadow-xs">
<dt className="text-text-neutral-secondary text-body-default-regular-0 font-body-default-regular-0 truncate">{item.name}</dt>
<dd className="text-text-neutral-primary text-subtitle-0 font-subtitle-0 truncate">
{item.stat} {item.hint && <span className="text-text-neutral-tertiary text-body-small-regular-0 font-body-small-regular-0">{item.hint}</span>}
</dd>
</div>
))}
</dl>
</div>
);
}