"use client"; import { ColumnDef } from "@tanstack/react-table"; import { AlertTriangle, Eye, MoreVertical } from "lucide-react"; import { useState } from "react"; import { ActionDropdown, ActionDropdownItem, } from "@/components/shadcn/dropdown"; import { CodeSnippet } from "@/components/ui/code-snippet/code-snippet"; import { EntityInfo } from "@/components/ui/entities"; import { DataTableColumnHeader } from "@/components/ui/table"; import { getGroupLabel } from "@/lib/categories"; import { ProviderType, ResourceProps } from "@/types"; import { ResourceDetail } from "./resource-detail"; const getResourceData = ( row: { original: ResourceProps }, field: keyof ResourceProps["attributes"], ) => { return row.original.attributes?.[field]; }; const getProviderData = ( row: { original: ResourceProps }, field: keyof ResourceProps["relationships"]["provider"]["data"]["attributes"], ) => { return ( row.original.relationships?.provider?.data?.attributes?.[field] ?? `No ${field} found in provider` ); }; // Component for resource name that opens the detail drawer const ResourceNameCell = ({ row }: { row: { original: ResourceProps } }) => { const resourceName = row.original.attributes?.name; const resourceUid = row.original.attributes?.uid; const displayName = typeof resourceName === "string" && resourceName.trim().length > 0 ? resourceName : "Unnamed resource"; // Note: We don't use defaultOpen here because ResourceDetailsSheet (rendered at page level) // already handles opening the drawer when resourceId is in the URL. Using defaultOpen={true} // here would cause duplicate drawers to render. return (

{displayName}

} /> {resourceUid && } ); }; // Component for failed findings badge with warning style const FailedFindingsBadge = ({ count }: { count: number }) => { if (count === 0) { return ( 0 ); } return ( {count} ); }; // Row actions dropdown const ResourceRowActions = ({ row }: { row: { original: ResourceProps } }) => { const [isDrawerOpen, setIsDrawerOpen] = useState(false); return ( <>
} ariaLabel="Resource actions" > } label="View Details" onSelect={() => setIsDrawerOpen(true)} />
} /> ); }; // Column definitions for resources table export const ColumnResources: ColumnDef[] = [ // Name column { accessorKey: "resourceName", header: ({ column }) => ( ), cell: ({ row }) => , enableSorting: false, }, // Provider Account column { accessorKey: "provider", header: ({ column }) => ( ), cell: ({ row }) => { const provider = getProviderData(row, "provider"); const alias = getProviderData(row, "alias"); const uid = getProviderData(row, "uid"); return ( ); }, enableSorting: false, }, // Failed Findings column { accessorKey: "failedFindings", header: ({ column }) => ( ), cell: ({ row }) => { const failedFindingsCount = getResourceData( row, "failed_findings_count", ) as number; return ; }, enableSorting: false, }, // Group column { accessorKey: "groups", header: ({ column }) => ( ), cell: ({ row }) => { const groups = getResourceData(row, "groups") as string[] | null; if (!groups || groups.length === 0) { return

-

; } const displayLabel = getGroupLabel(groups[0]); const extraCount = groups.length - 1; return (

{displayLabel}

{extraCount > 0 && ( +{extraCount} )}
); }, enableSorting: false, }, // Type column { accessorKey: "type", header: ({ column }) => ( ), cell: ({ row }) => { const type = getResourceData(row, "type"); return (

{typeof type === "string" ? type : "-"}

); }, }, // Region column { accessorKey: "region", header: ({ column }) => ( ), cell: ({ row }) => { const region = getResourceData(row, "region"); return (

{typeof region === "string" ? region : "-"}

); }, }, // Service column { accessorKey: "service", header: ({ column }) => ( ), cell: ({ row }) => { const service = getResourceData(row, "service"); return (

{typeof service === "string" ? service : "-"}

); }, }, // Actions column { id: "actions", header: () =>
, cell: ({ row }) => , enableSorting: false, }, ];