feat(BIT-247): consolidate error reporting repo from OTT
Merge ingest-api, collector-worker, admin-ui, database/error_reporting, deploy/lxc, docker-compose, and deployment docs into the dedicated repository. Paths updated for repo root (ER_REPO_ROOT, systemd WorkingDirectory). Root README documents layout. Co-Authored-By: Paperclip <[email protected]>
This commit is contained in:
1 parent
eeb5039a3c
commit
b0b733d5e1
88 files changed
+19321
No files matched your search
@@ -0,0 +1,5 @@
|
||||
# Base URL da API admin (Fastify) quando existir (BIT-179). Sem trailing slash.
|
||||
# ERROR_REPORTING_ADMIN_API_BASE=http://127.0.0.1:3050
|
||||
|
||||
# Apenas desenvolvimento: carrega dados fictícios para validar layout sem API.
|
||||
# ERROR_REPORTING_UI_DEMO=1
|
||||
@@ -0,0 +1,6 @@
|
||||
.next/
|
||||
node_modules/
|
||||
out/
|
||||
.env
|
||||
.env.local
|
||||
*.tsbuildinfo
|
||||
@@ -0,0 +1,41 @@
|
||||
@import "bootstrap/scss/bootstrap";
|
||||
|
||||
/* Velzon-adjacent shell (Bootstrap 5; no proprietary template assets). */
|
||||
.er-app {
|
||||
--er-sidebar-width: 260px;
|
||||
}
|
||||
|
||||
.er-sidebar {
|
||||
width: var(--er-sidebar-width);
|
||||
background: linear-gradient(180deg, #1a1d21 0%, #212529 40%, #1a1d21 100%);
|
||||
}
|
||||
|
||||
.er-nav-link {
|
||||
border-radius: 0.35rem;
|
||||
padding: 0.5rem 0.75rem;
|
||||
}
|
||||
|
||||
.er-nav-link:hover,
|
||||
.er-nav-link:focus {
|
||||
background: rgba(255, 255, 255, 0.06);
|
||||
color: #fff !important;
|
||||
}
|
||||
|
||||
.er-topbar {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 1020;
|
||||
}
|
||||
|
||||
.er-main {
|
||||
background-color: #f3f6f9;
|
||||
min-height: calc(100vh - 72px);
|
||||
}
|
||||
|
||||
pre.er-stack {
|
||||
max-height: 320px;
|
||||
overflow: auto;
|
||||
font-size: 0.8rem;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import Link from "next/link";
|
||||
import { AppShell } from "@/components/AppShell";
|
||||
|
||||
export default function IncidentNotFound() {
|
||||
return (
|
||||
<AppShell
|
||||
title="Incidente não encontrado"
|
||||
breadcrumb={[
|
||||
{ label: "Painel", href: "/" },
|
||||
{ label: "Incidentes", href: "/incidents" },
|
||||
{ label: "404" },
|
||||
]}
|
||||
>
|
||||
<p>O incidente pedido não existe ou foi removido.</p>
|
||||
<Link href="/incidents" className="btn btn-primary">
|
||||
Voltar à lista
|
||||
</Link>
|
||||
</AppShell>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
import Link from "next/link";
|
||||
import { notFound } from "next/navigation";
|
||||
import { AppShell } from "@/components/AppShell";
|
||||
import { DataAlert } from "@/components/DataAlert";
|
||||
import { IncidentNotes } from "@/components/IncidentNotes";
|
||||
import { SeverityBadge } from "@/components/SeverityBadge";
|
||||
import { StateBadge } from "@/components/StateBadge";
|
||||
import { formatDateTime } from "@/lib/format";
|
||||
import { fetchIncidentDetail } from "@/lib/incidents-data";
|
||||
|
||||
export default async function IncidentDetailPage(props: { params: Promise<{ id: string }> }) {
|
||||
const { id } = await props.params;
|
||||
const _decoded = decodeURIComponent(id);
|
||||
const _result = await fetchIncidentDetail(_decoded);
|
||||
|
||||
if (!_result.ok) {
|
||||
if (_result.error === "not_found") {
|
||||
notFound();
|
||||
}
|
||||
return (
|
||||
<AppShell
|
||||
title="Incidente"
|
||||
breadcrumb={[
|
||||
{ label: "Painel", href: "/" },
|
||||
{ label: "Incidentes", href: "/incidents" },
|
||||
{ label: "Detalhe" },
|
||||
]}
|
||||
>
|
||||
<DataAlert
|
||||
variant={_result.error === "not_configured" ? "warning" : "danger"}
|
||||
title={_result.error === "not_configured" ? "Detalhe indisponível" : "Erro de ligação"}
|
||||
body={_result.message}
|
||||
/>
|
||||
<Link href="/incidents" className="btn btn-outline-secondary">
|
||||
Voltar à lista
|
||||
</Link>
|
||||
</AppShell>
|
||||
);
|
||||
}
|
||||
|
||||
const _inc = _result.incident;
|
||||
const _occ = _inc.occurrences[0];
|
||||
|
||||
return (
|
||||
<AppShell
|
||||
title={_inc.title}
|
||||
breadcrumb={[
|
||||
{ label: "Painel", href: "/" },
|
||||
{ label: "Incidentes", href: "/incidents" },
|
||||
{ label: _inc.fingerprint },
|
||||
]}
|
||||
>
|
||||
{_result.source === "demo" ? (
|
||||
<p className="text-muted small">
|
||||
Dados de demonstração — stack e contexto alinhados com o modelo relacional (BIT-178).
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
<div className="row g-3">
|
||||
<div className="col-lg-8">
|
||||
<div className="card mb-3">
|
||||
<div className="card-header d-flex flex-wrap gap-2 align-items-center justify-content-between">
|
||||
<div className="d-flex flex-wrap gap-2 align-items-center">
|
||||
<StateBadge state={_inc.currentState} />
|
||||
<SeverityBadge severity={_inc.severity} />
|
||||
</div>
|
||||
<span className="small text-muted font-monospace">id: {_inc.id}</span>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
<dl className="row mb-0">
|
||||
<dt className="col-sm-3">Projeto</dt>
|
||||
<dd className="col-sm-9">
|
||||
<code>{_inc.projectSlug}</code>
|
||||
</dd>
|
||||
<dt className="col-sm-3">Fingerprint</dt>
|
||||
<dd className="col-sm-9">
|
||||
<code>{_inc.fingerprint}</code>
|
||||
</dd>
|
||||
<dt className="col-sm-3">Origem (ingest)</dt>
|
||||
<dd className="col-sm-9">{_inc.ingestKeyLabel ?? "—"}</dd>
|
||||
<dt className="col-sm-3">Primeira vista</dt>
|
||||
<dd className="col-sm-9">{formatDateTime(_inc.firstSeenAt)}</dd>
|
||||
<dt className="col-sm-3">Última vista</dt>
|
||||
<dd className="col-sm-9">{formatDateTime(_inc.lastSeenAt)}</dd>
|
||||
<dt className="col-sm-3">Ocorrências</dt>
|
||||
<dd className="col-sm-9 font-monospace">{_inc.occurrencesCount}</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="card mb-3">
|
||||
<div className="card-header fw-semibold">Meta (incidente)</div>
|
||||
<div className="card-body">
|
||||
{_inc.metadataJson && Object.keys(_inc.metadataJson).length > 0 ? (
|
||||
<pre className="er-stack bg-light border rounded p-3 mb-0">
|
||||
{JSON.stringify(_inc.metadataJson, null, 2)}
|
||||
</pre>
|
||||
) : (
|
||||
<p className="text-muted mb-0">Sem metadados agregados neste incidente.</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="card mb-3">
|
||||
<div className="card-header fw-semibold">Última ocorrência — mensagem</div>
|
||||
<div className="card-body">
|
||||
{_occ ? (
|
||||
<>
|
||||
<p className="mb-2">{_occ.message}</p>
|
||||
<p className="small text-muted mb-0">
|
||||
<span className="me-2">
|
||||
Nível: <code>{_occ.levelRaw}</code>
|
||||
</span>
|
||||
· {formatDateTime(_occ.occurredAt)}
|
||||
</p>
|
||||
</>
|
||||
) : (
|
||||
<p className="text-muted mb-0">Sem ocorrências carregadas nesta vista.</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="card mb-3">
|
||||
<div className="card-header fw-semibold">Stack trace</div>
|
||||
<div className="card-body">
|
||||
{_occ?.stacktrace ? (
|
||||
<pre className="er-stack bg-dark text-light rounded p-3 mb-0">{_occ.stacktrace}</pre>
|
||||
) : (
|
||||
<p className="text-muted mb-0">Sem stack trace na última ocorrência.</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="card mb-3">
|
||||
<div className="card-header fw-semibold">Contexto (JSON)</div>
|
||||
<div className="card-body">
|
||||
{_occ?.contextJson && Object.keys(_occ.contextJson).length > 0 ? (
|
||||
<pre className="er-stack bg-light border rounded p-3 mb-0">
|
||||
{JSON.stringify(_occ.contextJson, null, 2)}
|
||||
</pre>
|
||||
) : (
|
||||
<p className="text-muted mb-0">Sem contexto estruturado na última ocorrência.</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="col-lg-4">
|
||||
<div className="card mb-3">
|
||||
<div className="card-header fw-semibold">Notas</div>
|
||||
<div className="card-body">
|
||||
<IncidentNotes incidentId={_inc.id} />
|
||||
</div>
|
||||
</div>
|
||||
<Link href="/incidents" className="btn btn-outline-secondary w-100">
|
||||
Voltar à lista
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</AppShell>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
import Link from "next/link";
|
||||
import { AppShell } from "@/components/AppShell";
|
||||
import { DataAlert } from "@/components/DataAlert";
|
||||
import { SeverityBadge } from "@/components/SeverityBadge";
|
||||
import { StateBadge } from "@/components/StateBadge";
|
||||
import { formatDateTime } from "@/lib/format";
|
||||
import { fetchIncidentList } from "@/lib/incidents-data";
|
||||
import type { IncidentState, Severity } from "@/lib/types";
|
||||
|
||||
type SearchParams = Promise<Record<string, string | string[] | undefined>>;
|
||||
|
||||
const _states: IncidentState[] = ["open", "investigating", "resolved", "ignored"];
|
||||
const _severities: Severity[] = ["critical", "high", "medium", "low", "info"];
|
||||
|
||||
function _param(sp: Record<string, string | string[] | undefined>, key: string): string {
|
||||
const _v = sp[key];
|
||||
if (Array.isArray(_v)) {
|
||||
return _v[0] ?? "";
|
||||
}
|
||||
return _v ?? "";
|
||||
}
|
||||
|
||||
export default async function IncidentsPage(props: { searchParams: SearchParams }) {
|
||||
const _sp = await props.searchParams;
|
||||
const _state = _param(_sp, "state") as IncidentState | "";
|
||||
const _severity = _param(_sp, "severity") as Severity | "";
|
||||
const _project = _param(_sp, "project");
|
||||
const _q = _param(_sp, "q");
|
||||
|
||||
// Fetch unfiltered list first to build the project dropdown options.
|
||||
const _allList = await fetchIncidentList({});
|
||||
const _projectSlugs: string[] = _allList.ok
|
||||
? [...new Set(_allList.incidents.map((r) => r.projectSlug))].sort()
|
||||
: [];
|
||||
|
||||
const _list = await fetchIncidentList({
|
||||
state: _states.includes(_state as IncidentState) ? _state : "",
|
||||
severity: _severities.includes(_severity as Severity) ? _severity : "",
|
||||
project: _project,
|
||||
q: _q,
|
||||
});
|
||||
|
||||
return (
|
||||
<AppShell
|
||||
title="Incidentes"
|
||||
breadcrumb={[{ label: "Painel", href: "/" }, { label: "Incidentes" }]}
|
||||
>
|
||||
{_list.ok && _list.source === "demo" ? (
|
||||
<p className="text-muted small">
|
||||
Dados de demonstração — ligue <code>ERROR_REPORTING_ADMIN_API_BASE</code> para dados reais
|
||||
(BIT-179).
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
{!_list.ok ? (
|
||||
<DataAlert
|
||||
variant={_list.error === "not_configured" ? "warning" : "danger"}
|
||||
title={_list.error === "not_configured" ? "Lista indisponível" : "Erro de ligação"}
|
||||
body={_list.message}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
<div className="card mb-4">
|
||||
<div className="card-header fw-semibold">Filtros</div>
|
||||
<div className="card-body">
|
||||
<form className="row g-3 align-items-end" method="get" action="/incidents">
|
||||
<div className="col-md-2">
|
||||
<label className="form-label" htmlFor="f-project">
|
||||
Projeto
|
||||
</label>
|
||||
<select
|
||||
id="f-project"
|
||||
name="project"
|
||||
className="form-select"
|
||||
defaultValue={_project}
|
||||
>
|
||||
<option value="">Todos</option>
|
||||
{_projectSlugs.map((s) => (
|
||||
<option key={s} value={s}>
|
||||
{s}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="col-md-2">
|
||||
<label className="form-label" htmlFor="f-state">
|
||||
Estado
|
||||
</label>
|
||||
<select id="f-state" name="state" className="form-select" defaultValue={_state}>
|
||||
<option value="">Todos</option>
|
||||
{_states.map((s) => (
|
||||
<option key={s} value={s}>
|
||||
{s}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="col-md-2">
|
||||
<label className="form-label" htmlFor="f-severity">
|
||||
Severidade
|
||||
</label>
|
||||
<select
|
||||
id="f-severity"
|
||||
name="severity"
|
||||
className="form-select"
|
||||
defaultValue={_severity}
|
||||
>
|
||||
<option value="">Todas</option>
|
||||
{_severities.map((s) => (
|
||||
<option key={s} value={s}>
|
||||
{s}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="col-md-4">
|
||||
<label className="form-label" htmlFor="f-q">
|
||||
Texto
|
||||
</label>
|
||||
<input
|
||||
id="f-q"
|
||||
name="q"
|
||||
type="search"
|
||||
className="form-control"
|
||||
placeholder="Título ou fingerprint"
|
||||
defaultValue={_q}
|
||||
/>
|
||||
</div>
|
||||
<div className="col-md-2 d-grid">
|
||||
<button type="submit" className="btn btn-primary">
|
||||
Aplicar
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="card">
|
||||
<div className="card-header d-flex justify-content-between align-items-center">
|
||||
<span className="fw-semibold">Resultados</span>
|
||||
{_list.ok ? (
|
||||
<span className="badge text-bg-light text-dark border">{_list.incidents.length}</span>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="card-body p-0">
|
||||
{_list.ok && _list.incidents.length === 0 ? (
|
||||
<p className="p-4 mb-0 text-muted">Nenhum incidente corresponde aos filtros.</p>
|
||||
) : null}
|
||||
{_list.ok && _list.incidents.length > 0 ? (
|
||||
<div className="table-responsive">
|
||||
<table className="table table-hover table-striped mb-0 align-middle">
|
||||
<thead className="table-light">
|
||||
<tr>
|
||||
<th scope="col">Estado</th>
|
||||
<th scope="col">Severidade</th>
|
||||
<th scope="col">Projeto</th>
|
||||
<th scope="col">Título</th>
|
||||
<th scope="col" className="text-end">
|
||||
Ocorrências
|
||||
</th>
|
||||
<th scope="col">Última vista</th>
|
||||
<th scope="col" />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{_list.incidents.map((row) => (
|
||||
<tr key={row.id}>
|
||||
<td>
|
||||
<StateBadge state={row.currentState} />
|
||||
</td>
|
||||
<td>
|
||||
<SeverityBadge severity={row.severity} />
|
||||
</td>
|
||||
<td>
|
||||
<code className="small">{row.projectSlug}</code>
|
||||
</td>
|
||||
<td className="text-break">{row.title}</td>
|
||||
<td className="text-end font-monospace">{row.occurrencesCount}</td>
|
||||
<td className="text-nowrap small text-muted">
|
||||
{formatDateTime(row.lastSeenAt)}
|
||||
</td>
|
||||
<td className="text-end">
|
||||
<Link
|
||||
href={`/incidents/${encodeURIComponent(row.id)}`}
|
||||
className="btn btn-sm btn-outline-primary"
|
||||
>
|
||||
Detalhe
|
||||
</Link>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
</AppShell>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import type { Metadata } from "next";
|
||||
import "./globals.scss";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "BitReport — Error reporting",
|
||||
description: "Painel central de incidentes (BIT-181)",
|
||||
};
|
||||
|
||||
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<html lang="pt">
|
||||
<body className="bg-body text-body">{children}</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
import Link from "next/link";
|
||||
import { AppShell } from "@/components/AppShell";
|
||||
import { DataAlert } from "@/components/DataAlert";
|
||||
import { KpiCard } from "@/components/KpiCard";
|
||||
import { computeKpis, fetchIncidentList } from "@/lib/incidents-data";
|
||||
|
||||
export default async function DashboardPage() {
|
||||
const _list = await fetchIncidentList({});
|
||||
|
||||
if (!_list.ok) {
|
||||
return (
|
||||
<AppShell title="Painel" breadcrumb={[{ label: "Painel" }]}>
|
||||
<DataAlert
|
||||
variant={_list.error === "not_configured" ? "warning" : "danger"}
|
||||
title={_list.error === "not_configured" ? "Dados indisponíveis" : "Erro de ligação"}
|
||||
body={_list.message}
|
||||
/>
|
||||
<p className="text-muted small mb-0">
|
||||
Com <code>ERROR_REPORTING_UI_DEMO=1</code> pode visualizar KPIs de demonstração sem API.
|
||||
</p>
|
||||
</AppShell>
|
||||
);
|
||||
}
|
||||
|
||||
const _kpis = computeKpis(_list.incidents);
|
||||
const _sourceHint =
|
||||
_list.source === "demo" ? (
|
||||
<p className="text-muted small">
|
||||
Modo demonstração (<code>ERROR_REPORTING_UI_DEMO=1</code>) — substituir por API em
|
||||
produção.
|
||||
</p>
|
||||
) : null;
|
||||
|
||||
return (
|
||||
<AppShell title="Painel" breadcrumb={[{ label: "Painel" }]}>
|
||||
{_sourceHint}
|
||||
<div className="row g-3 mb-4">
|
||||
<KpiCard label="Total (vista actual)" value={_kpis.total} variant="dark" />
|
||||
<KpiCard label="Abertos" value={_kpis.open} variant="danger" />
|
||||
<KpiCard label="Em investigação" value={_kpis.investigating} variant="warning" />
|
||||
<KpiCard label="Resolvidos" value={_kpis.resolved} variant="success" />
|
||||
</div>
|
||||
<div className="row g-3 mb-4">
|
||||
<div className="col-md-4">
|
||||
<KpiCard label="Ignorados" value={_kpis.ignored} variant="secondary" />
|
||||
</div>
|
||||
</div>
|
||||
<div className="card">
|
||||
<div className="card-header d-flex align-items-center justify-content-between">
|
||||
<span className="fw-semibold">Atalhos</span>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
<p className="mb-3">
|
||||
Consulte a lista completa com filtros por estado, severidade e texto.
|
||||
</p>
|
||||
<Link href="/incidents" className="btn btn-primary">
|
||||
Ver incidentes
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</AppShell>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
import Link from "next/link";
|
||||
import type { ReactNode } from "react";
|
||||
|
||||
export function AppShell({
|
||||
children,
|
||||
title,
|
||||
breadcrumb,
|
||||
}: {
|
||||
children: ReactNode;
|
||||
title: string;
|
||||
breadcrumb?: { label: string; href?: string }[];
|
||||
}) {
|
||||
return (
|
||||
<div className="er-app d-flex min-vh-100">
|
||||
<aside className="er-sidebar text-white d-flex flex-column flex-shrink-0 p-3">
|
||||
<Link href="/" className="text-white text-decoration-none fs-5 fw-semibold mb-4">
|
||||
BitReport
|
||||
<span className="d-block small text-white-50 fw-normal">Error reporting</span>
|
||||
</Link>
|
||||
<nav className="nav flex-column gap-1">
|
||||
<Link className="nav-link text-white-50 er-nav-link" href="/">
|
||||
Painel
|
||||
</Link>
|
||||
<Link className="nav-link text-white-50 er-nav-link" href="/incidents">
|
||||
Incidentes
|
||||
</Link>
|
||||
</nav>
|
||||
<div className="mt-auto small text-white-50 pt-4">
|
||||
UI shell ·{" "}
|
||||
<abbr title="Consistência visual com template Velzon (Bootstrap 5)">Velzon base</abbr>
|
||||
</div>
|
||||
</aside>
|
||||
<div className="flex-grow-1 d-flex flex-column min-vw-0">
|
||||
<header className="er-topbar border-bottom bg-body px-4 py-3 d-flex align-items-center justify-content-between">
|
||||
<div>
|
||||
<h1 className="h5 mb-1">{title}</h1>
|
||||
{breadcrumb && breadcrumb.length > 0 ? (
|
||||
<nav aria-label="breadcrumb">
|
||||
<ol className="breadcrumb mb-0 small">
|
||||
{breadcrumb.map((b, idx) => (
|
||||
<li
|
||||
key={`${b.label}-${idx}`}
|
||||
className={`breadcrumb-item${b.href ? "" : " active"}`}
|
||||
{...(!b.href ? { "aria-current": "page" } : {})}
|
||||
>
|
||||
{b.href ? <Link href={b.href}>{b.label}</Link> : b.label}
|
||||
</li>
|
||||
))}
|
||||
</ol>
|
||||
</nav>
|
||||
) : null}
|
||||
</div>
|
||||
</header>
|
||||
<main className="flex-grow-1 p-4 er-main">{children}</main>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
export function DataAlert({
|
||||
variant,
|
||||
title,
|
||||
body,
|
||||
}: {
|
||||
variant: "warning" | "danger" | "info";
|
||||
title: string;
|
||||
body: string;
|
||||
}) {
|
||||
return (
|
||||
<div className={`alert alert-${variant}`} role="status">
|
||||
<strong className="d-block mb-1">{title}</strong>
|
||||
{body}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useId, useState } from "react";
|
||||
|
||||
const _storageKey = (id: string) => `er-incident-notes:${id}`;
|
||||
|
||||
export function IncidentNotes({ incidentId }: { incidentId: string }) {
|
||||
const _id = useId();
|
||||
const [value, setValue] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof window === "undefined") {
|
||||
return;
|
||||
}
|
||||
const _stored = window.sessionStorage.getItem(_storageKey(incidentId));
|
||||
setValue(_stored ?? "");
|
||||
}, [incidentId]);
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof window === "undefined") {
|
||||
return;
|
||||
}
|
||||
window.sessionStorage.setItem(_storageKey(incidentId), value);
|
||||
}, [incidentId, value]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<label className="form-label" htmlFor={_id}>
|
||||
Notas do operador
|
||||
</label>
|
||||
<textarea
|
||||
id={_id}
|
||||
className="form-control font-monospace small"
|
||||
rows={5}
|
||||
value={value}
|
||||
onChange={(e) => setValue(e.target.value)}
|
||||
placeholder="Rascunho local (sessionStorage). A persistência no servidor chega com a API admin (BIT-179)."
|
||||
/>
|
||||
<p className="form-text mb-0">
|
||||
Estas notas não são enviadas ao servidor nesta fase — apenas para acompanhamento na sessão do
|
||||
browser.
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
export function KpiCard({
|
||||
label,
|
||||
value,
|
||||
variant,
|
||||
}: {
|
||||
label: string;
|
||||
value: number;
|
||||
variant: "primary" | "danger" | "warning" | "success" | "secondary" | "dark";
|
||||
}) {
|
||||
return (
|
||||
<div className="col-sm-6 col-xl-3">
|
||||
<div className={`card border-${variant} border-opacity-25 h-100`}>
|
||||
<div className="card-body">
|
||||
<p className="text-muted text-uppercase small mb-1">{label}</p>
|
||||
<p className={`display-6 fw-semibold text-${variant} mb-0`}>{value}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import type { Severity } from "@/lib/types";
|
||||
|
||||
const _labels: Record<Severity, string> = {
|
||||
critical: "Crítico",
|
||||
high: "Alto",
|
||||
medium: "Médio",
|
||||
low: "Baixo",
|
||||
info: "Info",
|
||||
};
|
||||
|
||||
const _class: Record<Severity, string> = {
|
||||
critical: "text-bg-dark",
|
||||
high: "text-bg-danger",
|
||||
medium: "text-bg-warning",
|
||||
low: "text-bg-info",
|
||||
info: "text-bg-light text-dark border",
|
||||
};
|
||||
|
||||
export function SeverityBadge({ severity }: { severity: Severity }) {
|
||||
return <span className={`badge ${_class[severity]}`}>{_labels[severity]}</span>;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import type { IncidentState } from "@/lib/types";
|
||||
|
||||
const _labels: Record<IncidentState, string> = {
|
||||
open: "Aberto",
|
||||
investigating: "Em investigação",
|
||||
resolved: "Resolvido",
|
||||
ignored: "Ignorado",
|
||||
};
|
||||
|
||||
const _class: Record<IncidentState, string> = {
|
||||
open: "text-bg-danger",
|
||||
investigating: "text-bg-warning",
|
||||
resolved: "text-bg-success",
|
||||
ignored: "text-bg-secondary",
|
||||
};
|
||||
|
||||
export function StateBadge({ state }: { state: IncidentState }) {
|
||||
return <span className={`badge ${_class[state]}`}>{_labels[state]}</span>;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { dirname } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { FlatCompat } from "@eslint/eslintrc";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
|
||||
const compat = new FlatCompat({
|
||||
baseDirectory: __dirname,
|
||||
});
|
||||
|
||||
const eslintConfig = [...compat.extends("next/core-web-vitals", "next/typescript")];
|
||||
|
||||
export default eslintConfig;
|
||||
@@ -0,0 +1,123 @@
|
||||
import type { IncidentDetail, IncidentSummary } from "./types";
|
||||
|
||||
/** Deterministic demo payloads for local UI review only (BIT-179 replaces with API). */
|
||||
const _demoSummaries: IncidentSummary[] = [
|
||||
{
|
||||
id: "demo-1",
|
||||
projectSlug: "wdmi-store",
|
||||
fingerprint: "fp_checkout_timeout",
|
||||
title: "Checkout API timeout after 30s",
|
||||
severity: "high",
|
||||
currentState: "open",
|
||||
firstSeenAt: "2026-03-20T10:00:00.000Z",
|
||||
lastSeenAt: "2026-03-22T03:12:44.000Z",
|
||||
occurrencesCount: 142,
|
||||
},
|
||||
{
|
||||
id: "demo-2",
|
||||
projectSlug: "crm-wdmi",
|
||||
fingerprint: "fp_null_sku",
|
||||
title: "TypeError: Cannot read properties of undefined (reading 'sku')",
|
||||
severity: "medium",
|
||||
currentState: "investigating",
|
||||
firstSeenAt: "2026-03-18T14:22:00.000Z",
|
||||
lastSeenAt: "2026-03-21T18:01:02.000Z",
|
||||
occurrencesCount: 38,
|
||||
},
|
||||
{
|
||||
id: "demo-3",
|
||||
projectSlug: "wdmi-store",
|
||||
fingerprint: "fp_rate_limit",
|
||||
title: "429 Too Many Requests on /api/v1/prices",
|
||||
severity: "low",
|
||||
currentState: "resolved",
|
||||
firstSeenAt: "2026-03-10T08:00:00.000Z",
|
||||
lastSeenAt: "2026-03-15T22:00:00.000Z",
|
||||
occurrencesCount: 901,
|
||||
},
|
||||
{
|
||||
id: "demo-4",
|
||||
projectSlug: "legacy-ott",
|
||||
fingerprint: "fp_deprecated_endpoint",
|
||||
title: "Deprecated endpoint still called: /legacy/ping",
|
||||
severity: "info",
|
||||
currentState: "ignored",
|
||||
firstSeenAt: "2026-01-05T12:00:00.000Z",
|
||||
lastSeenAt: "2026-02-01T09:30:00.000Z",
|
||||
occurrencesCount: 12,
|
||||
},
|
||||
];
|
||||
|
||||
const _stackSample = `TypeError: Cannot read properties of undefined (reading 'sku')
|
||||
at mapLineItem (webpack-internal:///(api)/./src/cart.ts:42:17)
|
||||
at Array.map (<anonymous>)
|
||||
at POST (webpack-internal:///(api)/./src/routes/checkout.ts:118:22)`;
|
||||
|
||||
const _details: Record<string, IncidentDetail> = {
|
||||
"demo-1": {
|
||||
..._demoSummaries[0],
|
||||
metadataJson: { route: "/checkout", release: "store-1.4.2" },
|
||||
ingestKeyLabel: "production-web",
|
||||
occurrences: [
|
||||
{
|
||||
id: "occ-1a",
|
||||
occurredAt: "2026-03-22T03:12:44.000Z",
|
||||
levelRaw: "error",
|
||||
severity: "high",
|
||||
message: "Upstream payment service did not respond within 30000ms",
|
||||
stacktrace: null,
|
||||
contextJson: { requestId: "req_9f2a", userAgent: "Mozilla/5.0 …" },
|
||||
},
|
||||
],
|
||||
},
|
||||
"demo-2": {
|
||||
..._demoSummaries[1],
|
||||
metadataJson: { module: "Ecommerce.Cart" },
|
||||
ingestKeyLabel: "crm-php",
|
||||
occurrences: [
|
||||
{
|
||||
id: "occ-2a",
|
||||
occurredAt: "2026-03-21T18:01:02.000Z",
|
||||
levelRaw: "error",
|
||||
severity: "medium",
|
||||
message: "TypeError: Cannot read properties of undefined (reading 'sku')",
|
||||
stacktrace: _stackSample,
|
||||
contextJson: { userId: 10294, cartId: "cart_88aa" },
|
||||
},
|
||||
],
|
||||
},
|
||||
"demo-3": {
|
||||
..._demoSummaries[2],
|
||||
metadataJson: { limit: 120, window: "1m" },
|
||||
ingestKeyLabel: "store-bff",
|
||||
occurrences: [
|
||||
{
|
||||
id: "occ-3a",
|
||||
occurredAt: "2026-03-15T22:00:00.000Z",
|
||||
levelRaw: "warn",
|
||||
severity: "low",
|
||||
message: "429 Too Many Requests",
|
||||
stacktrace: null,
|
||||
contextJson: { clientIp: "203.0.113.10" },
|
||||
},
|
||||
],
|
||||
},
|
||||
"demo-4": {
|
||||
..._demoSummaries[3],
|
||||
metadataJson: { owner: "platform" },
|
||||
ingestKeyLabel: "ott-lb",
|
||||
occurrences: [],
|
||||
},
|
||||
};
|
||||
|
||||
export function getDemoIncidentSummaries(): IncidentSummary[] {
|
||||
return [..._demoSummaries];
|
||||
}
|
||||
|
||||
export function getDemoIncidentDetail(id: string): IncidentDetail | null {
|
||||
const _row = _details[id];
|
||||
if (!_row) {
|
||||
return null;
|
||||
}
|
||||
return { ..._row, occurrences: [..._row.occurrences] };
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
export function formatDateTime(iso: string): string {
|
||||
try {
|
||||
const _d = new Date(iso);
|
||||
if (Number.isNaN(_d.getTime())) {
|
||||
return iso;
|
||||
}
|
||||
return new Intl.DateTimeFormat("pt-PT", {
|
||||
dateStyle: "short",
|
||||
timeStyle: "medium",
|
||||
}).format(_d);
|
||||
} catch {
|
||||
return iso;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
import { getDemoIncidentDetail, getDemoIncidentSummaries } from "./demo-incidents";
|
||||
import type { DetailResult, IncidentState, IncidentSummary, ListResult, Severity } from "./types";
|
||||
|
||||
function _isDemoEnabled(): boolean {
|
||||
return process.env.ERROR_REPORTING_UI_DEMO === "1";
|
||||
}
|
||||
|
||||
function _apiBase(): string | null {
|
||||
const _raw = process.env.ERROR_REPORTING_ADMIN_API_BASE?.trim();
|
||||
if (!_raw) {
|
||||
return null;
|
||||
}
|
||||
return _raw.replace(/\/$/, "");
|
||||
}
|
||||
|
||||
async function _fetchJson<T>(_path: string): Promise<T> {
|
||||
const _base = _apiBase();
|
||||
if (!_base) {
|
||||
throw new Error("API base not configured");
|
||||
}
|
||||
const _url = `${_base}${_path.startsWith("/") ? _path : `/${_path}`}`;
|
||||
const _res = await fetch(_url, {
|
||||
next: { revalidate: 0 },
|
||||
headers: { Accept: "application/json" },
|
||||
});
|
||||
if (!_res.ok) {
|
||||
throw new Error(`HTTP ${_res.status}`);
|
||||
}
|
||||
return (await _res.json()) as T;
|
||||
}
|
||||
|
||||
function _applyFilters(
|
||||
rows: IncidentSummary[],
|
||||
_params: { state?: IncidentState | ""; severity?: Severity | ""; q?: string; project?: string },
|
||||
): IncidentSummary[] {
|
||||
let _out = rows;
|
||||
if (_params.state) {
|
||||
_out = _out.filter((r) => r.currentState === _params.state);
|
||||
}
|
||||
if (_params.severity) {
|
||||
_out = _out.filter((r) => r.severity === _params.severity);
|
||||
}
|
||||
if (_params.project?.trim()) {
|
||||
const _slug = _params.project.trim().toLowerCase();
|
||||
_out = _out.filter((r) => r.projectSlug.toLowerCase() === _slug);
|
||||
}
|
||||
if (_params.q?.trim()) {
|
||||
const _q = _params.q.trim().toLowerCase();
|
||||
_out = _out.filter(
|
||||
(r) =>
|
||||
r.title.toLowerCase().includes(_q) ||
|
||||
r.fingerprint.toLowerCase().includes(_q) ||
|
||||
r.projectSlug.toLowerCase().includes(_q),
|
||||
);
|
||||
}
|
||||
return _out;
|
||||
}
|
||||
|
||||
export async function fetchIncidentList(_params: {
|
||||
state?: IncidentState | "";
|
||||
severity?: Severity | "";
|
||||
q?: string;
|
||||
project?: string;
|
||||
}): Promise<ListResult> {
|
||||
const _base = _apiBase();
|
||||
if (!_base) {
|
||||
if (_isDemoEnabled()) {
|
||||
const _rows = _applyFilters(getDemoIncidentSummaries(), {
|
||||
state: _params.state,
|
||||
severity: _params.severity,
|
||||
q: _params.q,
|
||||
project: _params.project,
|
||||
});
|
||||
return { ok: true, incidents: _rows, source: "demo" };
|
||||
}
|
||||
return {
|
||||
ok: false,
|
||||
error: "not_configured",
|
||||
message:
|
||||
"ERROR_REPORTING_ADMIN_API_BASE não está definido. Para pré-visualizar o layout, defina ERROR_REPORTING_UI_DEMO=1 (apenas desenvolvimento).",
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
const _sp = new URLSearchParams();
|
||||
if (_params.state) {
|
||||
_sp.set("state", _params.state);
|
||||
}
|
||||
if (_params.severity) {
|
||||
_sp.set("severity", _params.severity);
|
||||
}
|
||||
if (_params.project?.trim()) {
|
||||
_sp.set("project", _params.project.trim());
|
||||
}
|
||||
if (_params.q?.trim()) {
|
||||
_sp.set("q", _params.q.trim());
|
||||
}
|
||||
const _qs = _sp.toString();
|
||||
const _path = `/v1/incidents${_qs ? `?${_qs}` : ""}`;
|
||||
const _payload = await _fetchJson<{ incidents: IncidentSummary[] }>(_path);
|
||||
return { ok: true, incidents: _payload.incidents ?? [], source: "api" };
|
||||
} catch (_err) {
|
||||
const _msg = _err instanceof Error ? _err.message : "fetch failed";
|
||||
return {
|
||||
ok: false,
|
||||
error: "unreachable",
|
||||
message: `Não foi possível contactar a API admin (${_msg}).`,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchIncidentDetail(id: string): Promise<DetailResult> {
|
||||
const _base = _apiBase();
|
||||
if (!_base) {
|
||||
if (_isDemoEnabled()) {
|
||||
const _row = getDemoIncidentDetail(id);
|
||||
if (!_row) {
|
||||
return {
|
||||
ok: false,
|
||||
error: "not_found",
|
||||
message: "Incidente não encontrado.",
|
||||
};
|
||||
}
|
||||
return { ok: true, incident: _row, source: "demo" };
|
||||
}
|
||||
return {
|
||||
ok: false,
|
||||
error: "not_configured",
|
||||
message:
|
||||
"ERROR_REPORTING_ADMIN_API_BASE não está definido. Para pré-visualizar o layout, defina ERROR_REPORTING_UI_DEMO=1 (apenas desenvolvimento).",
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
const _base = _apiBase();
|
||||
if (!_base) {
|
||||
throw new Error("unreachable");
|
||||
}
|
||||
const _url = `${_base}/v1/incidents/${encodeURIComponent(id)}`;
|
||||
const _res = await fetch(_url, {
|
||||
next: { revalidate: 0 },
|
||||
headers: { Accept: "application/json" },
|
||||
});
|
||||
if (_res.status === 404) {
|
||||
return {
|
||||
ok: false,
|
||||
error: "not_found",
|
||||
message: "Incidente não encontrado.",
|
||||
};
|
||||
}
|
||||
if (!_res.ok) {
|
||||
throw new Error(`HTTP ${_res.status}`);
|
||||
}
|
||||
const _payload = (await _res.json()) as { incident: import("./types").IncidentDetail };
|
||||
return { ok: true, incident: _payload.incident, source: "api" };
|
||||
} catch (_err) {
|
||||
const _msg = _err instanceof Error ? _err.message : "fetch failed";
|
||||
return {
|
||||
ok: false,
|
||||
error: "unreachable",
|
||||
message: `Não foi possível contactar a API admin (${_msg}).`,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function computeKpis(incidents: IncidentSummary[]): Record<IncidentState | "total", number> {
|
||||
const _acc: Record<IncidentState | "total", number> = {
|
||||
total: incidents.length,
|
||||
open: 0,
|
||||
investigating: 0,
|
||||
resolved: 0,
|
||||
ignored: 0,
|
||||
};
|
||||
for (const _i of incidents) {
|
||||
_acc[_i.currentState] += 1;
|
||||
}
|
||||
return _acc;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
export type IncidentState =
|
||||
| "open"
|
||||
| "investigating"
|
||||
| "resolved"
|
||||
| "ignored";
|
||||
|
||||
export type Severity = "critical" | "high" | "medium" | "low" | "info";
|
||||
|
||||
export type IncidentSummary = {
|
||||
id: string;
|
||||
projectSlug: string;
|
||||
fingerprint: string;
|
||||
title: string;
|
||||
severity: Severity;
|
||||
currentState: IncidentState;
|
||||
firstSeenAt: string;
|
||||
lastSeenAt: string;
|
||||
occurrencesCount: number;
|
||||
};
|
||||
|
||||
export type IncidentOccurrence = {
|
||||
id: string;
|
||||
occurredAt: string;
|
||||
levelRaw: string;
|
||||
severity: Severity;
|
||||
message: string;
|
||||
stacktrace: string | null;
|
||||
contextJson: Record<string, unknown> | null;
|
||||
};
|
||||
|
||||
export type IncidentDetail = IncidentSummary & {
|
||||
metadataJson: Record<string, unknown> | null;
|
||||
ingestKeyLabel: string | null;
|
||||
occurrences: IncidentOccurrence[];
|
||||
};
|
||||
|
||||
export type ListResult =
|
||||
| { ok: true; incidents: IncidentSummary[]; source: "api" | "demo" }
|
||||
| { ok: false; error: "not_configured" | "unreachable"; message: string };
|
||||
|
||||
export type DetailResult =
|
||||
| { ok: true; incident: IncidentDetail; source: "api" | "demo" }
|
||||
| {
|
||||
ok: false;
|
||||
error: "not_configured" | "unreachable" | "not_found";
|
||||
message: string;
|
||||
};
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
/// <reference types="next" />
|
||||
/// <reference types="next/image-types/global" />
|
||||
/// <reference path="./.next/types/routes.d.ts" />
|
||||
|
||||
// NOTE: This file should not be edited
|
||||
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
|
||||
@@ -0,0 +1,7 @@
|
||||
import type { NextConfig } from "next";
|
||||
|
||||
const nextConfig: NextConfig = {
|
||||
reactStrictMode: true,
|
||||
};
|
||||
|
||||
export default nextConfig;
|
||||
Generated
+5847
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"name": "@bitreport/error-reporting-admin-ui",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"description": "Velzon-style admin dashboard for BitReport error reporting (BIT-181)",
|
||||
"scripts": {
|
||||
"dev": "next dev --turbopack -p 3040",
|
||||
"build": "next build",
|
||||
"start": "next start -p 3040",
|
||||
"lint": "next lint",
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"bootstrap": "^5.3.3",
|
||||
"next": "^15.1.0",
|
||||
"react": "^19.0.0",
|
||||
"react-dom": "^19.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/eslintrc": "^3.2.0",
|
||||
"@types/node": "^22.9.0",
|
||||
"@types/react": "^19.0.0",
|
||||
"@types/react-dom": "^19.0.0",
|
||||
"eslint": "^9.15.0",
|
||||
"eslint-config-next": "^15.1.0",
|
||||
"sass": "^1.81.0",
|
||||
"typescript": "^5.6.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2022",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"allowJs": false,
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"noEmit": true,
|
||||
"esModuleInterop": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "bundler",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"jsx": "preserve",
|
||||
"incremental": true,
|
||||
"plugins": [{ "name": "next" }],
|
||||
"paths": { "@/*": ["./*"] }
|
||||
},
|
||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
Reference in new issue
Block a user