"use client"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import { Badge } from "@/components/ui/badge"; import { cn } from "@/lib/utils"; import { PRData } from "@/app/Interfaces/interface"; import React, { useState } from "react"; interface DataTableProps { columns: { accessorKey: string; header: string; }[]; data: PRData[]; } export function DataTable({ columns, data }: DataTableProps) { const [expandedRow, setExpandedRow] = useState(null); // Get all possible keys from data (assuming all rows have same keys) const allKeys = data.length > 0 ? Object.keys(data[0]) : []; const mainKeys = columns.map((col) => col.accessorKey); const extraKeys = allKeys.filter((key) => !mainKeys.includes(key)); const handleRowClick = (rowIndex: number) => { setExpandedRow(expandedRow === rowIndex ? null : rowIndex); }; return (
{columns.map((column) => ( {column.header} ))} {data.map((row, rowIndex) => ( handleRowClick(rowIndex)} > {columns.map((column) => ( {column.accessorKey === "status" ? ( ) : ( row[column.accessorKey as keyof PRData] )} ))} {expandedRow === rowIndex && extraKeys.length > 0 && (
Branch: {row.branch}
Days in Status: {row.daysSinceStatusChange} days
Created: {row.createdAt ? new Date(row.createdAt).toLocaleString( undefined, { dateStyle: "medium", timeStyle: "short" }, ) : ""}
Updated: {row.updatedAt ? new Date(row.updatedAt).toLocaleString( undefined, { dateStyle: "medium", timeStyle: "short" }, ) : ""}
Reviewer: {row.assignedReviewer}
Tester: {row.assignedTester}
)}
))}
); } const getStatusColor = (status: string) => { switch (status) { case "in_review": return "bg-blue-100 text-blue-700"; case "approved": return "bg-green-100 text-green-700"; case "needs_revision": return "bg-yellow-100 text-yellow-700"; case "merged": return "bg-purple-100 text-purple-700"; default: return "bg-gray-100 text-gray-700"; } }; function StatusBadge({ status }: { status: string }) { return ( {status.split("_").join(" ")} ); }