import * as React from 'react'; import { Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Paper, IconButton, Typography, Box, Button } from '@mui/material'; import EditIcon from '@mui/icons-material/Edit'; import DeleteIcon from '@mui/icons-material/Delete'; import { ResourceConfig } from '../types/config'; interface GenericTableProps { config: ResourceConfig; data: any[]; onEdit: (item: any) => void; onDelete: (id: string) => void; onCreate: () => void; } export default function GenericTable({ config, data, onEdit, onDelete, onCreate, }: GenericTableProps) { const fields = Object.entries(config.fields); return ( {config.pluralLabel} {fields.map(([key, field]) => ( {field.label} ))} Actions {data.map((item) => ( {fields.map(([key, field]) => ( {renderCellValue(item[key], field)} ))} onEdit(item)}> onDelete(item[config.primaryKey])}> ))}
); } function renderCellValue(value: any, field: any) { if (value === null || value === undefined) return '-'; switch (field.type) { case 'boolean': return value ? 'Yes' : 'No'; case 'date': return new Date(value).toLocaleDateString(); case 'object': return JSON.stringify(value); case 'array': return `${value.length} items`; default: return String(value); } }