peppa/apps/web/components/FeatureGate.tsx
peppa-bot acb6e3fb81
All checks were successful
peppa/lint lint: success за 1с
peppa/typecheck typecheck: success за 46с
peppa/build build: success за 34с
peppa/test test: success за 1325с
peppa-ci / ci (pull_request) Successful in 24m11s
PEP-224: статус функций из мониторинга (сведено с main после PEP-225)
Функция → мониторинги (core/feature-status.ts), серая кнопка входа через eGov и статус MCP,
отказ startEgovFlow, журнал и сообщения в канал. После переезда живых обновлений на
WebSocket (PEP-225): область `features` в LIVE_PLAIN_SCOPES, открыта без входа (SSE и
WebSocket с `anonymous: true` — только открытые области), смотрится по таймеру вместе с
`observe`, смена сбрасывает кэш статусов.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 15:00:03 +00:00

42 lines
2.3 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// PEP-224: a feature that depends on a failing service (Observability) — grey, inactive, with a
// plain caption and the time it failed. Available — its children as they are; unstable — the
// children with a note «может работать с задержками». For any new feature: pass `featureGateView`.
import type { ReactNode } from "react";
import { CircleSlash, Clock } from "lucide-react";
import { serverTimezone, type FeatureGateView } from "@peppa/core";
import { getLocale, getT } from "@/lib/i18n";
import { intlLocale } from "@peppa/shared/i18n";
import { cn } from "@/lib/utils";
export async function FeatureGate({ view, label, title, children, className }: { view: FeatureGateView; /** The grey button's text (a button-like control). */ label?: ReactNode; /** A grey status instead (an instruction, a section). */ title?: ReactNode; children: ReactNode; className?: string }) {
if (view.state === "available") return <>{children}</>;
const t = await getT();
if (view.state === "degraded")
return (
<>
{children}
<p className="m-0 flex items-center gap-1.5 text-xs text-warn" data-feature={view.name} data-feature-state="degraded">
<Clock className="size-3.5 shrink-0" /> {t.text(view.text)}
</p>
</>
);
const since = view.since ? new Date(view.since).toLocaleTimeString(intlLocale(await getLocale()), { hour: "2-digit", minute: "2-digit", timeZone: serverTimezone() }) : null;
return (
<div className={cn("flex w-full flex-col gap-1.5", className)} data-feature={view.name} data-feature-state="unavailable">
{label ? (
<button type="button" disabled aria-disabled="true" className="inline-flex h-10 w-full cursor-not-allowed items-center justify-center gap-2 rounded-md border border-dashed bg-muted px-4 text-sm font-medium text-muted-foreground opacity-80">
<CircleSlash className="size-4" /> {label}
</button>
) : (
<div role="status" aria-disabled="true" className="flex items-center gap-2 rounded-lg border border-dashed bg-muted px-4 py-3 text-sm font-medium text-muted-foreground">
<CircleSlash className="size-4 shrink-0" /> {title}
</div>
)}
<p className="m-0 text-xs text-muted-foreground">
{t.text(view.text)}
{since ? " · " + t("с {time}", { time: since }) : ""}
</p>
</div>
);
}