Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+598
@@ -0,0 +1,598 @@
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Link } from "react-router";
|
||||
import { FeatherArrowRight, FeatherPlug, FeatherPower, FeatherPowerOff, FeatherShieldCheck } from "@subframe/core";
|
||||
import type { PluginCapabilityRow, PluginCatalogRow, PluginCatalogVM, PluginI18nText } from "@hivegrid/view-models";
|
||||
import { useLocaleFormatters, type LocaleFormatters } from "~/locale/format";
|
||||
import { Alert } from "~/ui/components/Alert";
|
||||
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Card } from "~/ui/components/Card";
|
||||
import { Checkbox } from "~/ui/components/Checkbox";
|
||||
import { Dialog } from "~/ui/components/Dialog";
|
||||
import { EmptyState } from "~/ui/components/EmptyState";
|
||||
import { Loader } from "~/ui/components/Loader";
|
||||
import { PAGE_HEADER_ICON_CLASS, PageBody, PageHeader, PageIntro, PageShell } from "../shared/PageShell";
|
||||
|
||||
/** AK-UI-05 interim (AD-28): tenant plugin catalog composed from ~/ui until David's final D-P5 delta lands. */
|
||||
|
||||
export type PluginCapabilityApproval = {
|
||||
readonly pluginRowId: string;
|
||||
readonly op: "grant" | "grantAndEnable";
|
||||
readonly capabilityReviewDigest: string;
|
||||
readonly capabilityNames: readonly string[];
|
||||
};
|
||||
|
||||
export type PluginCapabilityRevocation = {
|
||||
readonly pluginRowId: string;
|
||||
readonly pluginId: string;
|
||||
readonly capabilityName: string;
|
||||
};
|
||||
|
||||
export type PluginCatalogActions = {
|
||||
readonly onEnable: (pluginRowId: string) => void | Promise<void>;
|
||||
readonly onDisable: (pluginRowId: string) => void | Promise<void>;
|
||||
readonly onApproveCapabilities: (approval: PluginCapabilityApproval) => void | Promise<void>;
|
||||
readonly onRevokeCapability: (revocation: PluginCapabilityRevocation) => void | Promise<void>;
|
||||
};
|
||||
|
||||
type RevokeTarget = PluginCapabilityRevocation & { readonly label: PluginI18nText };
|
||||
|
||||
type Translate = (key: string, options?: Record<string, unknown>) => string;
|
||||
|
||||
/**
|
||||
* Resolves a VM i18n descriptor. `fallbackKey` carries the "unknown capability"
|
||||
* default the route used to pass through i18next's `defaultValue`.
|
||||
*/
|
||||
function pluginText(t: Translate, text: PluginI18nText): string {
|
||||
if (text.fallbackKey) {
|
||||
return t(text.key, { ...text.params, defaultValue: t(text.fallbackKey, text.params) });
|
||||
}
|
||||
return t(text.key, text.params);
|
||||
}
|
||||
|
||||
function scopeText(t: Translate, capability: PluginCapabilityRow): string {
|
||||
if (capability.scopeParts.length === 0) {
|
||||
return t("settings.plugins.consent.noScope");
|
||||
}
|
||||
return capability.scopeParts.map((part) => pluginText(t, part)).join(" / ");
|
||||
}
|
||||
|
||||
function CapabilityMetaBadges({ capability, t }: { capability: PluginCapabilityRow; t: Translate }): React.JSX.Element | null {
|
||||
if (!capability.riskKey && !capability.availabilityKey) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
{capability.riskKey && capability.riskTone ? (
|
||||
<BadgeFeedback farbe={capability.riskTone} size="small" data-ui-id="ui.plugins.capabilityReview.risk">
|
||||
{t(capability.riskKey)}
|
||||
</BadgeFeedback>
|
||||
) : null}
|
||||
{capability.availabilityKey && capability.availabilityTone ? (
|
||||
<BadgeFeedback farbe={capability.availabilityTone} size="small" data-ui-id="ui.plugins.capabilityReview.availability">
|
||||
{t(capability.availabilityKey)}
|
||||
</BadgeFeedback>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function GrantedCapability({
|
||||
capability,
|
||||
row,
|
||||
canManage,
|
||||
formatters,
|
||||
onRevoke,
|
||||
t,
|
||||
}: {
|
||||
capability: PluginCapabilityRow;
|
||||
row: PluginCatalogRow;
|
||||
canManage: boolean;
|
||||
formatters: LocaleFormatters;
|
||||
onRevoke: (target: RevokeTarget) => void;
|
||||
t: Translate;
|
||||
}): React.JSX.Element {
|
||||
return (
|
||||
<div className="border-border-default bg-surface-neutral-secondary flex w-full flex-col items-start gap-2 rounded-md border border-solid p-3">
|
||||
<div className="flex w-full flex-wrap items-center justify-between gap-2">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{pluginText(t, capability.label)}</span>
|
||||
<BadgeFeedback farbe={capability.statusTone} size="small">
|
||||
{t(capability.statusKey)}
|
||||
</BadgeFeedback>
|
||||
</div>
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">{scopeText(t, capability)}</span>
|
||||
{capability.granted && capability.grantedAtIso ? (
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary" data-ui-id="ui.plugins.capability.grantMeta">
|
||||
{t("settings.plugins.consent.grantedAt", {
|
||||
date: formatters.date(capability.grantedAtIso, { dateStyle: "medium", timeStyle: "short" }),
|
||||
})}
|
||||
</span>
|
||||
) : null}
|
||||
{canManage && capability.granted ? (
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<Button
|
||||
variant="tertiary"
|
||||
size="small"
|
||||
onClick={() => onRevoke({ pluginRowId: row.id, pluginId: row.pluginId, capabilityName: capability.name, label: capability.label })}
|
||||
data-ui-id="ui.plugins.capability.revoke.button"
|
||||
data-capability={capability.name}
|
||||
>
|
||||
{t("settings.plugins.consent.revoke")}
|
||||
</Button>
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
||||
{t("settings.plugins.consent.revokeDisables")}
|
||||
</span>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function PluginCard({
|
||||
row,
|
||||
canManage,
|
||||
formatters,
|
||||
manifestOpen,
|
||||
reviewOpen,
|
||||
onToggleManifest,
|
||||
onReview,
|
||||
onRevoke,
|
||||
actions,
|
||||
t,
|
||||
}: {
|
||||
row: PluginCatalogRow;
|
||||
canManage: boolean;
|
||||
formatters: LocaleFormatters;
|
||||
manifestOpen: boolean;
|
||||
reviewOpen: boolean;
|
||||
onToggleManifest: () => void;
|
||||
onReview: () => void;
|
||||
onRevoke: (target: RevokeTarget) => void;
|
||||
actions: PluginCatalogActions;
|
||||
t: Translate;
|
||||
}): React.JSX.Element {
|
||||
return (
|
||||
<Card className="w-full" data-ui-id="ui.plugins.item" data-plugin-row-id={row.id} data-plugin-id={row.pluginId}>
|
||||
<div className="flex w-full flex-col items-start gap-4">
|
||||
<div className="flex w-full flex-wrap items-start justify-between gap-3">
|
||||
<div className="flex min-w-0 flex-col items-start">
|
||||
<h2 className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{row.pluginId}</h2>
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
||||
{t("settings.plugins.versionInstalled", {
|
||||
version: row.version,
|
||||
date: formatters.date(row.installedAtIso, { dateStyle: "medium", timeStyle: "short" }),
|
||||
})}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex flex-none flex-wrap items-center gap-3">
|
||||
<BadgeFeedback farbe={row.statusTone} size="small">
|
||||
{t(row.statusKey)}
|
||||
</BadgeFeedback>
|
||||
{canManage && row.enabled ? (
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="small"
|
||||
icon={<FeatherPowerOff />}
|
||||
onClick={() => void actions.onDisable(row.id)}
|
||||
data-ui-id="ui.plugins.lifecycle.button"
|
||||
data-op="disable"
|
||||
>
|
||||
{t("shared.disable")}
|
||||
</Button>
|
||||
) : null}
|
||||
{canManage && row.canEnable ? (
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="small"
|
||||
icon={<FeatherPower />}
|
||||
onClick={() => void actions.onEnable(row.id)}
|
||||
data-ui-id="ui.plugins.lifecycle.button"
|
||||
data-op="enable"
|
||||
>
|
||||
{t("shared.enable")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex w-full flex-col items-start gap-3">
|
||||
<span className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-tertiary uppercase">{t("settings.plugins.capabilities")}</span>
|
||||
{row.capabilities.length === 0 ? (
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">{t("settings.plugins.consent.none")}</span>
|
||||
) : (
|
||||
<div className="flex w-full flex-col items-start gap-2">
|
||||
{row.capabilities.map((capability) => (
|
||||
<GrantedCapability
|
||||
key={capability.name}
|
||||
capability={capability}
|
||||
row={row}
|
||||
canManage={canManage}
|
||||
formatters={formatters}
|
||||
onRevoke={onRevoke}
|
||||
t={t}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{canManage && row.canReviewCapabilities ? (
|
||||
<Alert
|
||||
variant="warning"
|
||||
notDismissible
|
||||
title={t("settings.plugins.consent.reviewCapabilities")}
|
||||
description={t("settings.plugins.consent.description")}
|
||||
actions={
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="small"
|
||||
icon={<FeatherShieldCheck />}
|
||||
aria-haspopup="dialog"
|
||||
aria-expanded={reviewOpen}
|
||||
onClick={onReview}
|
||||
data-ui-id="ui.plugins.capabilityReview.toggle"
|
||||
>
|
||||
{t("settings.plugins.consent.reviewCapabilities")}
|
||||
</Button>
|
||||
}
|
||||
className="w-full"
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<div className="flex w-full flex-wrap items-center gap-4">
|
||||
{/* The manifest preview stays a real button toggling a focusable region. */}
|
||||
<Button
|
||||
variant="tertiary"
|
||||
size="small"
|
||||
id={`plugin-manifest-toggle-${row.id}`}
|
||||
aria-expanded={manifestOpen}
|
||||
aria-controls={`plugin-manifest-${row.id}`}
|
||||
onClick={onToggleManifest}
|
||||
data-ui-id="ui.plugins.manifest.toggle"
|
||||
>
|
||||
{manifestOpen ? t("settings.plugins.hideManifest") : t("settings.plugins.viewManifest")}
|
||||
</Button>
|
||||
{row.settingsHref ? (
|
||||
<PluginCardLink to={row.settingsHref} uiId="ui.plugins.settings.open">
|
||||
{t("settings.plugins.openSettings")}
|
||||
</PluginCardLink>
|
||||
) : null}
|
||||
{row.auditHref ? (
|
||||
<PluginCardLink to={row.auditHref} uiId="ui.plugins.audit.open">
|
||||
{t("settings.plugins.viewAudit")}
|
||||
</PluginCardLink>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{manifestOpen ? (
|
||||
<pre
|
||||
id={`plugin-manifest-${row.id}`}
|
||||
// Scrollable regions must be keyboard-focusable (axe
|
||||
// scrollable-region-focusable) so keyboard users can scroll the
|
||||
// manifest content.
|
||||
role="region"
|
||||
aria-labelledby={`plugin-manifest-toggle-${row.id}`}
|
||||
tabIndex={0}
|
||||
className="bg-surface-neutral-secondary text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-secondary w-full overflow-auto rounded-md p-3"
|
||||
data-ui-id="ui.plugins.manifest.panel"
|
||||
>
|
||||
{row.manifestJson}
|
||||
</pre>
|
||||
) : null}
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
function PluginCardLink({
|
||||
to,
|
||||
uiId,
|
||||
children,
|
||||
}: {
|
||||
to: string;
|
||||
uiId: string;
|
||||
children: React.ReactNode;
|
||||
}): React.JSX.Element {
|
||||
return (
|
||||
<Link
|
||||
to={to}
|
||||
className="group/plugin-link flex cursor-pointer items-center gap-2 no-underline"
|
||||
data-ui-id={uiId}
|
||||
>
|
||||
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-primary group-hover/plugin-link:text-text-feedback-link-hover group-active/plugin-link:text-text-feedback-link-active">
|
||||
{children}
|
||||
</span>
|
||||
<FeatherArrowRight className="text-body-small-regular-150 font-body-small-regular-150 text-icon-neutral-primary group-hover/plugin-link:text-icon-feedback-link-hover group-active/plugin-link:text-icon-feedback-link-active" />
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
|
||||
export function PluginCatalogPage({
|
||||
vm,
|
||||
actions,
|
||||
actionMessage,
|
||||
actionOk,
|
||||
submitting,
|
||||
embedded = false,
|
||||
}: {
|
||||
vm: PluginCatalogVM;
|
||||
actions: PluginCatalogActions;
|
||||
actionMessage?: string;
|
||||
actionOk?: boolean;
|
||||
submitting?: boolean;
|
||||
/** Inside the Erweiterungen hub (AK-SET-01) the hub owns the header. */
|
||||
embedded?: boolean;
|
||||
}): React.JSX.Element {
|
||||
const { t } = useTranslation();
|
||||
const formatters = useLocaleFormatters();
|
||||
const [manifestOpenFor, setManifestOpenFor] = useState<string | null>(null);
|
||||
const [reviewRowId, setReviewRowId] = useState<string | null>(null);
|
||||
const [revokeTarget, setRevokeTarget] = useState<RevokeTarget | null>(null);
|
||||
const [reviewedCapabilities, setReviewedCapabilities] = useState<ReadonlySet<string>>(() => new Set());
|
||||
const busy = Boolean(submitting);
|
||||
const readyData = vm.status === "ready" ? vm.data : undefined;
|
||||
const actionFailed = actionMessage !== undefined && actionOk === false;
|
||||
|
||||
if (vm.status === "idle" || vm.status === "loading") {
|
||||
return (
|
||||
<PageShell uiId="ui.plugins.page">
|
||||
{embedded ? null : <PageHeader icon={<FeatherPlug className={PAGE_HEADER_ICON_CLASS} />} title={t("settings.plugins.title")} />}
|
||||
<PageBody>
|
||||
<Card data-ui-id="ui.plugins.loading">
|
||||
<div className="flex w-full items-center gap-3">
|
||||
<Loader />
|
||||
<div className="flex flex-col items-start">
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
|
||||
{t("settings.plugins.loading.headline")}
|
||||
</span>
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">{t("settings.plugins.loading.body")}</span>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
</PageBody>
|
||||
</PageShell>
|
||||
);
|
||||
}
|
||||
|
||||
if (vm.status === "error" || !readyData) {
|
||||
return (
|
||||
<PageShell uiId="ui.plugins.page">
|
||||
{embedded ? null : <PageHeader icon={<FeatherPlug className={PAGE_HEADER_ICON_CLASS} />} title={t("settings.plugins.title")} />}
|
||||
<PageBody>
|
||||
<EmptyState
|
||||
outlined
|
||||
variant="error"
|
||||
title={t("settings.plugins.error.headline")}
|
||||
body={vm.status === "error" ? t(vm.error.messageKey) : t("settings.plugins.error.body")}
|
||||
data-ui-id="ui.plugins.error"
|
||||
/>
|
||||
</PageBody>
|
||||
</PageShell>
|
||||
);
|
||||
}
|
||||
|
||||
const { tenantSlug, canManage, rows, emptyHeadlineKey, emptyBodyKey } = readyData;
|
||||
|
||||
/**
|
||||
* Dialogs close data-driven, never on submit: a rejected mutation (e.g. a
|
||||
* stale capability-review digest -> 409) must leave the review open and usable
|
||||
* so the manager can read the error and retry. Once the server accepted the
|
||||
* grant, the revalidated VM no longer reports the row as review-pending and
|
||||
* the dialog disappears on its own.
|
||||
*/
|
||||
const reviewCandidate = rows.find((row) => row.id === reviewRowId) ?? null;
|
||||
const reviewRow = reviewCandidate?.canReviewCapabilities ? reviewCandidate : null;
|
||||
const revokeRow = revokeTarget ? (rows.find((row) => row.id === revokeTarget.pluginRowId) ?? null) : null;
|
||||
const revokeStillGranted = Boolean(
|
||||
revokeTarget && revokeRow?.capabilities.some((capability) => capability.name === revokeTarget.capabilityName && capability.granted)
|
||||
);
|
||||
const openRevokeTarget = revokeStillGranted ? revokeTarget : null;
|
||||
|
||||
// The review key is digest-scoped: a changed manifest/grant set invalidates
|
||||
// every tick the manager already made (stale-consent guard, server-enforced).
|
||||
const reviewKey = (row: PluginCatalogRow, capabilityName: string): string => `${row.id}:${row.capabilityReviewDigest}:${capabilityName}`;
|
||||
|
||||
const reviewComplete =
|
||||
reviewRow !== null &&
|
||||
!reviewRow.hasUnapprovableCapability &&
|
||||
reviewRow.missingCapabilities.every((capabilityName) => reviewedCapabilities.has(reviewKey(reviewRow, capabilityName)));
|
||||
|
||||
const closeReview = (row: PluginCatalogRow | null): void => {
|
||||
if (row) {
|
||||
setReviewedCapabilities((current) => {
|
||||
const next = new Set(current);
|
||||
for (const capabilityName of row.missingCapabilities) {
|
||||
next.delete(reviewKey(row, capabilityName));
|
||||
}
|
||||
return next;
|
||||
});
|
||||
}
|
||||
setReviewRowId(null);
|
||||
};
|
||||
|
||||
return (
|
||||
<PageShell uiId="ui.plugins.page">
|
||||
{embedded ? null : (
|
||||
<PageHeader
|
||||
icon={<FeatherPlug className={PAGE_HEADER_ICON_CLASS} />}
|
||||
title={t("settings.plugins.title")}
|
||||
subtitle={t("settings.plugins.description", { tenantSlug })}
|
||||
/>
|
||||
)}
|
||||
<PageBody>
|
||||
{embedded ? <PageIntro uiId="ui.plugins.intro">{t("settings.plugins.description", { tenantSlug })}</PageIntro> : null}
|
||||
{actionMessage ? (
|
||||
<Alert
|
||||
variant={actionOk ? "success" : "error"}
|
||||
role={actionOk ? "status" : "alert"}
|
||||
notDismissible
|
||||
title={actionMessage}
|
||||
className="w-full"
|
||||
data-ui-id={actionOk ? "ui.plugins.actionSuccess" : "ui.plugins.actionError"}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{rows.length === 0 ? (
|
||||
<EmptyState outlined title={t(emptyHeadlineKey)} body={t(emptyBodyKey)} data-ui-id="ui.plugins.empty" />
|
||||
) : (
|
||||
<div className="flex w-full flex-col items-start gap-4" data-ui-id="ui.plugins.list">
|
||||
{rows.map((row) => (
|
||||
<PluginCard
|
||||
key={row.id}
|
||||
row={row}
|
||||
canManage={canManage}
|
||||
formatters={formatters}
|
||||
manifestOpen={manifestOpenFor === row.id}
|
||||
reviewOpen={reviewRow?.id === row.id}
|
||||
onToggleManifest={() => setManifestOpenFor(manifestOpenFor === row.id ? null : row.id)}
|
||||
onReview={() => setReviewRowId(row.id)}
|
||||
onRevoke={setRevokeTarget}
|
||||
actions={actions}
|
||||
t={t}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Mounted only while open: the ~/ui Dialog renders an empty visually-hidden
|
||||
* Radix title even when closed, which axe flags as an empty heading. */}
|
||||
{reviewRow !== null ? (
|
||||
<Dialog open onOpenChange={(open: boolean) => (open ? undefined : closeReview(reviewRow))}>
|
||||
<Dialog.Content
|
||||
className="w-[720px] max-w-[90vw] p-4"
|
||||
aria-label={t("settings.plugins.consent.reviewFormLabel", { pluginId: reviewRow.pluginId })}
|
||||
data-ui-id="ui.plugins.capabilityReview.form"
|
||||
>
|
||||
<div className="flex w-full flex-col items-start gap-6">
|
||||
<div className="flex w-full flex-col items-start gap-2">
|
||||
<span className="text-heading-0 font-heading-0 text-text-neutral-primary">
|
||||
{t("settings.plugins.consent.reviewTitle", { pluginId: reviewRow.pluginId })}
|
||||
</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("settings.plugins.consent.reviewDescription", { version: reviewRow.version })}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* A rejected grant (e.g. a stale review digest) is announced here,
|
||||
* inside the dialog the manager is still standing in. */}
|
||||
{actionFailed ? (
|
||||
<Alert role="alert" variant="error" notDismissible title={actionMessage} className="w-full" data-ui-id="ui.plugins.capabilityReview.error" />
|
||||
) : null}
|
||||
|
||||
<div className="flex max-h-[50vh] w-full flex-col items-start gap-4 overflow-y-auto">
|
||||
{reviewRow.capabilitiesToReview.map((capability) => {
|
||||
const key = reviewKey(reviewRow, capability.name);
|
||||
return (
|
||||
<div key={capability.name} className="border-border-default flex w-full flex-col items-start gap-2 rounded-md border border-solid p-3">
|
||||
<Checkbox
|
||||
label={t("settings.plugins.consent.reviewCapability", { capability: pluginText(t, capability.label) })}
|
||||
checked={reviewedCapabilities.has(key)}
|
||||
disabled={!capability.approvable}
|
||||
onCheckedChange={(checked: boolean) => {
|
||||
setReviewedCapabilities((current) => {
|
||||
const next = new Set(current);
|
||||
if (checked) {
|
||||
next.add(key);
|
||||
} else {
|
||||
next.delete(key);
|
||||
}
|
||||
return next;
|
||||
});
|
||||
}}
|
||||
data-ui-id="ui.plugins.capabilityReview.checkbox"
|
||||
data-capability={capability.name}
|
||||
/>
|
||||
<CapabilityMetaBadges capability={capability} t={t} />
|
||||
{!capability.approvable ? (
|
||||
<span
|
||||
className="text-body-small-regular-150 font-body-small-regular-150 text-text-feedback-negative"
|
||||
data-ui-id="ui.plugins.capabilityReview.unavailableReason"
|
||||
>
|
||||
{t("settings.plugins.consent.unavailableDescription")}
|
||||
</span>
|
||||
) : null}
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">{scopeText(t, capability)}</span>
|
||||
<code
|
||||
className="border-border-default bg-surface-neutral-secondary text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-secondary inline-flex rounded-sm border border-solid px-1.5 py-0.5"
|
||||
data-ui-id="ui.plugins.capabilityReview.grantName"
|
||||
>
|
||||
{capability.name}
|
||||
</code>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
<div className="flex w-full items-center justify-end gap-2">
|
||||
<Button variant="tertiary" disabled={busy} onClick={() => closeReview(reviewRow)} data-ui-id="ui.plugins.capabilityReview.deny">
|
||||
{t("shared.deny")}
|
||||
</Button>
|
||||
<Button
|
||||
disabled={!reviewComplete || busy}
|
||||
loading={busy}
|
||||
onClick={() =>
|
||||
void actions.onApproveCapabilities({
|
||||
pluginRowId: reviewRow.id,
|
||||
op: reviewRow.grantOp,
|
||||
capabilityReviewDigest: reviewRow.capabilityReviewDigest,
|
||||
capabilityNames: reviewRow.missingCapabilities,
|
||||
})
|
||||
}
|
||||
data-ui-id="ui.plugins.capabilityReview.button"
|
||||
>
|
||||
{reviewRow.enabled ? t("settings.plugins.consent.approve") : t("settings.plugins.consent.approveAndEnable")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
) : null}
|
||||
|
||||
{openRevokeTarget !== null ? (
|
||||
<Dialog open onOpenChange={(open: boolean) => (open ? undefined : setRevokeTarget(null))}>
|
||||
<Dialog.Content
|
||||
className="w-[420px] max-w-[90vw] p-4"
|
||||
aria-label={t("settings.plugins.revokeDialog.title")}
|
||||
data-ui-id="ui.plugins.capability.revoke.form"
|
||||
>
|
||||
<div className="flex w-full flex-col items-start gap-6">
|
||||
<div className="flex w-full flex-col items-start gap-2">
|
||||
<span className="text-heading-0 font-heading-0 text-text-neutral-primary">{t("settings.plugins.revokeDialog.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("settings.plugins.revokeDialog.body", {
|
||||
capability: pluginText(t, openRevokeTarget.label),
|
||||
pluginId: openRevokeTarget.pluginId,
|
||||
})}
|
||||
</span>
|
||||
</div>
|
||||
{actionFailed ? (
|
||||
<Alert role="alert" variant="error" notDismissible title={actionMessage} className="w-full" data-ui-id="ui.plugins.capability.revoke.error" />
|
||||
) : null}
|
||||
<div className="flex w-full items-center justify-end gap-2">
|
||||
<Button variant="tertiary" disabled={busy} onClick={() => setRevokeTarget(null)}>
|
||||
{t("settings.plugins.revokeDialog.cancel")}
|
||||
</Button>
|
||||
<Button
|
||||
variant="destructive"
|
||||
disabled={busy}
|
||||
loading={busy}
|
||||
onClick={() =>
|
||||
void actions.onRevokeCapability({
|
||||
pluginRowId: openRevokeTarget.pluginRowId,
|
||||
pluginId: openRevokeTarget.pluginId,
|
||||
capabilityName: openRevokeTarget.capabilityName,
|
||||
})
|
||||
}
|
||||
data-ui-id="ui.plugins.capability.revoke.confirm"
|
||||
>
|
||||
{t("settings.plugins.revokeDialog.confirm")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
) : null}
|
||||
</PageBody>
|
||||
</PageShell>
|
||||
);
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
||||
|
||||
exports[`AK-UI-05 plugin catalog interim visual baseline > renders the catalog, consent-pending and empty states from ~/ui 1`] = `"<main data-ui-id="ui.plugins.interim.visualBaseline"><div class="flex w-full flex-col items-start" data-ui-id="ui.plugins.page"><div class="flex w-full items-start gap-4 border-b border-solid border-border-default bg-surface-neutral-secondary px-6 py-5 mobile:flex-col mobile:px-4"><div class="flex grow shrink-0 basis-0 flex-col items-start gap-1"><div class="flex items-center gap-2"><span class="text-heading- font-heading- text-icon-neutral-tertiary icon-wrapper-module_root__-l6uP"><svg data-visual-icon="true"></svg></span><h1 class="text-subtitle font-subtitle text-text-neutral-primary mobile:text-heading- mobile:font-heading-">settings.plugins.title</h1></div><p class="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">settings.plugins.description:acme</p></div></div><div class="flex w-full flex-col gap-6 p-6 mobile:p-4"><div class="flex w-full flex-col items-start gap-4" data-ui-id="ui.plugins.list"><div class="group/56067c50 flex flex-col items-start gap-4 rounded-md border border-solid border-border-default bg-surface-neutral-secondary px-4 py-4 shadow-sm w-full" data-ui-id="ui.plugins.item" data-plugin-row-id="pl-1" data-plugin-id="com.acme.outbound"><div class="flex w-full flex-col items-start gap-4"><div class="flex w-full flex-wrap items-start justify-between gap-3"><div class="flex min-w-0 flex-col items-start"><h2 class="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">com.acme.outbound</h2><span class="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">settings.plugins.versionInstalled:1.2.3/2020-01-02T09:00:00.000Z</span></div><div class="flex flex-none flex-wrap items-center gap-3"><div class="group/896531e4 flex items-center gap-2 rounded-round px-2.5 h-5 py-0.5 bg-surface-feedback-subtle-positive"><div class="flex h-1 w-1 flex-none flex-col items-start gap-2 rounded-round bg-icon-feedback-positive"></div><span class="whitespace-nowrap text-body-small-medium-0 font-body-small-medium-0 text-text-feedback-positive">shared.enabled</span></div><button class="group/3b777358 flex cursor-pointer items-center justify-center rounded-md border-none text-left focus-within:shadow-focus disabled:cursor-default disabled:bg-surface-neutral-disabled disabled:pointer-events-none hover:disabled:cursor-default hover:disabled:bg-surface-neutral-disabled active:disabled:cursor-default active:disabled:bg-surface-neutral-disabled h-8 gap-2 px-3 py-2 bg-brand-brand-secondary-surface-subtle-default hover:bg-brand-brand-secondary-surface-subtle-hover active:bg-brand-brand-secondary-surface-subtle-active" type="button" data-ui-id="ui.plugins.lifecycle.button" data-op="disable"><span class="text-body-default-regular-0 font-body-default-regular-0 group-disabled/3b777358:text-icon-neutral-disabled text-icon-neutral-primary icon-wrapper-module_root__-l6uP"><span class="icon-wrapper-module_root__-l6uP"><svg data-visual-icon="true"></svg></span></span><div class="hidden h-4 w-4 flex-none items-center justify-center gap-2"><div class="text-body-extra-small-regular-150 font-body-extra-small-regular-150 group-disabled/3b777358:text-icon-neutral-disabled group-hover/3b777358:group-disabled/3b777358:text-icon-neutral-on-solid group-active/3b777358:group-disabled/3b777358:text-icon-neutral-disabled text-icon-neutral-primary loader-module_root__-0Kak"></div></div><span class="whitespace-nowrap text-body-default-regular-0 font-body-default-regular-0 group-disabled/3b777358:text-text-neutral-disabled text-text-neutral-primary">shared.disable</span></button></div></div><div class="flex w-full flex-col items-start gap-3"><span class="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-tertiary uppercase">settings.plugins.capabilities</span><div class="flex w-full flex-col items-start gap-2"><div class="border-border-default bg-surface-neutral-secondary flex w-full flex-col items-start gap-2 rounded-md border border-solid p-3"><div class="flex w-full flex-wrap items-center justify-between gap-2"><span class="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">settings.plugins.capabilityNames.http_outbound</span><div class="group/896531e4 flex items-center gap-2 rounded-round px-2.5 h-5 py-0.5 bg-surface-feedback-subtle-positive"><div class="flex h-1 w-1 flex-none flex-col items-start gap-2 rounded-round bg-icon-feedback-positive"></div><span class="whitespace-nowrap text-body-small-medium-0 font-body-small-medium-0 text-text-feedback-positive">settings.plugins.consent.granted</span></div></div><span class="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">settings.plugins.consent.allowedHosts:api.example.test</span><span class="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary" data-ui-id="ui.plugins.Line truncated
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
import { buildPluginCatalogVM, type PluginCatalogRowInput, type PluginCatalogVM } from "@hivegrid/view-models";
|
||||
|
||||
import { PluginCatalogPage, type PluginCatalogActions } from "./PluginCatalogPage";
|
||||
|
||||
export const PLUGIN_CATALOG_INTERIM_VISUAL_SCREENS = ["catalog", "review-pending", "empty"] as const;
|
||||
|
||||
export type PluginCatalogInterimVisualScreen = (typeof PLUGIN_CATALOG_INTERIM_VISUAL_SCREENS)[number];
|
||||
|
||||
/** Install timestamps stay far in the past so the markup snapshot never depends
|
||||
* on the test run date (the screen renders absolute timestamps). */
|
||||
const GRANTED_ROW: PluginCatalogRowInput = {
|
||||
id: "pl-1",
|
||||
pluginId: "com.acme.outbound",
|
||||
version: "1.2.3",
|
||||
enabled: true,
|
||||
installedAtIso: "2020-01-02T09:00:00.000Z",
|
||||
capabilities: [
|
||||
{
|
||||
name: "http.outbound",
|
||||
scope: { allowedHosts: ["api.example.test"] },
|
||||
granted: true,
|
||||
grantedAtIso: "2020-01-02T09:30:00.000Z",
|
||||
hookName: null,
|
||||
known: true,
|
||||
risk: "high",
|
||||
productionAvailable: true,
|
||||
},
|
||||
{
|
||||
name: "log",
|
||||
scope: null,
|
||||
granted: true,
|
||||
grantedAtIso: "2020-01-02T09:30:00.000Z",
|
||||
hookName: null,
|
||||
known: true,
|
||||
risk: "low",
|
||||
productionAvailable: true,
|
||||
},
|
||||
],
|
||||
missingCapabilities: [],
|
||||
capabilityReviewDigest: "digest-granted",
|
||||
hasSettingsUi: true,
|
||||
manifestJson: JSON.stringify({ id: "com.acme.outbound", version: "1.2.3" }, null, 2),
|
||||
settingsHref: "/app/acme/settings/integrations/plugins/pl-1",
|
||||
auditHref: "/app/acme/settings/integrations/plugins/pl-1/audit",
|
||||
};
|
||||
|
||||
/** A disabled plugin whose consent is still missing — including one host binding
|
||||
* that this runtime can never approve (productionAvailable: false). */
|
||||
const PENDING_ROW: PluginCatalogRowInput = {
|
||||
id: "pl-2",
|
||||
pluginId: "com.acme.workflow-hook",
|
||||
version: "0.9.0",
|
||||
enabled: false,
|
||||
installedAtIso: "2020-02-03T10:00:00.000Z",
|
||||
capabilities: [
|
||||
{
|
||||
name: "hook:workflow.executed",
|
||||
scope: null,
|
||||
granted: false,
|
||||
grantedAtIso: null,
|
||||
hookName: "workflow.executed",
|
||||
known: false,
|
||||
risk: "medium",
|
||||
productionAvailable: true,
|
||||
},
|
||||
{
|
||||
name: "secret.read",
|
||||
scope: { keyPattern: "acme_*" },
|
||||
granted: false,
|
||||
grantedAtIso: null,
|
||||
hookName: null,
|
||||
known: true,
|
||||
risk: "critical",
|
||||
productionAvailable: false,
|
||||
},
|
||||
],
|
||||
missingCapabilities: ["hook:workflow.executed", "secret.read"],
|
||||
capabilityReviewDigest: "digest-pending",
|
||||
hasSettingsUi: false,
|
||||
manifestJson: JSON.stringify({ id: "com.acme.workflow-hook", version: "0.9.0" }, null, 2),
|
||||
settingsHref: "/app/acme/settings/integrations/plugins/pl-2",
|
||||
auditHref: "/app/acme/settings/integrations/plugins/pl-2/audit",
|
||||
};
|
||||
|
||||
/** No declared capabilities at all — enable is offered straight away. */
|
||||
const CAPABILITY_FREE_ROW: PluginCatalogRowInput = {
|
||||
id: "pl-3",
|
||||
pluginId: "com.acme.theme",
|
||||
version: "2.0.0",
|
||||
enabled: false,
|
||||
installedAtIso: "2020-03-04T11:00:00.000Z",
|
||||
capabilities: [],
|
||||
missingCapabilities: [],
|
||||
capabilityReviewDigest: "digest-free",
|
||||
hasSettingsUi: false,
|
||||
manifestJson: JSON.stringify({ id: "com.acme.theme", version: "2.0.0" }, null, 2),
|
||||
settingsHref: "/app/acme/settings/integrations/plugins/pl-3",
|
||||
auditHref: "/app/acme/settings/integrations/plugins/pl-3/audit",
|
||||
};
|
||||
|
||||
export function createPluginCatalogInterimVisualVMs(): Record<PluginCatalogInterimVisualScreen, PluginCatalogVM> {
|
||||
return {
|
||||
catalog: buildPluginCatalogVM({
|
||||
tenantSlug: "acme",
|
||||
canManage: true,
|
||||
canAudit: true,
|
||||
rows: [GRANTED_ROW, CAPABILITY_FREE_ROW],
|
||||
}),
|
||||
"review-pending": buildPluginCatalogVM({
|
||||
tenantSlug: "acme",
|
||||
canManage: true,
|
||||
canAudit: false,
|
||||
rows: [PENDING_ROW],
|
||||
}),
|
||||
empty: buildPluginCatalogVM({ tenantSlug: "acme", canManage: true, canAudit: true, rows: [] }),
|
||||
};
|
||||
}
|
||||
|
||||
const noOpActions: PluginCatalogActions = {
|
||||
onEnable: () => undefined,
|
||||
onDisable: () => undefined,
|
||||
onApproveCapabilities: () => undefined,
|
||||
onRevokeCapability: () => undefined,
|
||||
};
|
||||
|
||||
export function PluginCatalogInterimVisualFixture({ screen }: { screen: PluginCatalogInterimVisualScreen }): React.JSX.Element {
|
||||
const vm = createPluginCatalogInterimVisualVMs()[screen];
|
||||
return <PluginCatalogPage vm={vm} actions={noOpActions} />;
|
||||
}
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
// @vitest-environment jsdom
|
||||
import "@testing-library/jest-dom/vitest";
|
||||
import React from "react";
|
||||
import { MemoryRouter } from "react-router";
|
||||
import { fireEvent, render } from "@testing-library/react";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { PLUGIN_CATALOG_INTERIM_VISUAL_SCREENS, PluginCatalogInterimVisualFixture } from "./plugin-catalog-interim.visual-fixture";
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({
|
||||
t: (key: string, values?: Record<string, unknown>) => (values ? `${key}:${Object.values(values).join("/")}` : key),
|
||||
i18n: { language: "de" },
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("~/locale/format", () => ({
|
||||
useLocaleFormatters: () => ({
|
||||
locale: "de",
|
||||
number: (value: number) => String(value),
|
||||
currency: (value: number, currency: string) => `${value.toFixed(2)} ${currency}`,
|
||||
currencyFromCents: (value: number, currency: string) => `${(value / 100).toFixed(2)} ${currency}`,
|
||||
percent: (value: number) => `${value}%`,
|
||||
compact: (value: number) => String(value),
|
||||
date: (value: Date | number | string) => new Date(value).toISOString(),
|
||||
dateTime: (value: Date | number | string) => new Date(value).toISOString(),
|
||||
relativeTime: (value: number, unit: string) => `${value} ${unit}`,
|
||||
relativeDate: (value: Date | number | string) => new Date(value).toISOString(),
|
||||
}),
|
||||
}));
|
||||
|
||||
describe("AK-UI-05 plugin catalog interim visual baseline", () => {
|
||||
it("renders the catalog, consent-pending and empty states from ~/ui", () => {
|
||||
const { container } = render(
|
||||
<MemoryRouter>
|
||||
<main data-ui-id="ui.plugins.interim.visualBaseline">
|
||||
{PLUGIN_CATALOG_INTERIM_VISUAL_SCREENS.map((screen) => (
|
||||
<PluginCatalogInterimVisualFixture key={screen} screen={screen} />
|
||||
))}
|
||||
</main>
|
||||
</MemoryRouter>
|
||||
);
|
||||
|
||||
expect(container.querySelectorAll("[data-ui-id='ui.plugins.page']")).toHaveLength(3);
|
||||
// Two screens carry rows, the third is the empty state.
|
||||
expect(container.querySelectorAll("[data-ui-id='ui.plugins.list']")).toHaveLength(2);
|
||||
expect(container.querySelectorAll("[data-ui-id='ui.plugins.empty']")).toHaveLength(1);
|
||||
expect(container.querySelectorAll("[data-ui-id='ui.plugins.item']")).toHaveLength(3);
|
||||
// Only the enabled plugin with a settings entry links into its settings UI.
|
||||
expect(container.querySelectorAll("[data-ui-id='ui.plugins.settings.open']")).toHaveLength(1);
|
||||
// The consent-pending screen has no audit permission, so only the catalog links out.
|
||||
expect(container.querySelectorAll("[data-ui-id='ui.plugins.audit.open']")).toHaveLength(2);
|
||||
// Consent still missing -> the review entry point replaces the enable button.
|
||||
expect(container.querySelectorAll("[data-ui-id='ui.plugins.capabilityReview.toggle']")).toHaveLength(1);
|
||||
// Disable (enabled plugin) + Enable (capability-free plugin).
|
||||
expect(container.querySelectorAll("[data-ui-id='ui.plugins.lifecycle.button']")).toHaveLength(2);
|
||||
expect(container.querySelectorAll("[data-ui-id='ui.plugins.capability.revoke.button']")).toHaveLength(2);
|
||||
// Dialogs only mount while open (the ~/ui Dialog emits an empty hidden heading otherwise).
|
||||
expect(container.querySelectorAll("[data-ui-id='ui.plugins.capabilityReview.form']")).toHaveLength(0);
|
||||
|
||||
const stableMarkup = container.innerHTML.replace(/<svg\b[^>]*>[\s\S]*?<\/svg>/gu, '<svg data-visual-icon="true"></svg>');
|
||||
expect(stableMarkup).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("opens the capability review as a real ~/ui dialog and gates approval on every tick", async () => {
|
||||
const { findByText, container } = render(
|
||||
<MemoryRouter>
|
||||
<PluginCatalogInterimVisualFixture screen="review-pending" />
|
||||
</MemoryRouter>
|
||||
);
|
||||
|
||||
const reviewToggle = container.querySelector("[data-ui-id='ui.plugins.capabilityReview.toggle']");
|
||||
expect(reviewToggle).not.toBeNull();
|
||||
fireEvent.click(reviewToggle as HTMLButtonElement);
|
||||
|
||||
expect(await findByText("settings.plugins.consent.reviewTitle:com.acme.workflow-hook")).toBeInTheDocument();
|
||||
const dialog = document.querySelector("[data-ui-id='ui.plugins.capabilityReview.form']");
|
||||
expect(dialog).not.toBeNull();
|
||||
|
||||
const approve = dialog?.querySelector("[data-ui-id='ui.plugins.capabilityReview.button']");
|
||||
expect(approve).toBeDisabled();
|
||||
|
||||
const checkboxes = dialog?.querySelectorAll("[data-ui-id='ui.plugins.capabilityReview.checkbox']") ?? [];
|
||||
expect(checkboxes).toHaveLength(2);
|
||||
// secret.read is not production-available -> it can never be ticked, so the
|
||||
// approval stays blocked no matter what the manager does.
|
||||
expect(checkboxes[1]).toBeDisabled();
|
||||
expect(dialog?.querySelector("[data-ui-id='ui.plugins.capabilityReview.unavailableReason']")).not.toBeNull();
|
||||
|
||||
fireEvent.click(checkboxes[0] as HTMLButtonElement);
|
||||
expect(approve).toBeDisabled();
|
||||
});
|
||||
|
||||
it("confirms a capability revoke through a destructive dialog", async () => {
|
||||
const { findByText, container } = render(
|
||||
<MemoryRouter>
|
||||
<PluginCatalogInterimVisualFixture screen="catalog" />
|
||||
</MemoryRouter>
|
||||
);
|
||||
|
||||
const revoke = container.querySelector("[data-ui-id='ui.plugins.capability.revoke.button']");
|
||||
expect(revoke).not.toBeNull();
|
||||
fireEvent.click(revoke as HTMLButtonElement);
|
||||
|
||||
expect(await findByText("settings.plugins.revokeDialog.title")).toBeInTheDocument();
|
||||
const dialog = document.querySelector("[data-ui-id='ui.plugins.capability.revoke.form']");
|
||||
expect(dialog).not.toBeNull();
|
||||
expect(dialog?.querySelector("[data-ui-id='ui.plugins.capability.revoke.confirm']")).not.toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user