"use client"; import { ColumnDef } from "@tanstack/react-table"; import { Container } from "lucide-react"; import { DateWithTime, EntityInfo } from "@/components/ui/entities"; import { DataTableColumnHeader, SeverityBadge, StatusFindingBadge, } from "@/components/ui/table"; import { getRegionFlag } from "@/lib/region-flags"; import { FindingProps, ProviderType } from "@/types"; import { FindingDetailDrawer } from "./finding-detail-drawer"; import { DeltaValues, NotificationIndicator } from "./notification-indicator"; import { ProviderIconCell } from "./provider-icon-cell"; interface GetStandaloneFindingColumnsOptions { includeUpdatedAt?: boolean; openFindingId?: string | null; } const getFindingsData = (row: { original: FindingProps }) => { return row.original; }; const getFindingsMetadata = (row: { original: FindingProps }) => { return row.original.attributes.check_metadata; }; const getResourceData = ( row: { original: FindingProps }, field: keyof FindingProps["relationships"]["resource"]["attributes"], ) => { return row.original.relationships?.resource?.attributes?.[field] || "-"; }; const getProviderData = ( row: { original: FindingProps }, field: keyof FindingProps["relationships"]["provider"]["attributes"], ) => { return row.original.relationships?.provider?.attributes?.[field] || "-"; }; function FindingTitleCell({ finding, defaultOpen = false, }: { finding: FindingProps; defaultOpen?: boolean; }) { return (

{finding.attributes.check_metadata.checktitle}

} /> ); } export function getStandaloneFindingColumns({ includeUpdatedAt = false, openFindingId = null, }: GetStandaloneFindingColumnsOptions = {}): ColumnDef[] { const columns: ColumnDef[] = [ { id: "notification", header: () => null, cell: ({ row }) => { const finding = row.original; const delta = finding.attributes.delta as | (typeof DeltaValues)[keyof typeof DeltaValues] | undefined; return ( ); }, enableSorting: false, enableHiding: false, }, { accessorKey: "status", header: ({ column }) => ( ), cell: ({ row }) => { const { attributes: { status }, } = getFindingsData(row); return ; }, }, { accessorKey: "check", header: ({ column }) => ( ), cell: ({ row }) => ( ), }, { accessorKey: "resourceName", header: ({ column }) => ( ), cell: ({ row }) => { const name = getResourceData(row, "name"); const uid = getResourceData(row, "uid"); const entityAlias = typeof name === "string" && name.trim().length > 0 && name !== "-" ? name : undefined; const entityId = typeof uid === "string" && uid.trim().length > 0 && uid !== "-" ? uid : undefined; return (
} entityAlias={entityAlias} entityId={entityId} />
); }, enableSorting: false, }, { accessorKey: "severity", header: ({ column }) => ( ), cell: ({ row }) => { const { attributes: { severity }, } = getFindingsData(row); return ; }, }, { accessorKey: "provider", header: ({ column }) => ( ), cell: ({ row }) => { const provider = getProviderData(row, "provider"); return ( ); }, enableSorting: false, }, { accessorKey: "service", header: ({ column }) => ( ), cell: ({ row }) => { const { servicename } = getFindingsMetadata(row); return (

{servicename}

); }, enableSorting: false, }, { accessorKey: "region", header: ({ column }) => ( ), cell: ({ row }) => { const region = getResourceData(row, "region"); const regionText = typeof region === "string" ? region : "-"; const regionFlag = typeof region === "string" ? getRegionFlag(region) : ""; return ( {regionFlag && ( {regionFlag} )} {regionText} ); }, enableSorting: false, }, ]; if (includeUpdatedAt) { columns.push({ accessorKey: "updated_at", header: ({ column }) => ( ), cell: ({ row }) => { const { attributes: { updated_at }, } = getFindingsData(row); return ; }, }); } return columns; }