183 lines
6.9 KiB
TypeScript
183 lines
6.9 KiB
TypeScript
import { buildSystemHealthVM, type SystemHealthData, type SystemHealthService } from "@hivegrid/view-models";
|
|
import {
|
|
FeatherAlertTriangle,
|
|
FeatherCheckCircle,
|
|
FeatherDatabase,
|
|
FeatherExternalLink,
|
|
FeatherHardDrive,
|
|
FeatherHelpCircle,
|
|
FeatherRadioTower,
|
|
FeatherServer,
|
|
FeatherShieldCheck,
|
|
} from "@subframe/core";
|
|
import { Link, LoaderFunctionArgs, MetaFunction, useLoaderData } from "react-router";
|
|
import { useTranslation } from "react-i18next";
|
|
import { AdminPageHeader } from "~/components/screens/admin/AdminPageHeader";
|
|
import { getTranslations } from "~/locale/i18next.server";
|
|
import { getSystemHealthSnapshot } from "~/services/admin/system-health.server";
|
|
import { ADMIN_AREA_ACCESS } from "~/services/admin/admin-access-contract";
|
|
import { verifyUserHasPermission } from "~/utils/helpers/.server/PermissionsService";
|
|
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
|
import { BannerAlert } from "~/ui/components/BannerAlert";
|
|
import { Button } from "~/ui/components/Button";
|
|
import { Card } from "~/ui/components/Card";
|
|
import { EmptyState } from "~/ui/components/EmptyState";
|
|
import { StatsCard } from "~/ui/components/StatsCard";
|
|
|
|
type LoaderData = {
|
|
title: string;
|
|
vm: ReturnType<typeof buildSystemHealthVM>;
|
|
};
|
|
|
|
export const meta: MetaFunction<typeof loader> = ({ data }) => [{ title: data?.title }];
|
|
|
|
export const loader = async ({ request }: LoaderFunctionArgs) => {
|
|
await verifyUserHasPermission(request, ADMIN_AREA_ACCESS.system);
|
|
const { t } = await getTranslations(request);
|
|
const snapshot = await getSystemHealthSnapshot();
|
|
return {
|
|
title: `${t("admin.system.title")} | ${process.env.APP_NAME}`,
|
|
vm: buildSystemHealthVM(snapshot),
|
|
} satisfies LoaderData;
|
|
};
|
|
|
|
export default function AdminSystemRoute() {
|
|
const { t } = useTranslation();
|
|
const data = useLoaderData<LoaderData>();
|
|
|
|
return (
|
|
<div className="flex w-full flex-col">
|
|
<AdminPageHeader title={t("admin.system.title")} description={t("admin.system.description")} />
|
|
<div className="mobile:px-4 flex w-full flex-col items-start gap-4 px-6 py-6">
|
|
{data.vm.status === "ready" ? <SystemHealthPage data={data.vm.data} /> : <SystemHealthEmpty />}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function SystemHealthPage({ data }: { data: SystemHealthData }) {
|
|
const { t } = useTranslation();
|
|
|
|
return (
|
|
<>
|
|
<Card variant="neutral">
|
|
<div className="flex w-full flex-wrap items-center justify-between gap-3">
|
|
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-secondary">
|
|
{t("admin.system.deployLine", {
|
|
environment: data.deploy.environment,
|
|
release: data.deploy.release,
|
|
nodeEnv: data.deploy.nodeEnv,
|
|
})}
|
|
</span>
|
|
<BadgeFeedback farbe={statusTone(data.overallStatus)}>{t(data.overallLabelKey)}</BadgeFeedback>
|
|
</div>
|
|
</Card>
|
|
|
|
<div className="mobile:grid-cols-1 grid w-full grid-cols-5 gap-4 md:grid-cols-2 xl:grid-cols-5">
|
|
<StatsCard
|
|
label={t("admin.system.summary.ok")}
|
|
value={data.summary.ok}
|
|
trend="positive"
|
|
percentage=""
|
|
comparisonText=""
|
|
icon={<FeatherCheckCircle />}
|
|
/>
|
|
<StatsCard
|
|
label={t("admin.system.summary.warning")}
|
|
value={data.summary.warning}
|
|
trend={data.summary.warning ? "negative" : "positive"}
|
|
percentage=""
|
|
comparisonText=""
|
|
icon={<FeatherAlertTriangle />}
|
|
/>
|
|
<StatsCard
|
|
label={t("admin.system.summary.critical")}
|
|
value={data.summary.critical}
|
|
trend={data.summary.critical ? "negative" : "positive"}
|
|
percentage=""
|
|
comparisonText=""
|
|
icon={<FeatherAlertTriangle />}
|
|
/>
|
|
<StatsCard
|
|
label={t("admin.system.summary.unknown")}
|
|
value={data.summary.unknown}
|
|
trend="neutral"
|
|
percentage=""
|
|
comparisonText=""
|
|
icon={<FeatherHelpCircle />}
|
|
/>
|
|
<StatsCard
|
|
label={t("admin.system.summary.total")}
|
|
value={data.summary.total}
|
|
trend="neutral"
|
|
percentage=""
|
|
comparisonText=""
|
|
icon={<FeatherServer />}
|
|
/>
|
|
</div>
|
|
|
|
{data.summary.critical > 0 ? (
|
|
<BannerAlert type="error" fillContainer>
|
|
{t("admin.system.incident.title")} — {t("admin.system.incident.body")}
|
|
</BannerAlert>
|
|
) : null}
|
|
|
|
<div className="mobile:grid-cols-1 grid w-full gap-4 lg:grid-cols-2 xl:grid-cols-3">
|
|
{data.services.map((service) => (
|
|
<ServiceCard key={service.id} service={service} />
|
|
))}
|
|
</div>
|
|
</>
|
|
);
|
|
}
|
|
|
|
function ServiceCard({ service }: { service: SystemHealthService }) {
|
|
const { t } = useTranslation();
|
|
const detail = service.detailKey ? t(service.detailKey, { value: service.detailValue }) : service.detailValue;
|
|
|
|
return (
|
|
<Card>
|
|
<div className="flex w-full items-start justify-between gap-4">
|
|
<div className="flex min-w-0 items-start gap-3">
|
|
<span className="text-heading- font-heading- text-icon-neutral-tertiary">{categoryIcon(service.category)}</span>
|
|
<div className="flex min-w-0 flex-col items-start">
|
|
<span className="text-body-large-0 font-body-large-0 text-text-neutral-primary truncate">{t(service.labelKey)}</span>
|
|
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">{t(service.categoryLabelKey)}</span>
|
|
</div>
|
|
</div>
|
|
<BadgeFeedback farbe={statusTone(service.status)} size="small">
|
|
{t(service.statusLabelKey)}
|
|
</BadgeFeedback>
|
|
</div>
|
|
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-secondary min-h-10 w-full">{detail}</span>
|
|
{service.href ? (
|
|
<Link to={service.href}>
|
|
<Button variant="tertiary" size="small" iconRight={<FeatherExternalLink />}>
|
|
{t("admin.system.actions.openDetail")}
|
|
</Button>
|
|
</Link>
|
|
) : null}
|
|
</Card>
|
|
);
|
|
}
|
|
|
|
function SystemHealthEmpty() {
|
|
const { t } = useTranslation();
|
|
return <EmptyState outlined title={t("admin.system.empty.headline")} body={t("admin.system.empty.body")} />;
|
|
}
|
|
|
|
function categoryIcon(category: SystemHealthService["category"]) {
|
|
if (category === "database") return <FeatherDatabase />;
|
|
if (category === "queue") return <FeatherRadioTower />;
|
|
if (category === "storage") return <FeatherHardDrive />;
|
|
if (category === "observability") return <FeatherShieldCheck />;
|
|
return <FeatherServer />;
|
|
}
|
|
|
|
function statusTone(status: SystemHealthService["status"]): "subtle-positive" | "subtle-warning" | "subtle-negative" | "subtle-neutral" {
|
|
if (status === "ok") return "subtle-positive";
|
|
if (status === "warning") return "subtle-warning";
|
|
if (status === "critical") return "subtle-negative";
|
|
return "subtle-neutral";
|
|
}
|