Update hivegrid-cloud reference to latest main
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e98d38e716
commit
7b21524c86
3781 files changed
+373484
-225607
No files matched your search
+126
-8
@@ -19,7 +19,6 @@ import { getTenant } from "~/utils/db/tenants.db.server";
|
||||
import { Fragment } from "react";
|
||||
import { loadAppData } from "~/utils/data/.server/appData";
|
||||
import { getUserHasPermission } from "~/utils/helpers/PermissionsHelper";
|
||||
import { verifyUserHasPermission } from "~/utils/helpers/.server/PermissionsService";
|
||||
import { requireAuth } from "~/utils/loaders.middleware";
|
||||
import { v2MetaFunction } from "~/utils/compat/v2MetaFunction";
|
||||
import { appTenantPlanRequiredPath } from "~/utils/app/AppTenantStatusPaths";
|
||||
@@ -30,8 +29,13 @@ 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 { getFirstStepsChecklist } from "~/utils/services/.server/akP20OnboardingService";
|
||||
export { serverTimingHeaders as headers };
|
||||
|
||||
const DASHBOARD_READ_PERMISSION = "dashboard.read";
|
||||
const LEGACY_DASHBOARD_PERMISSION = "app.dashboard.view";
|
||||
|
||||
export const meta: v2MetaFunction<LoaderData> = ({ data }) => [{ title: data?.title }];
|
||||
|
||||
type LoaderData = DashboardLoaderData & {
|
||||
@@ -39,6 +43,8 @@ type LoaderData = DashboardLoaderData & {
|
||||
stats: Stat[];
|
||||
modules: DashboardModuleDefinition[];
|
||||
moduleDiagnostics: DashboardModuleGateDiagnostic[];
|
||||
dashboard: DashboardVM;
|
||||
firstStepsChecklist: Awaited<ReturnType<typeof getFirstStepsChecklist>>;
|
||||
};
|
||||
|
||||
function isDashboardModuleVisible(modules: readonly DashboardModuleDefinition[], moduleId: DashboardModuleId) {
|
||||
@@ -54,7 +60,7 @@ function getSafeModuleNoticePath(diagnostic: DashboardModuleGateDiagnostic) {
|
||||
}
|
||||
|
||||
export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
||||
await requireAuth({ request, params });
|
||||
const userInfo = await requireAuth({ request, params });
|
||||
const { time, getServerTimingHeader } = await createMetrics({ request, params }, "app.$tenant.dashboard");
|
||||
let { t } = await getTranslations(request);
|
||||
const { tenantId, appData } = await time(
|
||||
@@ -69,12 +75,12 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
||||
if (!tenant) {
|
||||
throw Response.json({ error: t("app.dashboard.errors.tenantNotFound") }, { status: 404 });
|
||||
}
|
||||
await verifyUserHasPermission(request, "app.dashboard.view", tenantId);
|
||||
|
||||
const { stats, dashboardData, moduleDecisions } = await time(
|
||||
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 }),
|
||||
moduleDecisions: evaluateDashboardModuleGates({
|
||||
request,
|
||||
params,
|
||||
@@ -94,6 +100,8 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
||||
stats,
|
||||
modules: getVisibleDashboardModules(moduleDecisions),
|
||||
moduleDiagnostics: getDashboardModuleDiagnostics(moduleDecisions),
|
||||
dashboard,
|
||||
firstStepsChecklist,
|
||||
};
|
||||
return Response.json(data, { headers: getServerTimingHeader() });
|
||||
};
|
||||
@@ -104,6 +112,9 @@ export default function DashboardRoute() {
|
||||
const data = useLoaderData<LoaderData>();
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
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];
|
||||
|
||||
return (
|
||||
<main className="relative z-0 flex-1 pb-8" data-ui-id="ui.dashboard.page">
|
||||
@@ -113,15 +124,53 @@ export default function DashboardRoute() {
|
||||
</div>
|
||||
|
||||
<div className="mx-auto grid max-w-5xl gap-5 px-4 py-5 sm:px-8">
|
||||
{getUserHasPermission(appData, "app.dashboard.view") ? (
|
||||
{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 truncate p-1">
|
||||
<div className="space-y-3 p-1">
|
||||
<div className="flex items-center justify-between space-x-2">
|
||||
<h3 className="text-foreground grow leading-4 font-medium">{t("app.dashboard.summary")}</h3>
|
||||
<div>
|
||||
<InputSelect
|
||||
className="w-44"
|
||||
className="w-48 shrink-0"
|
||||
name="period"
|
||||
value={searchParams.get("period")?.toString() ?? defaultPeriodFilter}
|
||||
options={PeriodFilters.map((f) => {
|
||||
@@ -167,6 +216,29 @@ export default function DashboardRoute() {
|
||||
))}
|
||||
</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>
|
||||
)}
|
||||
</Fragment>
|
||||
) : (
|
||||
<div className="font-medium">{t("app.dashboard.noPermission")}</div>
|
||||
@@ -176,6 +248,52 @@ 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 />;
|
||||
}
|
||||
Reference in new issue
Block a user