203 lines
7.2 KiB
TypeScript
203 lines
7.2 KiB
TypeScript
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";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
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>
|
|
);
|
|
}
|