Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
@@ -1,74 +1,218 @@
|
||||
import { LoaderFunctionArgs, useLoaderData } from "react-router";
|
||||
import { Link } from "react-router";
|
||||
import { Fragment } from "react";
|
||||
import { buildApiAdminVM, type ApiAdminMetricInput, type ApiAdminData } from "@hivegrid/view-models";
|
||||
import { FeatherActivity, FeatherArrowRight, FeatherKey, FeatherRadioTower, FeatherShieldAlert, FeatherUsers } from "@subframe/core";
|
||||
import type React from "react";
|
||||
import { Link, LoaderFunctionArgs, MetaFunction, useLoaderData } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FilterablePropertyDto } from "~/application/dtos/data/FilterablePropertyDto";
|
||||
import ErrorBanner from "~/components/ui/banners/ErrorBanner";
|
||||
import ServerError from "~/components/ui/errors/ServerError";
|
||||
import EditPageLayout from "~/components/ui/layouts/EditPageLayout";
|
||||
import ApiKeyLogsSummary from "~/modules/api/components/ApiKeyLogsSummary";
|
||||
import { ApiCallSummaryDto } from "~/modules/api/dtos/ApiCallSummaryDto";
|
||||
import ApiKeyLogService from "~/modules/api/services/ApiKeyLogService";
|
||||
import { verifyUserHasPermission } from "~/utils/helpers/.server/PermissionsService";
|
||||
import ServerError from "~/components/ui/errors/ServerError";
|
||||
import { getTranslations } from "~/locale/i18next.server";
|
||||
import { useLocaleFormatters } from "~/locale/format";
|
||||
import { getApiAdminSnapshot } from "~/services/admin/api-admin.server";
|
||||
import { adminPath } from "~/utils/app/CanonicalUrlUtils";
|
||||
import { verifyUserHasPermission } from "~/utils/helpers/.server/PermissionsService";
|
||||
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
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 =
|
||||
| { error: string }
|
||||
| {
|
||||
items: ApiCallSummaryDto[];
|
||||
allTenants: { id: string; name: string; slug: string }[];
|
||||
filterableProperties: FilterablePropertyDto[];
|
||||
};
|
||||
export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
||||
await verifyUserHasPermission(request, "admin.apiKeys.view");
|
||||
try {
|
||||
const { items, allTenants, filterableProperties } = await ApiKeyLogService.getSummary({ request, params });
|
||||
const data: LoaderData = {
|
||||
items,
|
||||
allTenants,
|
||||
filterableProperties,
|
||||
};
|
||||
return data;
|
||||
} catch (e: any) {
|
||||
return Response.json({ error: e.message }, { status: 400 });
|
||||
}
|
||||
type LoaderData = {
|
||||
title: string;
|
||||
vm: ReturnType<typeof buildApiAdminVM>;
|
||||
};
|
||||
|
||||
export default function () {
|
||||
export const meta: MetaFunction<typeof loader> = ({ data }) => [{ title: data?.title }];
|
||||
|
||||
export const loader = async ({ request }: LoaderFunctionArgs) => {
|
||||
await verifyUserHasPermission(request, "admin.apiKeys.view");
|
||||
const { t } = await getTranslations(request);
|
||||
const snapshot = await getApiAdminSnapshot({ platformLeadVisibility: null });
|
||||
return {
|
||||
title: `${t("admin.apiAdmin.title")} | ${process.env.APP_NAME}`,
|
||||
vm: buildApiAdminVM(snapshot),
|
||||
} satisfies LoaderData;
|
||||
};
|
||||
|
||||
export default function AdminApiIndexRoute() {
|
||||
const { t } = useTranslation();
|
||||
const data = useLoaderData<LoaderData>();
|
||||
|
||||
return (
|
||||
<EditPageLayout
|
||||
tabs={[
|
||||
{
|
||||
name: t("shared.overview"),
|
||||
routePath: adminPath("api", { mode: "host-aware" }),
|
||||
},
|
||||
{
|
||||
name: t("models.apiCall.plural"),
|
||||
routePath: adminPath("api/logs", { mode: "host-aware" }),
|
||||
},
|
||||
{
|
||||
name: t("models.apiKey.plural"),
|
||||
routePath: adminPath("api/keys", { mode: "host-aware" }),
|
||||
},
|
||||
]}
|
||||
>
|
||||
{"error" in data ? (
|
||||
<ErrorBanner title={t(data.error)}>
|
||||
<Link to="." className="underline">
|
||||
{t("shared.clickHereToTryAgain")}
|
||||
</Link>
|
||||
</ErrorBanner>
|
||||
) : (
|
||||
<Fragment>
|
||||
<ApiKeyLogsSummary data={data} />
|
||||
</Fragment>
|
||||
)}
|
||||
<EditPageLayout title={t("shared.overview")} tabs={apiTabs(t)} fullWidth>
|
||||
{data.vm.status === "ready" ? <ApiAdminPage data={data.vm.data} /> : <EmptyApiAdmin />}
|
||||
</EditPageLayout>
|
||||
);
|
||||
}
|
||||
|
||||
export function apiTabs(t: (key: string) => string) {
|
||||
return [
|
||||
{ name: t("shared.overview"), routePath: adminPath("api", { mode: "host-aware" }) },
|
||||
{ name: t("models.apiCall.plural"), routePath: adminPath("api/logs", { mode: "host-aware" }) },
|
||||
{ name: t("models.apiKey.plural"), routePath: adminPath("api/keys", { mode: "host-aware" }) },
|
||||
{ name: t("admin.apiAdmin.tabs.clients"), routePath: adminPath("api/clients", { mode: "host-aware" }) },
|
||||
{ name: t("admin.apiAdmin.tabs.inbound"), routePath: adminPath("api/inbound-registrations", { mode: "host-aware" }) },
|
||||
];
|
||||
}
|
||||
|
||||
function ApiAdminPage({ data }: { data: ApiAdminData }) {
|
||||
const { t } = useTranslation();
|
||||
const format = useLocaleFormatters();
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col items-start gap-4">
|
||||
<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.apiAdmin.publicApiHint")}</span>
|
||||
{data.hasInboundAttention ? (
|
||||
<BadgeFeedback farbe="subtle-warning">{t("admin.apiAdmin.inboundAttention")}</BadgeFeedback>
|
||||
) : (
|
||||
<BadgeFeedback farbe="subtle-positive">{t("admin.apiAdmin.inboundHealthy")}</BadgeFeedback>
|
||||
)}
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<div className="mobile:grid-cols-1 grid w-full gap-4 md:grid-cols-2 xl:grid-cols-5">
|
||||
{data.metrics.map((metric) => (
|
||||
<MetricCard key={metric.id} metric={metric} />
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="mobile:grid-cols-1 grid w-full gap-4 xl:grid-cols-[minmax(0,1.2fr)_minmax(320px,0.8fr)]">
|
||||
<Card>
|
||||
<div className="flex w-full items-start justify-between gap-4">
|
||||
<div className="flex min-w-0 flex-col items-start">
|
||||
<span className="text-body-large-0 font-body-large-0 text-text-neutral-primary">{t("admin.apiAdmin.consumers.title")}</span>
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
||||
{t("admin.apiAdmin.consumers.description")}
|
||||
</span>
|
||||
</div>
|
||||
<Link to={adminPath("api/clients", { mode: "host-aware" })}>
|
||||
<Button variant="tertiary" size="small" iconRight={<FeatherArrowRight />}>
|
||||
{t("shared.viewAll")}
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
<Table
|
||||
header={
|
||||
<Table.HeaderRow>
|
||||
<Table.HeaderCell>{t("models.tenant.object")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("admin.apiAdmin.consumers.keys")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("admin.apiAdmin.consumers.activeKeys")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("admin.apiAdmin.consumers.lastKey")}</Table.HeaderCell>
|
||||
</Table.HeaderRow>
|
||||
}
|
||||
>
|
||||
{data.consumers.slice(0, 8).map((consumer) => (
|
||||
<Table.Row key={consumer.id}>
|
||||
<Table.Cell>
|
||||
<div className="flex min-w-0 flex-col items-start">
|
||||
<Link
|
||||
className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-primary truncate hover:underline"
|
||||
to={adminPath(`accounts/${consumer.id}`, { mode: "host-aware" })}
|
||||
>
|
||||
{consumer.name}
|
||||
</Link>
|
||||
<span className="text-body-extra-small-regular-150 font-body-extra-small-regular-150 text-text-neutral-tertiary">/{consumer.slug}</span>
|
||||
</div>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-primary">{format.number(consumer.keyCount)}</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-primary">
|
||||
{format.number(consumer.activeKeyCount)}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
||||
{consumer.lastKeyCreatedAt ? format.dateTime(consumer.lastKeyCreatedAt) : t("shared.notSet")}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
))}
|
||||
</Table>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<div className="flex w-full items-start justify-between gap-4">
|
||||
<div className="flex min-w-0 flex-col items-start">
|
||||
<span className="text-body-large-0 font-body-large-0 text-text-neutral-primary">{t("admin.apiAdmin.inbound.title")}</span>
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
||||
{t("admin.apiAdmin.inbound.description")}
|
||||
</span>
|
||||
</div>
|
||||
<Link to={adminPath("api/inbound-registrations", { mode: "host-aware" })}>
|
||||
<Button variant="tertiary" size="small" iconRight={<FeatherArrowRight />}>
|
||||
{t("shared.viewAll")}
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
<div className="grid w-full grid-cols-3 gap-2">
|
||||
<MiniStat label={t("admin.apiAdmin.inbound.pending")} value={data.inbound.registrationsPending} />
|
||||
<MiniStat label={t("admin.apiAdmin.inbound.newLeads")} value={data.inbound.leadsNew} />
|
||||
<MiniStat label={t("admin.apiAdmin.inbound.qualified")} value={data.inbound.leadsQualified} />
|
||||
</div>
|
||||
<div className="flex w-full flex-col items-start gap-2">
|
||||
{data.inbound.recentLeads.slice(0, 5).map((lead) => (
|
||||
<Link
|
||||
key={lead.id}
|
||||
to={adminPath(`leads/${lead.id}`, { mode: "host-aware" })}
|
||||
className="border-border-default bg-surface-neutral-primary hover:bg-surface-neutral-secondary/60 flex w-full flex-col items-start rounded-md border border-solid px-4 py-3 transition-colors"
|
||||
>
|
||||
<span className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-primary truncate">
|
||||
{lead.email ?? lead.company ?? t("shared.notSet")}
|
||||
</span>
|
||||
<span className="text-body-extra-small-regular-150 font-body-extra-small-regular-150 text-text-neutral-tertiary w-full truncate">
|
||||
{[lead.company, lead.source, t(`admin.platformLeads.status.${lead.status}`)].filter(Boolean).join(" · ")}
|
||||
</span>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function MetricCard({ metric }: { metric: ApiAdminMetricInput }) {
|
||||
const { t } = useTranslation();
|
||||
const format = useLocaleFormatters();
|
||||
return (
|
||||
<StatsCard
|
||||
label={t(metric.labelKey)}
|
||||
value={format.number(metric.value)}
|
||||
trend={metric.tone === "success" ? "positive" : metric.tone === "danger" || metric.tone === "warning" ? "negative" : "neutral"}
|
||||
percentage=""
|
||||
comparisonText={t(metric.detailKey)}
|
||||
icon={metricIcon(metric.id)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function MiniStat({ label, value }: { label: string; value: number }) {
|
||||
const format = useLocaleFormatters();
|
||||
return (
|
||||
<div className="border-border-default bg-surface-neutral-primary flex flex-col items-center rounded-md border border-solid px-3 py-3">
|
||||
<span className="text-subtitle-0 font-subtitle-0 text-text-neutral-primary">{format.number(value)}</span>
|
||||
<span className="text-body-extra-small-regular-150 font-body-extra-small-regular-150 text-text-neutral-tertiary text-center">{label}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function EmptyApiAdmin() {
|
||||
const { t } = useTranslation();
|
||||
return <EmptyState outlined title={t("admin.apiAdmin.empty.title")} body={t("admin.apiAdmin.empty.body")} />;
|
||||
}
|
||||
|
||||
function metricIcon(id: string): React.ReactNode {
|
||||
if (id === "keys") return <FeatherKey />;
|
||||
if (id === "activeKeys") return <FeatherShieldAlert />;
|
||||
if (id === "expiredKeys") return <FeatherActivity />;
|
||||
if (id === "failedLogs") return <FeatherRadioTower />;
|
||||
return <FeatherUsers />;
|
||||
}
|
||||
|
||||
export function ErrorBoundary() {
|
||||
return <ServerError />;
|
||||
}
|
||||
Reference in new issue
Block a user