peppa/apps/web/components/ProjectErrors.tsx

33 lines
1.9 KiB
TypeScript

// PEP-218: the project's tab «Баги» — errors of its own Bugsink projects (`<KEY>-web` /
// `<KEY>-api`), read on the server, in the same view as the superadmin's /observability.
import Link from "next/link";
import { errorScope, listErrors } from "@peppa/core";
import { ErrorFilters, errorFilterFrom, ErrorRows, ErrorsDown } from "@/components/Errors";
import { Section } from "@/components/common";
import { requireUser } from "@/lib/auth";
import { db } from "@/lib/db";
import { getT } from "@/lib/i18n";
export type ErrorSearch = { bp?: string; state?: string; env?: string; rel?: string; q?: string; sort?: string; cursor?: string };
export async function ProjectErrors({ projectId, projectKey, sp }: { projectId: number; projectKey: string; sp: ErrorSearch }) {
const user = await requireUser();
const t = await getT();
const scope = await errorScope(db, user, { projectId });
if (!scope.projects.length) return null;
const f = errorFilterFrom(sp);
const list = await listErrors(db, scope, f);
const query = new URLSearchParams(Object.entries({ tab: "bugs", bp: sp.bp, state: sp.state, env: sp.env, rel: sp.rel, q: sp.q, sort: sp.sort }).filter((e): e is [string, string] => !!e[1]));
const from = `/p/${projectKey}?${query}`;
return (
<Section title={t("Ошибки продукта")} count={list.rows.length}>
<ErrorsDown down={list.down} at={list.at} tech={scope.tech} t={t} />
<ErrorFilters action={`/p/${projectKey}`} scope={scope} f={f} keep={{ tab: "bugs" }} t={t} showProject={scope.tech} />
<ErrorRows rows={list.rows} tech={scope.tech} from={from} t={t} showProject={scope.tech} />
{list.next ? (
<Link href={`/p/${projectKey}?${new URLSearchParams([...query, ["cursor", list.next]])}`} className="mt-2 inline-block text-sm text-primary hover:underline">{t("Дальше →")}</Link>
) : null}
</Section>
);
}