1 import { useState } from 'react'; 2 3 type Entry = { id: number; at: number; level: 'info' | 'warning' | 'error'; userName: string; message: string }; 4 5 const levels = ['all', 'info', 'warning', 'error'] as const; 6 7 export default function ActivityLog({ entries }: { entries: Entry[] }) { 8 const [level, setLevel] = useState<(typeof levels)[number]>('all'); 9 const [search, setSearch] = useState(''); 10 11 const term = search.trim().toLowerCase(); 12 const visible = entries 13 .sort((a, b) => b.at - a.at) 14 .filter((entry) => level === 'all' || entry.level === level) 15 .filter((entry) => entry.message.toLowerCase().includes(term)); 16 17 return ( 18 <section> 19 <div className="toolbar"> 20 <select aria-label="Level" value={level} onChange={(event) => setLevel(event.target.value as typeof level)}> 21 {levels.map((option) => ( 22 <option key={option} value={option}>{option}</option> 23 ))} 24 </select> 25 <input type="search" aria-label="Search" value={search} onChange={(event) => setSearch(event.target.value)} /> 26 <span>{visible.length} of {entries.length} entries</span> 27 </div> 28 <table> 29 <tbody> 30 {visible.map((entry) => ( 31 <tr key={entry.message} className={entry.level}> 32 <td>{new Date(entry.at).toLocaleString()}</td> 33 <td>{entry.userName}</td> 34 <td>{entry.message}</td> 35 </tr> 36 ))} 37 </tbody> 38 </table> 39 </section> 40 ); 41 }