121 lines
4.4 KiB
TypeScript
121 lines
4.4 KiB
TypeScript
// R-P5 (P5) — sync-run detail: one AppSyncRun with its AppSyncItem rows and
|
|
// AppSyncRunLog lines (Klartext). Requires integrations.view_logs; module off or
|
|
// missing permission -> 404. Interim UI from ~/ui (AD-28); final optic = D-P5.
|
|
|
|
import { redirect, type LoaderFunctionArgs, useLoaderData } from "react-router";
|
|
import {
|
|
buildSyncRunDetailVM,
|
|
syncItemOperationKey,
|
|
syncItemStatusKey,
|
|
syncKindKey,
|
|
syncLogSeverityKey,
|
|
syncStatusKey,
|
|
type SyncItemRow,
|
|
type SyncLogRow,
|
|
type SyncRunDetailVM,
|
|
} from "@hivegrid/view-models";
|
|
import { getCatalogEntry } from "@hivegrid/integrations";
|
|
import { getTranslations } from "~/locale/i18next.server";
|
|
import { loadIntegrationsContext, notFoundResponse, requireIntegrationsPermission } from "~/utils/integrations/integrationsAccess.server";
|
|
import { getConnectionOrThrow, getSyncRunWithItems } from "~/utils/integrations/appsEngineService.server";
|
|
import { integrationsAppPath, integrationsCatalogPath, integrationsSyncsPath, legacyIntegrationsRedirectPath } from "~/utils/integrations/integrationsRoutePaths";
|
|
import { requireKwpIntegrationModule } from "~/modules/kwp/routes/kwpAccess.server";
|
|
import { SyncRunDetailPage } from "~/components/screens/integrations/SyncRunDetailPage";
|
|
import ServerError from "~/components/ui/errors/ServerError";
|
|
|
|
type LoaderData = {
|
|
title: string;
|
|
breadcrumbAncestors: { label: string; href: string }[];
|
|
backHref: string;
|
|
vm: SyncRunDetailVM;
|
|
};
|
|
|
|
export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
|
const legacyRedirect = legacyIntegrationsRedirectPath(request.url, params.tenant ?? "");
|
|
if (legacyRedirect) {
|
|
throw redirect(legacyRedirect);
|
|
}
|
|
const { t } = await getTranslations(request);
|
|
const ctx = await loadIntegrationsContext({ request, params });
|
|
const tenantSlug = params.tenant ?? "";
|
|
const appKey = params.app ?? "";
|
|
const connectionId = params.connectionId ?? "";
|
|
const runId = params.runId ?? "";
|
|
|
|
if (!ctx.hasModule) {
|
|
throw notFoundResponse();
|
|
}
|
|
try {
|
|
requireIntegrationsPermission(ctx, "integrations.view_logs");
|
|
} catch {
|
|
throw notFoundResponse();
|
|
}
|
|
const app = getCatalogEntry(appKey);
|
|
if (!app) {
|
|
throw notFoundResponse();
|
|
}
|
|
if (appKey === "kwp") {
|
|
await requireKwpIntegrationModule(ctx);
|
|
throw notFoundResponse();
|
|
}
|
|
// Tenant-scoped; 404 if connection or run is not in this tenant.
|
|
await getConnectionOrThrow(ctx.tenantId, connectionId, appKey);
|
|
const { run, items, logs } = await getSyncRunWithItems(ctx.tenantId, runId, connectionId, appKey);
|
|
|
|
const itemRows: SyncItemRow[] = items.map((item) => ({
|
|
id: item.id,
|
|
entityType: item.entityType,
|
|
entityId: item.entityId,
|
|
externalId: item.externalId,
|
|
operation: item.operation,
|
|
operationKey: syncItemOperationKey(item.operation),
|
|
status: item.status,
|
|
statusKey: syncItemStatusKey(item.status),
|
|
errorText: item.errorText,
|
|
}));
|
|
const logRows: SyncLogRow[] = logs.map((log) => ({
|
|
id: log.id,
|
|
severity: log.severity,
|
|
severityKey: syncLogSeverityKey(log.severity),
|
|
messageKey: log.messageText,
|
|
createdIso: log.createdAt.toISOString(),
|
|
}));
|
|
|
|
const vm = buildSyncRunDetailVM({
|
|
runId: run.id,
|
|
connectionId,
|
|
kind: run.kind,
|
|
kindKey: syncKindKey(run.kind),
|
|
status: run.status,
|
|
statusKey: syncStatusKey(run.status),
|
|
itemsTotal: run.itemsTotal,
|
|
itemsSucceeded: run.itemsSucceeded,
|
|
itemsFailed: run.itemsFailed,
|
|
summaryKey: run.summaryText,
|
|
startedIso: run.startedAt ? run.startedAt.toISOString() : null,
|
|
completedIso: run.completedAt ? run.completedAt.toISOString() : null,
|
|
items: itemRows,
|
|
logs: logRows,
|
|
});
|
|
return Response.json({
|
|
// Breadcrumb: … > Erweiterungen > Integrationen > <app> > Sync-Historie > Run.
|
|
title: `${t("integrations.runDetail.title")} | ${process.env.APP_NAME}`,
|
|
breadcrumbAncestors: [
|
|
{ label: t("integrations.nav.title"), href: integrationsCatalogPath(tenantSlug) },
|
|
{ label: t(app.titleKey), href: integrationsAppPath(tenantSlug, appKey) },
|
|
{ label: t("integrations.syncs.title"), href: integrationsSyncsPath(tenantSlug, appKey, connectionId) },
|
|
],
|
|
backHref: integrationsSyncsPath(tenantSlug, appKey, connectionId),
|
|
vm,
|
|
} satisfies LoaderData);
|
|
};
|
|
|
|
export default function IntegrationsSyncRunDetailRoute() {
|
|
const { backHref, vm } = useLoaderData<LoaderData>();
|
|
return <SyncRunDetailPage vm={vm} backHref={backHref} />;
|
|
}
|
|
|
|
export function ErrorBoundary() {
|
|
return <ServerError />;
|
|
}
|