// PEP-218: production errors read from Bugsink on the server — summary, filters, rows and the // error card blocks. «Инженер» and the superadmin (`tech`) also see code places, releases, // stacks and tags; «Продакт» — the title, how often, when and the bug task. import Link from "next/link"; import { Bug, TrendingUp } from "lucide-react"; import type { ErrorDetail, ErrorFilter, ErrorRow, ErrorScope, ErrorsOverview, ErrorState } from "@peppa/core"; import { m, type Translator } from "@peppa/shared/i18n"; import { Hidden } from "@/components/cards"; import { ago, Empty, Key, Notice } from "@/components/common"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Card } from "@/components/ui/card"; import { Input, NativeSelect } from "@/components/ui/input"; import { errorAction } from "@/app/(app)/errors/actions"; const STATE_LABEL: Record = { unresolved: m("не решена"), resolved: m("решена"), muted: m("приглушена") }; const STATE_TONE: Record = { unresolved: "danger", resolved: "ok", muted: "muted" }; const hhmm = (d: Date, t: Translator) => d.toLocaleTimeString(t.locale === "en" ? "en-GB" : "ru-RU", { hour: "2-digit", minute: "2-digit" }); /** Bugsink failed: say so; the data below (if any) is from the cache. */ export function ErrorsDown({ down, at, tech, t }: { down: boolean; at: Date | null; tech: boolean; t: Translator }) { if (!down) return null; return ( {tech ? at ? // glossary-ignore: «Инженер» and the superadmin only. t("Bugsink не отвечает — показаны данные на {time}.", { time: hhmm(at, t) }) : // glossary-ignore: «Инженер» and the superadmin only. t("Bugsink не отвечает, данных пока нет. Загляните через минуту.") : at ? t("Учёт ошибок не отвечает — показаны данные на {time}.", { time: hhmm(at, t) }) : t("Учёт ошибок не отвечает. Загляните через минуту.")} ); } export function ErrorStateBadge({ state, t }: { state: ErrorState; t: Translator }) { return {t(STATE_LABEL[state])}; } /** Superadmin summary: one line per Bugsink project. */ export function ErrorsSummary({ ov, t, hrefFor }: { ov: ErrorsOverview; t: Translator; hrefFor: (bugsinkId: number) => string }) { if (!ov.projects.length) return {t("Проектов учёта ошибок нет.")}; return (
{ov.projects.map((p) => ( ))}
{t("Проект")} {t("Нерешённых")} {t("Новых за сутки")} {t("За час")}
{p.name} {p.projectKey ? {p.projectKey} : {t("не подключён")}} {p.unresolved}{p.more ? "+" : ""} {p.newDay} {p.growing ? {t("растёт")} : null} {p.lastHour} / {p.dayAvg}
); } /** Errors as cards; the title opens the error card. */ export function ErrorRows({ rows, tech, from, t, showProject = true }: { rows: ErrorRow[]; tech: boolean; from: string; t: Translator; showProject?: boolean }) { if (!rows.length) return {t("Ошибок нет.")}; return (
{rows.map((r) => (
{r.title} {r.state !== "unresolved" ? : null}
{tech && r.culprit ? {r.culprit} : null} {showProject ? {r.bugsinkName} : null} {t.n(r.events, "{n} раз", "{n} раза", "{n} раз")} {t("впервые {ago}", { ago: ago(r.firstSeen, t) })} {t("последний раз {ago}", { ago: ago(r.lastSeen, t) })} {/* glossary-ignore: the release is shown to «Инженер» and the superadmin only */} {tech && r.release ? {t("релиз {sha}", { sha: r.release.slice(0, 8) })} : null} {r.taskKey ? {r.taskKey} : null}
))}
); } /** Filters (GET form): project, state, environment, release, text, order. */ export function ErrorFilters({ action, scope, f, keep, t, showProject = true }: { action: string; scope: ErrorScope; f: ErrorFilter; keep: Record; t: Translator; showProject?: boolean }) { return (
{Object.entries(keep).map(([k, v]) => ( ))} {showProject && scope.projects.length > 1 ? ( {scope.projects.map((p) => ( ))} ) : null} {scope.tech ? ( <> {/* glossary-ignore: «Инженер» and the superadmin only */} ) : null}
); } /** The filter from the page's query string. */ export function errorFilterFrom(sp: Record): ErrorFilter { const state = sp.state === "resolved" || sp.state === "muted" || sp.state === "all" ? sp.state : "unresolved"; return { bugsink: sp.bp && /^\d+$/.test(sp.bp) ? Number(sp.bp) : undefined, state, environment: sp.env?.trim() || undefined, release: sp.rel?.trim() || undefined, q: sp.q?.trim() || undefined, sort: sp.sort === "digested_event_count" ? "digested_event_count" : "last_seen", cursor: sp.cursor || undefined, }; } /** «Решено», «Приглушить»/«Вернуть», «Завести задачу» on the error card. */ export function ErrorActions({ d, back, t }: { d: ErrorDetail; back: string; t: Translator }) { const btn = (action: string, label: string, variant: "default" | "secondary" | "ghost" = "secondary") => (
); return (
{d.row.taskKey ? null : d.projectId != null ? btn("task", t("Завести задачу"), "default") : null} {d.row.state === "resolved" ? btn("reopen", t("Открыть снова")) : btn("resolve", t("Решено"))} {d.row.state === "muted" ? btn("unmute", t("Вернуть")) : d.row.state === "unresolved" ? btn("mute", t("Приглушить"), "ghost") : null}
); } /** Stack frames, innermost first; code around the line where the SDK sent it. */ export function ErrorStack({ d, t }: { d: ErrorDetail; t: Translator }) { if (!d.frames.length) return {t("Кадров нет.")}; return (
{d.frames.map((f, n) => (
{f.fn ?? "?"} {f.file}{f.line != null ? `:${f.line}` : ""}
{f.context.length ? (
              {f.context.map(([no, text, hit], k) => (
                
{no ?? ""} {text}
))}
) : n === 0 ? (
{t("Кода вокруг строки нет: его не прислали.")}
) : null}
))}
); }