"use client"; import { ColumnDef } from "@tanstack/react-table"; import { createContext, useContext, useState } from "react"; import { IssuePanel } from "@/components/issues/issue-panel"; import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/shadcn"; import { Badge } from "@/components/shadcn/badge/badge"; import { EntityInfo } from "@/components/shadcn/entities"; import { DataTable, DataTableColumnHeader } from "@/components/shadcn/table"; import { SeverityBadge } from "@/components/shadcn/table/severity-badge"; import { TriageStatusBadge } from "@/components/shared/triage/triage-status-badge"; import { attackPathLabel, LEG_LABELS, LEG_STATE_LABELS, legBadgeVariant, VERDICTS, } from "@/lib/issues/verdicts"; import { MetaDataProps } from "@/types"; import { IssueResponse, LegName } from "@/types/issues"; type IssueRow = IssueResponse["data"][number]; /** One letter per leg, in the order the legs are asked. */ const LEG_LETTERS: Record = { reachability: "R", access: "A", target: "T", controls: "C", verification: "V", }; const OpenIssueContext = createContext<(id: string) => void>(() => {}); function IssueCell({ issue }: { issue: IssueRow }) { const open = useContext(OpenIssueContext); const { title, pattern } = issue.attributes; const path = attackPathLabel(issue.attributes); // Single line like the finding groups title: ellipsis past the max width, // the full title in the tooltip. return (
{title}

{path ? `${path} ยท ${pattern}` : pattern}

); } const columns: ColumnDef[] = [ { id: "verdict", accessorKey: "attributes.verdict", header: ({ column }) => ( ), cell: ({ row }) => { const verdict = VERDICTS.find( (v) => v.id === row.original.attributes.verdict, ); return ( {verdict?.label ?? row.original.attributes.verdict} ); }, }, { id: "issue", header: "Issue", cell: ({ row }) => , }, { id: "legs", header: "Why", cell: ({ row }) => (
    {(Object.keys(LEG_LETTERS) as LegName[]).map((name) => { const leg = row.original.attributes.legs[name]; if (!leg) return null; const label = `${LEG_LABELS[name]}: ${LEG_STATE_LABELS[leg.state]}`; return (
  • {label}

    {leg.text}

  • ); })}
), }, { id: "severity", header: "Severity", cell: ({ row }) => ( ), }, { id: "provider", header: "Account", cell: ({ row }) => (
), }, { id: "findings", accessorKey: "attributes.findings_count", header: ({ column }) => ( ), cell: ({ row }) => ( {row.original.attributes.findings_count.toLocaleString()} ), }, { id: "triage", header: "Triage", cell: ({ row }) => ( ), }, ]; export const IssuesTable = ({ issues, metadata, }: { issues: IssueRow[]; metadata?: MetaDataProps; }) => { const [openId, setOpenId] = useState(null); const openIssue = issues.find((issue) => issue.id === openId); return (
setOpenId(row.original.id)} /> {openIssue && ( { if (!open) setOpenId(null); }} /> )}
); };