103 lines
3.6 KiB
TypeScript
103 lines
3.6 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 { 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 { integrationsSyncsPath } from "~/utils/integrations/integrationsRoutePaths";
|
|
import { SyncRunDetailPage } from "~/components/screens/integrations/SyncRunDetailPage";
|
|
import ServerError from "~/components/ui/errors/ServerError";
|
|
|
|
type LoaderData = { title: string; backHref: string; vm: SyncRunDetailVM };
|
|
|
|
export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
|
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();
|
|
}
|
|
if (!getCatalogEntry(appKey)) {
|
|
throw notFoundResponse();
|
|
}
|
|
// Tenant-scoped; 404 if connection or run is not in this tenant.
|
|
await getConnectionOrThrow(ctx.tenantId, connectionId);
|
|
const { run, items, logs } = await getSyncRunWithItems(ctx.tenantId, runId);
|
|
if (run.dataConnectionId !== connectionId) {
|
|
throw notFoundResponse();
|
|
}
|
|
|
|
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({
|
|
title: `${t("integrations.runDetail.title")} | ${process.env.APP_NAME}`,
|
|
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 />;
|
|
}
|