import { buildDeployAdminVM, type DeployAdminData, type DeploySignal, type MigrationState } from "@hivegrid/view-models"; import { FeatherRocket, FeatherTableProperties } from "@subframe/core"; import { 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 { getDeployAdminSnapshot } from "~/services/admin/deploy-admin.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 { Card } from "~/ui/components/Card"; import { EmptyState } from "~/ui/components/EmptyState"; import { StatsCard } from "~/ui/components/StatsCard"; import { Table } from "~/ui/components/Table"; type LoaderData = { title: string; vm: ReturnType; }; export const meta: MetaFunction = ({ data }) => [{ title: data?.title }]; export const loader = async ({ request }: LoaderFunctionArgs) => { await verifyUserHasPermission(request, ADMIN_AREA_ACCESS.deploys); const { t } = await getTranslations(request); const snapshot = await getDeployAdminSnapshot(); return { title: `${t("admin.deploys.title")} | ${process.env.APP_NAME}`, vm: buildDeployAdminVM(snapshot), } satisfies LoaderData; }; export default function AdminDeploysRoute() { const { t } = useTranslation(); const data = useLoaderData(); return (
{data.vm.status === "ready" ? : }
); } function DeploysPage({ data }: { data: DeployAdminData }) { const { t } = useTranslation(); return ( <>
{t("admin.deploys.deployLine", { environment: data.metadata.environment, release: data.metadata.release, branch: data.metadata.branch, })} {t(data.overallLabelKey)}
{data.signals.map((signal) => ( ))}
); } function SignalCard({ signal }: { signal: DeploySignal }) { const { t } = useTranslation(); return ( } /> ); } function VersionCard({ data }: { data: DeployAdminData }) { const { t } = useTranslation(); const rows = [ ["admin.deploys.fields.environment", data.metadata.environment], ["admin.deploys.fields.nodeEnv", data.metadata.nodeEnv], ["admin.deploys.fields.release", data.metadata.release], ["admin.deploys.fields.revision", data.metadata.revision], ["admin.deploys.fields.branch", data.metadata.branch], ["admin.deploys.fields.image", data.metadata.image], ["admin.deploys.fields.buildTime", data.metadata.buildTime], ] as const; return (
{t("admin.deploys.version.title")} {t("admin.deploys.version.description")}
{/* `min-w-0` keeps the grid from growing past the card: without it a 40-char commit hash pushed the value column wider than its container and ran over the neighbouring cards (admin audit 2026-07-26, P0-07). Long hashes are additionally shortened for reading, with the full value on hover. */}
{rows.map(([labelKey, value]) => (
{t(labelKey)}
{shortenRevision(value)}
))}
); } function MigrationCard({ data }: { data: DeployAdminData }) { const { t } = useTranslation(); return (
{t("admin.deploys.migrations.title")} {t("admin.deploys.migrations.description")}
0 || data.migrationSummary.failed > 0 ? "subtle-warning" : "subtle-positive"} size="small"> {t("admin.deploys.migrations.summary", data.migrationSummary)}
{t("admin.deploys.migrations.name")}{t("admin.deploys.migrations.state")}{t("admin.deploys.migrations.appliedAt")} } > {data.migrations.map((migration) => ( {migration.name} {t(`admin.deploys.migrationState.${migration.state}`)} {migration.appliedAt ?? t("shared.notSet")} ))}
); } function DeploysEmpty() { const { t } = useTranslation(); return ; } const FULL_COMMIT_HASH = /^[0-9a-f]{13,}$/iu; const SHORT_HASH_LENGTH = 12; /** * Shortens a full commit hash to its readable prefix. Anything that is not a * long hex string (image tags, branch names, `local`) is left untouched, and the * complete value stays available through the cell's `title`. */ export function shortenRevision(value: string): string { return FULL_COMMIT_HASH.test(value) ? value.slice(0, SHORT_HASH_LENGTH) : value; } function statusTone(status: DeploySignal["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"; } function migrationTone(state: MigrationState): "subtle-positive" | "subtle-warning" | "subtle-negative" | "subtle-neutral" { if (state === "applied") return "subtle-positive"; if (state === "pending") return "subtle-warning"; if (state === "failed" || state === "rolledBack") return "subtle-negative"; return "subtle-neutral"; }