178 lines
8.0 KiB
TypeScript
178 lines
8.0 KiB
TypeScript
// 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 { Link } from "react-router";
|
|
import { useTranslation } from "react-i18next";
|
|
import { 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 { LinkButton } from "~/ui/components/LinkButton";
|
|
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[];
|
|
backHref: string;
|
|
actions: ConnectionDetailActions;
|
|
submitting: boolean;
|
|
errorMessage: string | null;
|
|
/** Increments after a successful mutation — closes any open dialog. */
|
|
closeSignal: number;
|
|
};
|
|
|
|
type WizardState = ConnectWizardMode | null;
|
|
|
|
export function ConnectionDetailPage({ vm, connectionType, credentialFields, backHref, actions, submitting, errorMessage, closeSignal }: ConnectionDetailPageProps) {
|
|
const { t } = useTranslation();
|
|
const [wizard, setWizard] = useState<WizardState>(null);
|
|
const [disconnectRow, setDisconnectRow] = useState<ConnectionRow | null>(null);
|
|
|
|
useEffect(() => {
|
|
if (closeSignal > 0) {
|
|
setWizard(null);
|
|
setDisconnectRow(null);
|
|
}
|
|
}, [closeSignal]);
|
|
|
|
if (vm.status !== "ready" || !vm.data) {
|
|
return <div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.integrations.app" />;
|
|
}
|
|
|
|
const { appTitleKey, rows, canConnect, canDisconnect, canManualSync, emptyHeadlineKey, emptyBodyKey } = vm.data;
|
|
const unhealthy = rows.filter((row) => row.status === "degraded" || row.status === "broken");
|
|
|
|
return (
|
|
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.integrations.app">
|
|
{/* Breadcrumb back to the catalog (DoD B9) + header with connect CTA */}
|
|
<Link to={backHref} className="contents no-underline" data-ui-id="ui.integrations.app.back">
|
|
<LinkButton variant="subtle">{t("integrations.connections.back")}</LinkButton>
|
|
</Link>
|
|
<div className="flex flex-wrap items-start justify-between gap-4">
|
|
<div className="flex flex-col gap-0">
|
|
<span className="text-heading-2 font-heading-2 text-text-neutral-primary">{t(appTitleKey)}</span>
|
|
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
|
{t("integrations.connections.subtitle")}
|
|
</span>
|
|
</div>
|
|
{canConnect ? (
|
|
<Button icon={<FeatherPlus />} onClick={() => setWizard({ type: "connect" })} data-ui-id="ui.integrations.app.connect">
|
|
{t("integrations.connections.add")}
|
|
</Button>
|
|
) : null}
|
|
</div>
|
|
|
|
{/* Screen banner (hierarchy §8): at least one degraded/broken connection. */}
|
|
{unhealthy.length > 0 ? (
|
|
<Alert
|
|
variant={unhealthy.some((row) => 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 ? (
|
|
<Button variant="secondary" size="small" onClick={() => setWizard({ type: "reconnect", connectionId: unhealthy[0].id, label: unhealthy[0].label })}>
|
|
{t("integrations.connections.actions.reconnect")}
|
|
</Button>
|
|
) : undefined
|
|
}
|
|
data-ui-id="ui.integrations.app.banner"
|
|
/>
|
|
) : null}
|
|
|
|
{rows.length === 0 ? (
|
|
<div className="flex w-full flex-col items-center gap-4" data-ui-id="ui.integrations.app.empty">
|
|
<EmptyState title={t(emptyHeadlineKey)} body={t(emptyBodyKey)} />
|
|
{canConnect ? (
|
|
<Button icon={<FeatherPlus />} onClick={() => setWizard({ type: "connect" })}>
|
|
{t("integrations.connections.add")}
|
|
</Button>
|
|
) : null}
|
|
</div>
|
|
) : (
|
|
<div className="grid w-full grid-cols-1 gap-4 lg:grid-cols-2" data-ui-id="ui.integrations.app.list">
|
|
{rows.map((row) => (
|
|
<ConnectionCard
|
|
key={row.id}
|
|
row={row}
|
|
canDisconnect={canDisconnect}
|
|
canManualSync={canManualSync}
|
|
canReconnect={canConnect}
|
|
submitting={submitting}
|
|
onManualSync={actions.onManualSync}
|
|
onReconnect={(target) => setWizard({ type: "reconnect", connectionId: target.id, label: target.label })}
|
|
onDisconnect={setDisconnectRow}
|
|
/>
|
|
))}
|
|
</div>
|
|
)}
|
|
|
|
{/* Connect/Reconnect wizard (A5, M 720) */}
|
|
{wizard ? (
|
|
<ConnectWizardDialog
|
|
open
|
|
mode={wizard}
|
|
appTitleKey={appTitleKey}
|
|
connectionType={connectionType}
|
|
credentialFields={credentialFields}
|
|
submitting={submitting}
|
|
errorMessage={errorMessage}
|
|
onSubmit={(input) => {
|
|
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) */}
|
|
<Dialog open={disconnectRow !== null} onOpenChange={(open: boolean) => (open ? undefined : setDisconnectRow(null))}>
|
|
<Dialog.Content className="w-[420px] max-w-[90vw] p-4">
|
|
{disconnectRow ? (
|
|
<div className="flex w-full flex-col gap-6" data-ui-id="ui.integrations.app.disconnectConfirm">
|
|
<div className="flex flex-col gap-2">
|
|
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">{t("integrations.disconnect.title", { label: disconnectRow.label })}</span>
|
|
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
|
{t("integrations.disconnect.description")}
|
|
</span>
|
|
{errorMessage ? <Alert variant="error" title={t(errorMessage)} /> : null}
|
|
</div>
|
|
<div className="flex w-full items-center justify-end gap-2">
|
|
<Button variant="tertiary" onClick={() => setDisconnectRow(null)}>
|
|
{t("shared.cancel")}
|
|
</Button>
|
|
<Button variant="destructive" loading={submitting} onClick={() => actions.onDisconnect(disconnectRow.id)} data-ui-id="ui.integrations.app.disconnectSubmit">
|
|
{t("integrations.connections.actions.disconnect")}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
) : (
|
|
<div />
|
|
)}
|
|
</Dialog.Content>
|
|
</Dialog>
|
|
</div>
|
|
);
|
|
}
|