Refresh HiveGrid Cloud reference snapshot

This commit is contained in:
david committed 2026-08-03 15:31:14 +02:00
1 parent 5e99e14772
commit 7f88026f79
5955 files changed
+1177325 -188362

No files matched your search

@@ -1,10 +1,10 @@
import { Link, LoaderFunctionArgs, useLoaderData } from "react-router";
import { Link, LoaderFunctionArgs, useLoaderData, useNavigate } from "react-router";
import { useSearchParams } from "react-router";
import { ready, toFirstStepsChecklistVM, type FirstStepsChecklistVM } from "@hivegrid/view-models";
import { useAppData } from "~/utils/data/useAppData";
import { DashboardLoaderData, loadDashboardData } from "~/utils/data/useDashboardData";
import { getTranslations } from "~/locale/i18next.server";
import { getAppDashboardStats } from "~/utils/services/appDashboardService";
import ProfileBanner from "~/components/app/ProfileBanner";
import { DashboardStats } from "~/components/ui/stats/DashboardStats";
import { getTenantIdFromUrl } from "~/utils/services/.server/urlService";
import { Stat } from "~/application/dtos/stats/Stat";
@@ -29,12 +29,17 @@ import {
type DashboardModuleGateDiagnostic,
} from "~/services/dashboard-registry/gating.server";
import type { DashboardModuleDefinition, DashboardModuleId } from "~/services/dashboard-registry/registry.server";
import { loadDashboardVM, type DashboardVM, type DashboardWidgetVM } from "~/services/dashboard/dashboard.server";
import { loadDashboardVM, type DashboardVM } from "~/services/dashboard/dashboard.server";
import { getFirstStepsChecklist } from "~/utils/services/.server/akP20OnboardingService";
import { DashboardPage } from "~/components/screens/dashboard/DashboardPage";
import { useDashboardStream } from "~/components/screens/dashboard/useDashboardStream";
import { FirstStepsChecklistWidget } from "~/components/screens/onboarding/FirstStepsChecklistWidget";
import UrlUtils from "~/utils/app/UrlUtils";
export { serverTimingHeaders as headers };
const DASHBOARD_READ_PERMISSION = "dashboard.read";
const LEGACY_DASHBOARD_PERMISSION = "app.dashboard.view";
const FIRST_STEPS_CHECKLIST_PERMISSION = "app.onboarding.checklist.update";
export const meta: v2MetaFunction<LoaderData> = ({ data }) => [{ title: data?.title }];
@@ -44,7 +49,7 @@ type LoaderData = DashboardLoaderData & {
modules: DashboardModuleDefinition[];
moduleDiagnostics: DashboardModuleGateDiagnostic[];
dashboard: DashboardVM;
firstStepsChecklist: Awaited<ReturnType<typeof getFirstStepsChecklist>>;
firstStepsChecklist: FirstStepsChecklistVM;
};
function isDashboardModuleVisible(modules: readonly DashboardModuleDefinition[], moduleId: DashboardModuleId) {
@@ -75,12 +80,21 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
if (!tenant) {
throw Response.json({ error: t("app.dashboard.errors.tenantNotFound") }, { status: 404 });
}
const canViewFirstStepsChecklist = getUserHasPermission(appData, FIRST_STEPS_CHECKLIST_PERMISSION);
const firstStepsChecklistRequest = canViewFirstStepsChecklist
? getFirstStepsChecklist({ tenantId, userId: userInfo.userId }).then((checklist) =>
toFirstStepsChecklistVM({
...checklist,
items: checklist.items.map((item) => ({ ...item, href: UrlUtils.currentTenantUrl(params, item.href) })),
})
)
: Promise.resolve<FirstStepsChecklistVM>({ status: "empty" });
const { stats, dashboardData, dashboard, firstStepsChecklist, moduleDecisions } = await time(
promiseHash({
stats: getAppDashboardStats({ t, tenant, gte: PeriodHelper.getGreaterThanOrEqualsFromRequest({ request }) }),
dashboardData: loadDashboardData({ request, params }),
dashboard: loadDashboardVM({ request, params }),
firstStepsChecklist: getFirstStepsChecklist({ tenantId, userId: userInfo.userId }),
firstStepsChecklist: firstStepsChecklistRequest,
moduleDecisions: evaluateDashboardModuleGates({
request,
params,
@@ -110,60 +124,28 @@ export default function DashboardRoute() {
const { t } = useTranslation();
const appData = useAppData();
const data = useLoaderData<LoaderData>();
const navigate = useNavigate();
const [searchParams, setSearchParams] = useSearchParams();
const { snapshot } = useDashboardStream({
streamUrl: data.dashboard.streamUrl,
initialGeneratedAt: data.dashboard.generatedAt,
});
const canViewSummary = isDashboardModuleVisible(data.modules, "summary-stats");
const canViewDashboard =
getUserHasPermission(appData, DASHBOARD_READ_PERMISSION) || getUserHasPermission(appData, LEGACY_DASHBOARD_PERMISSION);
const activeRole = data.dashboard.roles.find((role) => role.role === data.dashboard.activeRole) ?? data.dashboard.roles[0];
const dashboard = snapshot ?? data.dashboard;
const planRequiredDiagnostics = data.moduleDiagnostics.filter((diagnostic) => diagnostic.reason === "plan-required");
return (
<main className="relative z-0 flex-1 pb-8" data-ui-id="ui.dashboard.page">
{/*Page header */}
<div className="bg-background border-border hidden border-b md:block">
<ProfileBanner user={appData.user} />
</div>
<div className="mx-auto grid max-w-5xl gap-5 px-4 py-5 sm:px-8">
{/* The screen renders its own full-bleed page header; only the sibling blocks stay in the centered column. */}
{canViewDashboard ? (
<DashboardPage vm={ready(dashboard)} />
) : null}
<div className="grid w-full gap-5 px-4 py-5 sm:px-6">
{canViewDashboard ? (
<Fragment>
{activeRole ? (
<section className="space-y-4" data-ui-id="ui.dashboard.roleLayouts">
<div className="flex flex-col gap-3 sm:flex-row sm:items-end sm:justify-between">
<div>
<h1 className="text-foreground text-2xl font-semibold">{t("app.dashboard.title")}</h1>
<p className="text-muted-foreground text-sm">{t(activeRole.descriptionKey)}</p>
</div>
<div className="flex flex-wrap gap-2" role="tablist" aria-label={t("app.dashboard.roleSwitcher.label")}>
{data.dashboard.roles.map((role) => (
<Link
key={role.role}
to={`?role=${role.role}`}
role="tab"
aria-selected={role.role === data.dashboard.activeRole}
className={`rounded-md border px-3 py-2 text-sm font-medium ${
role.role === data.dashboard.activeRole
? "border-neutral-900 bg-neutral-900 text-white"
: "border-border bg-background text-foreground hover:bg-secondary"
}`}
data-ui-id={`ui.dashboard.roleSwitcher.${role.role}`}
>
{t(role.nameKey)}
</Link>
))}
</div>
</div>
<div className="text-muted-foreground flex flex-wrap items-center gap-3 text-xs">
<span>{t("app.dashboard.live.enabled")}</span>
<span>{t("app.dashboard.live.lastUpdated", { at: data.dashboard.generatedAt })}</span>
{data.dashboard.canCustomize ? <span>{t("app.dashboard.customize.available")}</span> : null}
</div>
<div className={activeRole.mobileFirst ? "grid gap-3 sm:grid-cols-2 xl:grid-cols-3" : "grid gap-4 md:grid-cols-2 xl:grid-cols-3"}>
{activeRole.widgets.map((widget) => (
<DashboardWidgetCard key={widget.key} widget={widget} />
))}
</div>
</section>
) : null}
{canViewSummary && data.stats.length > 0 && (
<div className="space-y-3 p-1">
<div className="flex items-center justify-between space-x-2">
@@ -193,52 +175,22 @@ export default function DashboardRoute() {
<DashboardStats items={data.stats} />
</div>
)}
{data.moduleDiagnostics.length > 0 && (
{/* Feature-disabled diagnostics still gate the module content but render no notice —
only actionable plan-required diagnostics surface to the user. */}
{planRequiredDiagnostics.length > 0 && (
<div className="space-y-2">
{data.moduleDiagnostics.map((diagnostic) => (
{planRequiredDiagnostics.map((diagnostic) => (
<div key={diagnostic.moduleId} className="border-border bg-secondary rounded-md border border-dashed px-4 py-3 text-sm">
<div className="text-foreground font-medium">
{diagnostic.reason === "plan-required"
? t("app.dashboard.moduleDiagnostics.planRequiredTitle")
: t("app.dashboard.moduleDiagnostics.unavailableTitle")}
</div>
<div className="text-muted-foreground mt-1">
{diagnostic.reason === "plan-required"
? t("app.dashboard.moduleDiagnostics.planRequiredDescription")
: t("app.dashboard.moduleDiagnostics.unavailableDescription")}
</div>
<div className="text-foreground font-medium">{t("app.dashboard.moduleDiagnostics.planRequiredTitle")}</div>
<div className="text-muted-foreground mt-1">{t("app.dashboard.moduleDiagnostics.planRequiredDescription")}</div>
<Link className="text-theme-600 mt-2 inline-flex underline" to={getSafeModuleNoticePath(diagnostic)}>
{diagnostic.reason === "plan-required"
? t("app.dashboard.moduleDiagnostics.viewPlanOptions")
: t("app.dashboard.moduleDiagnostics.learnMore")}
{t("app.dashboard.moduleDiagnostics.viewPlanOptions")}
</Link>
</div>
))}
</div>
)}
{!data.firstStepsChecklist.dismissed && (
<section className="rounded-md border p-4">
<div className="flex flex-wrap items-start justify-between gap-3">
<div>
<h3 className="text-foreground font-medium">{t("onboarding.firstSteps.dashboardTitle")}</h3>
<p className="text-muted-foreground mt-1 text-sm">
{data.firstStepsChecklist.percentComplete === 100
? t("onboarding.firstSteps.dashboardComplete")
: t("onboarding.firstSteps.dashboardProgress", {
completed: data.firstStepsChecklist.completedCount,
total: data.firstStepsChecklist.totalCount,
})}
</p>
</div>
<Link className="text-theme-600 text-sm underline" to="../onboarding/checklist">
{t("onboarding.firstSteps.open")}
</Link>
</div>
<div className="bg-muted mt-4 h-2 overflow-hidden rounded">
<div className="bg-primary h-full" style={{ width: `${data.firstStepsChecklist.percentComplete}%` }} />
</div>
</section>
)}
<FirstStepsChecklistWidget vm={data.firstStepsChecklist} href="../onboarding/checklist" onOpen={(href) => navigate(href)} />
</Fragment>
) : (
<div className="font-medium">{t("app.dashboard.noPermission")}</div>
@@ -248,52 +200,6 @@ export default function DashboardRoute() {
);
}
function DashboardWidgetCard({ widget }: { widget: DashboardWidgetVM }) {
const { t } = useTranslation();
return (
<section
className="border-border bg-background flex min-h-32 flex-col gap-3 rounded-md border px-4 py-4 shadow-sm"
data-ui-id={`ui.dashboard.widget.${widget.key}`}
data-loading={widget.loadingMode}
>
<div>
<h2 className="text-foreground text-sm font-semibold">{t(widget.titleKey)}</h2>
<p className="text-muted-foreground mt-1 text-xs">{t(widget.descriptionKey)}</p>
</div>
{!widget.visible ? (
<p className="text-muted-foreground rounded-md border border-dashed px-3 py-2 text-xs">{t("app.dashboard.widgets.permissionHidden")}</p>
) : widget.metrics.length > 0 ? (
<dl className="grid grid-cols-2 gap-2">
{widget.metrics.map((metric) => (
<div key={metric.labelKey} className="rounded-md bg-secondary px-3 py-2">
<dt className="text-muted-foreground text-xs">{t(metric.labelKey)}</dt>
<dd className="text-foreground mt-1 text-lg font-semibold">{metric.value}</dd>
</div>
))}
</dl>
) : widget.items.length > 0 ? (
<ul className="divide-border divide-y">
{widget.items.map((item) => (
<li key={item.id} className="flex items-center justify-between gap-3 py-2 text-sm">
{item.href ? (
<Link className="text-theme-600 min-w-0 truncate hover:underline" to={item.href}>
{item.labelKey ? t(item.labelKey) : item.label}
</Link>
) : (
<span className="text-foreground min-w-0 truncate">{item.labelKey ? t(item.labelKey) : item.label}</span>
)}
{item.meta ? <span className="text-muted-foreground shrink-0 text-xs">{item.meta}</span> : null}
</li>
))}
</ul>
) : (
<p className="text-muted-foreground rounded-md border border-dashed px-3 py-2 text-xs">{t("app.dashboard.widgets.empty")}</p>
)}
</section>
);
}
export function ErrorBoundary() {
return <ServerError />;
}