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
+32
-59
@@ -1,65 +1,38 @@
|
||||
import { Link, useLoaderData } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { LoaderFunctionArgs } from "react-router";
|
||||
import { loadAutomationListVM, type AutomationListVM } from "~/services/automation/automation.server";
|
||||
import { appPath } from "~/utils/app/CanonicalUrlUtils";
|
||||
import { redirect, useActionData, useLoaderData } from "react-router";
|
||||
import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";
|
||||
import { getTranslations } from "~/locale/i18next.server";
|
||||
import {
|
||||
handleAutomationListAction,
|
||||
loadAutomationListVM,
|
||||
type AutomationListActionData,
|
||||
type AutomationListVM,
|
||||
} from "~/services/automation/automation.server";
|
||||
import { validateCSRFToken } from "~/utils/session.server";
|
||||
import { v2MetaFunction } from "~/utils/compat/v2MetaFunction";
|
||||
import { AutomationListPage } from "~/components/screens/automation/AutomationListPage";
|
||||
|
||||
type LoaderData = AutomationListVM & { title: string };
|
||||
|
||||
export const meta: v2MetaFunction<LoaderData> = ({ data }) => [{ title: data?.title }];
|
||||
|
||||
export async function loader({ request, params }: LoaderFunctionArgs) {
|
||||
return Response.json(await loadAutomationListVM({ request, params }));
|
||||
const [{ t }, vm] = await Promise.all([getTranslations(request), loadAutomationListVM({ request, params })]);
|
||||
return Response.json({ ...vm, title: `${t("automation.title")} | ${process.env.APP_NAME}` } satisfies LoaderData);
|
||||
}
|
||||
|
||||
export async function action({ request, params }: ActionFunctionArgs) {
|
||||
await validateCSRFToken(request);
|
||||
const result = await handleAutomationListAction({ request, params });
|
||||
if (result.ok && result.redirectTo) {
|
||||
const target = new URL(result.redirectTo, request.url);
|
||||
target.searchParams.set("toast", result.messageKey);
|
||||
return redirect(target.toString());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export default function AutomationsIndexRoute() {
|
||||
const data = useLoaderData() as AutomationListVM;
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<main className="mx-auto flex w-full max-w-6xl flex-col gap-6 p-6">
|
||||
<header className="flex flex-col gap-2">
|
||||
<h1 className="text-foreground text-2xl font-semibold">{t("automation.title")}</h1>
|
||||
<p className="text-muted-foreground text-sm">{t("automation.subtitle")}</p>
|
||||
<Link className="text-theme-600 text-sm font-medium" to={appPath({ tenantSlug: data.tenantSlug, path: "automations/templates", mode: "host-aware" })}>
|
||||
{t("automation.templatesPage.title")}
|
||||
</Link>
|
||||
</header>
|
||||
|
||||
<section className="grid gap-3 md:grid-cols-3">
|
||||
<MetricCard label={t("automation.metrics.triggers")} value={String(data.triggers.length)} />
|
||||
<MetricCard label={t("automation.metrics.actions")} value={String(data.actions.length)} />
|
||||
<MetricCard label={t("automation.metrics.templates")} value={String(data.templates.length)} />
|
||||
</section>
|
||||
|
||||
<section className="overflow-hidden rounded-lg border">
|
||||
<div className="border-b px-4 py-3">
|
||||
<h2 className="text-foreground text-sm font-semibold">{t("automation.sections.rules")}</h2>
|
||||
</div>
|
||||
{data.rules.length === 0 ? (
|
||||
<div className="text-muted-foreground px-4 py-8 text-sm">{t("automation.empty.rules")}</div>
|
||||
) : (
|
||||
<div className="divide-y">
|
||||
{data.rules.map((rule) => (
|
||||
<Link className="hover:bg-muted/40 grid gap-2 px-4 py-3 md:grid-cols-[1fr_160px_120px_140px_120px]" key={rule.id} to={rule.editUrl}>
|
||||
<span>
|
||||
<span className="text-foreground block text-sm font-medium">{rule.name}</span>
|
||||
<span className="text-muted-foreground block text-xs">{rule.triggerKey ?? t("automation.values.noTrigger")}</span>
|
||||
</span>
|
||||
<span className="text-muted-foreground text-sm">{t(`automation.status.${rule.status}`, { defaultValue: rule.status })}</span>
|
||||
<span className="text-muted-foreground text-sm">{rule.runs30d}</span>
|
||||
<span className="text-muted-foreground text-sm">{rule.lastExecutionAt ?? t("automation.values.never")}</span>
|
||||
<span className="text-theme-600 text-sm">{t("automation.editor.actions.openEditor")}</span>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
function MetricCard({ label, value }: { label: string; value: string }) {
|
||||
return (
|
||||
<div className="rounded-lg border px-4 py-3">
|
||||
<div className="text-muted-foreground text-xs">{label}</div>
|
||||
<div className="text-foreground mt-1 text-2xl font-semibold">{value}</div>
|
||||
</div>
|
||||
);
|
||||
const data = useLoaderData() as LoaderData;
|
||||
const actionData = useActionData() as AutomationListActionData | undefined;
|
||||
return <AutomationListPage vm={data} actionData={actionData} />;
|
||||
}
|
||||
Reference in new issue
Block a user