import { useState } from "react"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@catalyst/table"; import { CustomTooltip } from "./Tooltip"; import { ArrowsPointingInIcon, ArrowsPointingOutIcon, MinusIcon, ArrowDownTrayIcon, } from "@heroicons/react/24/outline"; import Minimizer from "../Minimizer/Minimizer"; import { useExportData } from "@/hooks/messages"; // TODO: Remove after defining this better on backend export const DynamicTable: React.FC<{ // eslint-disable-next-line @typescript-eslint/no-explicit-any data: { columns: string[]; rows: any[][] }; initialCreatedAt?: Date; minimize?: boolean; linked_id?: string; }> = ({ data, minimize, linked_id }) => { const [minimized, setMinimized] = useState(minimize || false); const [limitedView, setLimitedView] = useState(true); const { mutate: exportData } = useExportData(); const handleExpand = () => { if (minimized) setMinimized(false); else if (limitedView) setLimitedView(false); }; return (
{data.columns.map((header: string, index: number) => ( {header} ))} {data.rows.map((row: string[] | number[], index: number) => { return ( {row.map((item: string | number, cellIndex: number) => ( {item} ))} ); })}
{/* Minimize Icon */} {/* On minimize, also collapse if already expanded */} {data.rows.length > 4 && // 4 data rows + 1 header (columns) row (limitedView ? ( /* Expand Icon */ ) : ( /* Contract Icon */ ))} {data.rows.length > 1 && linked_id && ( )}
); };