// R-P5 Interim-UI (AD-28) — per-app connection management screen composed from // ~/ui (D-P5 "App-Detail / Connection-Verwaltung", archetype A6+A2). Pure // presentational: renders the server-built ConnectionDetailVM and reports the // lifecycle mutations (connect / reconnect / disconnect / manual re-sync) // through injected actions — the route owns the fetcher. Degraded/broken // connections raise a screen banner with a reconnect solution button (D-P5 // Klartext requirement). Final Subframe optics = tracked design-nachzug. import { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { FeatherDownloadCloud, FeatherPlug, FeatherPlus } from "@subframe/core"; import type { AppCredentialField } from "@hivegrid/integrations"; import type { ConnectionDetailVM, ConnectionRow } from "@hivegrid/view-models"; import { Alert } from "~/ui/components/Alert"; import { Button } from "~/ui/components/Button"; import { Dialog } from "~/ui/components/Dialog"; import { EmptyState } from "~/ui/components/EmptyState"; import { PageBody, PageIntro, PageShell } from "../shared/PageShell"; import { ConnectionCard } from "./ConnectionCard"; import { ConnectWizardDialog, type ConnectWizardMode, type ConnectWizardSubmit } from "./ConnectWizardDialog"; export type ConnectionDetailActions = { /** POSTs intent=connect to the app route action. */ onConnect: (input: ConnectWizardSubmit) => void; /** POSTs intent=reconnect (same connection id, no history loss). */ onReconnect: (connectionId: string, input: ConnectWizardSubmit) => void; /** POSTs intent=disconnect (status revoked, no hard delete). */ onDisconnect: (connectionId: string) => void; /** POSTs intent=manual-sync. */ onManualSync: (connectionId: string) => void; }; export type ConnectionDetailPageProps = { vm: ConnectionDetailVM; connectionType: string; credentialFields: readonly AppCredentialField[]; actions: ConnectionDetailActions; submitting: boolean; errorMessage: string | null; feedback?: { readonly variant: "success" | "error"; readonly titleKey: string; readonly descriptionKey: string; } | null; /** Increments after a successful mutation — closes any open dialog. */ closeSignal: number; }; type WizardState = ConnectWizardMode | null; export function ConnectionDetailPage({ vm, connectionType, credentialFields, actions, submitting, errorMessage, feedback, closeSignal }: ConnectionDetailPageProps) { const { t } = useTranslation(); const [wizard, setWizard] = useState(null); const [disconnectRow, setDisconnectRow] = useState(null); useEffect(() => { if (closeSignal > 0) { setWizard(null); setDisconnectRow(null); } }, [closeSignal]); if (vm.status !== "ready" || !vm.data) { return ; } const { appKey, appTitleKey, rows, canConnect, canDisconnect, canManualSync, connectHref, projectImportHref, emptyHeadlineKey, emptyBodyKey } = vm.data; const unhealthy = rows.filter((row) => row.status === "degraded" || row.status === "broken"); const openConnect = (mode: ConnectWizardMode) => { if (appKey === "kwp") { window.location.assign(connectHref); return; } setWizard(mode); }; return ( {/* Embedded in the Erweiterungen hub (AK-SET-01): the hub owns the page

and tab bar, so this screen carries a simple section heading. */}
{t(appTitleKey)}
{t("integrations.connections.subtitle")}
{/* The empty state below carries its own connect button — only show the header action once at least one connection exists. */} {canConnect && rows.length > 0 ? ( ) : null}
{feedback ? ( ) : null} {projectImportHref ? ( } onClick={() => window.location.assign(projectImportHref)} data-ui-id="ui.integrations.kwp.project-import.open" > {t("integrations.kwp.projectImport.entry.action")} } /> ) : null} {/* Screen banner (hierarchy §8): at least one degraded/broken connection. */} {unhealthy.length > 0 ? ( row.status === "broken") ? "error" : "warning"} title={t("integrations.connections.banner.title", { count: unhealthy.length })} description={unhealthy[0].healthMessageKey ? t(unhealthy[0].healthMessageKey) : undefined} actions={ canConnect ? ( ) : undefined } data-ui-id="ui.integrations.app.banner" /> ) : null} {rows.length === 0 ? (
{canConnect ? ( ) : null}
) : (
{rows.map((row) => ( openConnect({ type: "reconnect", connectionId: target.id, label: target.label })} onDisconnect={setDisconnectRow} /> ))}
)} {/* Connect/Reconnect wizard (A5, M 720) */} {wizard ? ( { if (wizard.type === "reconnect") actions.onReconnect(wizard.connectionId, input); else actions.onConnect(input); }} onClose={() => setWizard(null)} /> ) : null} {/* Disconnect confirm (XS 420, Klartext: sync jobs stop, history preserved) */} (open ? undefined : setDisconnectRow(null))}> {disconnectRow ? (
{t("integrations.disconnect.title", { label: disconnectRow.label })} {t("integrations.disconnect.description")} {errorMessage ? : null}
) : (
)}
); }