190 lines
8.7 KiB
TypeScript
190 lines
8.7 KiB
TypeScript
// VD-MCP Interim-UI (AD-28) — "Mit KI verbinden" as a shell dialog, modelled on
|
|
// the Subframe "Connect to code" modal: one accordion per client, each step a
|
|
// copyable command or URL. Presentational only: the shell injects the VM and the
|
|
// revoke callback, so there is no useLoaderData/useFetcher in here (DoD A.5).
|
|
// Final Subframe optics land as a tracked design-nachzug.
|
|
|
|
import { useTranslation } from "react-i18next";
|
|
import { FeatherX } from "@subframe/core";
|
|
import type { McpClientGuideVM, McpConnectionVM, McpConnectVM } from "@hivegrid/view-models";
|
|
|
|
import { Accordion } from "~/ui/components/Accordion";
|
|
import { Button } from "~/ui/components/Button";
|
|
import { CopyToClipboardButton } from "~/ui/components/CopyToClipboardButton";
|
|
import { Dialog } from "~/ui/components/Dialog";
|
|
import { IconButton } from "~/ui/components/IconButton";
|
|
import { useLocaleFormatters } from "~/locale/format";
|
|
import { ClientIcon } from "./ClientIcon";
|
|
|
|
export type McpConnectDialogProps = {
|
|
open: boolean;
|
|
onOpenChange: (open: boolean) => void;
|
|
vm: McpConnectVM;
|
|
/** Cuts one client's tokens; the shell reloads the VM afterwards. */
|
|
onRevoke: (clientId: string) => void;
|
|
/** Client id currently being revoked, for the pending button state. */
|
|
revokingClientId?: string | null;
|
|
};
|
|
|
|
export function McpConnectDialog({ open, onOpenChange, vm, onRevoke, revokingClientId = null }: McpConnectDialogProps) {
|
|
const { t } = useTranslation();
|
|
|
|
return (
|
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
|
<Dialog.Content className="w-[620px] max-w-[94vw] p-0" data-ui-id="ui.mcp.connect.dialog">
|
|
<div className="flex w-full flex-col gap-6 p-6">
|
|
<div className="flex w-full items-start justify-between gap-4">
|
|
<div className="flex flex-col items-start gap-3">
|
|
<div className="flex flex-col gap-1">
|
|
<span className="text-heading- font-heading- text-text-neutral-primary">{t("mcp.connect.title")}</span>
|
|
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
|
|
{vm.status === "ready"
|
|
? t("mcp.connect.subtitle", { tenantName: vm.data.tenantName, appName: vm.data.appName })
|
|
: t("mcp.connect.subtitleFallback")}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
<IconButton variant="ghost" size="small" icon={<FeatherX />} aria-label={t("shared.close")} onClick={() => onOpenChange(false)} />
|
|
</div>
|
|
|
|
{vm.status === "loading" || vm.status === "idle" ? (
|
|
<p className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary" data-ui-id="ui.mcp.connect.loading">
|
|
{t("mcp.connect.loading")}
|
|
</p>
|
|
) : null}
|
|
|
|
{vm.status === "error" ? (
|
|
<p className="text-body-default-regular-0 font-body-default-regular-0 text-text-feedback-negative" data-ui-id="ui.mcp.connect.error">
|
|
{t(vm.error.messageKey, { defaultValue: t("mcp.connect.error") })}
|
|
</p>
|
|
) : null}
|
|
|
|
{vm.status === "ready" ? (
|
|
<>
|
|
<section className="flex w-full flex-col gap-2">
|
|
<span className="text-body-default-semibold-0 font-body-default-semibold-0 text-text-neutral-primary">{t("mcp.connect.connectorHeading")}</span>
|
|
<CopyRow value={vm.data.connectorUrl} label={t("mcp.connect.connectorCopy")} uiId="ui.mcp.connect.connectorUrl" />
|
|
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">{t("mcp.connect.connectorHint")}</span>
|
|
</section>
|
|
|
|
<section className="flex w-full flex-col gap-2">
|
|
<span className="text-body-default-semibold-0 font-body-default-semibold-0 text-text-neutral-primary">{t("mcp.connect.setupHeading")}</span>
|
|
{vm.data.guides.map((guide) => (
|
|
<GuideAccordion key={guide.id} guide={guide} />
|
|
))}
|
|
</section>
|
|
|
|
<section className="flex w-full flex-col gap-2">
|
|
<span className="text-body-default-semibold-0 font-body-default-semibold-0 text-text-neutral-primary">
|
|
{t("mcp.connect.connectionsHeading")}
|
|
</span>
|
|
{vm.data.connections.length === 0 ? (
|
|
<p
|
|
className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary"
|
|
data-ui-id="ui.mcp.connect.connections.empty"
|
|
>
|
|
{t("mcp.connect.connections.empty")}
|
|
</p>
|
|
) : (
|
|
<ul className="flex w-full list-none flex-col gap-2 p-0">
|
|
{vm.data.connections.map((connection) => (
|
|
<ConnectionRow
|
|
key={connection.id}
|
|
connection={connection}
|
|
canRevoke={vm.data.canRevoke}
|
|
pending={revokingClientId === connection.id}
|
|
onRevoke={onRevoke}
|
|
/>
|
|
))}
|
|
</ul>
|
|
)}
|
|
</section>
|
|
</>
|
|
) : null}
|
|
</div>
|
|
</Dialog.Content>
|
|
</Dialog>
|
|
);
|
|
}
|
|
|
|
function GuideAccordion({ guide }: { guide: McpClientGuideVM }) {
|
|
const { t } = useTranslation();
|
|
return (
|
|
<Accordion
|
|
data-ui-id={`ui.mcp.connect.guide.${guide.id}`}
|
|
trigger={
|
|
<div className="flex w-full items-center gap-2 px-3 py-2.5">
|
|
<ClientIcon icon={guide.icon} />
|
|
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary grow">{t(guide.labelKey)}</span>
|
|
<Accordion.Chevron />
|
|
</div>
|
|
}
|
|
>
|
|
<div className="flex w-full flex-col gap-3 px-3 pb-3">
|
|
{guide.steps.map((step) => (
|
|
<div key={step.id} className="flex w-full flex-col gap-1">
|
|
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">{t(step.titleKey)}</span>
|
|
{step.hintKey ? (
|
|
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">{t(step.hintKey)}</span>
|
|
) : null}
|
|
{step.copyText ? <CopyRow value={step.copyText} label={t("mcp.connect.copy")} uiId={`ui.mcp.connect.guide.${guide.id}.${step.id}`} /> : null}
|
|
</div>
|
|
))}
|
|
</div>
|
|
</Accordion>
|
|
);
|
|
}
|
|
|
|
function CopyRow({ value, label, uiId }: { value: string; label: string; uiId: string }) {
|
|
return (
|
|
<div
|
|
className="border-border-default bg-surface-neutral-secondary flex w-full items-start gap-2 rounded-md border border-solid px-3 py-2"
|
|
data-ui-id={uiId}
|
|
>
|
|
<code className="text-body-small-regular-0 text-text-neutral-primary min-w-0 grow font-mono break-all whitespace-pre-wrap">{value}</code>
|
|
<CopyToClipboardButton clipboardText={value} tooltipText={label} aria-label={label} successKey="mcp.connect.toast.configurationCopied" />
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function ConnectionRow({
|
|
connection,
|
|
canRevoke,
|
|
pending,
|
|
onRevoke,
|
|
}: {
|
|
connection: McpConnectionVM;
|
|
canRevoke: boolean;
|
|
pending: boolean;
|
|
onRevoke: (clientId: string) => void;
|
|
}) {
|
|
const { t } = useTranslation();
|
|
const formatters = useLocaleFormatters();
|
|
return (
|
|
<li
|
|
className="border-border-default flex w-full items-center gap-3 rounded-md border border-solid px-3 py-2"
|
|
data-ui-id={`ui.mcp.connect.connection.${connection.id}`}
|
|
>
|
|
{/* The client's own mark identifies the row; the live/expired state moved
|
|
into the meta line so the icon slot can carry the brand. */}
|
|
<ClientIcon icon={connection.icon} />
|
|
<div className="flex min-w-0 grow flex-col">
|
|
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary truncate">
|
|
{connection.clientName || t("mcp.connect.connections.unnamedClient")}
|
|
</span>
|
|
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
|
<span className={connection.expired ? "text-text-neutral-tertiary" : "text-text-feedback-positive"}>
|
|
{t(connection.expired ? "mcp.connect.connections.statusExpired" : "mcp.connect.connections.statusActive")}
|
|
</span>{" "}
|
|
· {t(connection.accessKey)} · {t("mcp.connect.connections.connectedAt", { date: formatters.date(connection.connectedAtIso) })}
|
|
</span>
|
|
</div>
|
|
{canRevoke ? (
|
|
<Button variant="destructive" size="small" loading={pending} onClick={() => onRevoke(connection.id)}>
|
|
{t("mcp.connect.connections.revoke")}
|
|
</Button>
|
|
) : null}
|
|
</li>
|
|
);
|
|
}
|