/** * AuditLogTable component - Display detailed audit log with pagination */ import React, { useState } from 'react'; import { Box, Typography, Paper, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, TablePagination, TextField, InputAdornment, Chip, LinearProgress, } from '@mui/material'; import { Search as SearchIcon, } from '@mui/icons-material'; interface AuditLogEntry { rowNumber: number; column: string; oldValue: string; newValue: string; actionType: string; agent: string; confidence: number; timestamp: string; } interface AuditLogTableProps { entries: AuditLogEntry[]; loading?: boolean; } const AuditLogTable: React.FC = ({ entries, loading = false }) => { const [page, setPage] = useState(0); const [rowsPerPage, setRowsPerPage] = useState(50); const [searchTerm, setSearchTerm] = useState(''); const handleChangePage = (_event: unknown, newPage: number) => { setPage(newPage); }; const handleChangeRowsPerPage = (event: React.ChangeEvent) => { setRowsPerPage(parseInt(event.target.value, 10)); setPage(0); }; const filteredEntries = entries.filter((entry) => { const searchLower = searchTerm.toLowerCase(); return ( entry.column.toLowerCase().includes(searchLower) || entry.actionType.toLowerCase().includes(searchLower) || entry.agent.toLowerCase().includes(searchLower) ); }); const paginatedEntries = filteredEntries.slice( page * rowsPerPage, page * rowsPerPage + rowsPerPage ); const getConfidenceColor = (confidence: number): 'success' | 'warning' | 'error' => { if (confidence >= 0.8) return 'success'; if (confidence >= 0.5) return 'warning'; return 'error'; }; const formatTimestamp = (timestamp: string): string => { const date = new Date(timestamp); return date.toLocaleString(); }; const formatValue = (value: string): string => { if (!value || value === 'null' || value === '') { return '-'; } return value.length > 50 ? `${value.substring(0, 50)}...` : value; }; return ( Audit Log setSearchTerm(e.target.value)} slotProps={{ input: { startAdornment: ( ), }, }} sx={{ width: 300 }} /> {loading ? ( ) : ( <> Row # Column Old Value New Value Action Type Agent Confidence Timestamp {paginatedEntries.length > 0 ? ( paginatedEntries.map((entry, index) => ( {entry.rowNumber} {formatValue(entry.oldValue)} {formatValue(entry.newValue)} {entry.agent} {(entry.confidence * 100).toFixed(0)}% {formatTimestamp(entry.timestamp)} )) ) : ( No audit log entries found )}
)}
); }; export default AuditLogTable;