'use client'; import React, { useState, useMemo } from 'react'; interface NotificationType { id: number; type: string; message: string; timestamp: string; acknowledged: boolean; priority: string; detector_id: number; detector_name: string; location: string; object: string; } interface DetectorType { detector_id: number name: string serial_number: string object: string status: string type: string location: string floor: number checked: boolean notifications: Array<{ id: number type: string message: string timestamp: string acknowledged: boolean priority: string }> } interface DetectorsDataType { detectors: Record } interface ReportsListProps { objectId?: string; detectorsData: DetectorsDataType; } const ReportsList: React.FC = ({ detectorsData }) => { const [searchTerm, setSearchTerm] = useState(''); const [statusFilter, setStatusFilter] = useState('all'); const [priorityFilter] = useState('all'); const [acknowledgedFilter] = useState('all'); const allNotifications = useMemo(() => { const notifications: NotificationType[] = []; Object.values(detectorsData.detectors).forEach(detector => { if (detector.notifications && detector.notifications.length > 0) { detector.notifications.forEach(notification => { notifications.push({ ...notification, detector_id: detector.detector_id, detector_name: detector.name, location: detector.location, object: detector.object }); }); } }); return notifications; }, [detectorsData]); const filteredDetectors = useMemo(() => { return allNotifications.filter(notification => { const matchesSearch = notification.detector_name.toLowerCase().includes(searchTerm.toLowerCase()) || notification.location.toLowerCase().includes(searchTerm.toLowerCase()) || notification.message.toLowerCase().includes(searchTerm.toLowerCase()); const matchesStatus = statusFilter === 'all' || notification.type === statusFilter; const matchesPriority = priorityFilter === 'all' || notification.priority === priorityFilter; const matchesAcknowledged = acknowledgedFilter === 'all' || (acknowledgedFilter === 'acknowledged' && notification.acknowledged) || (acknowledgedFilter === 'unacknowledged' && !notification.acknowledged); return matchesSearch && matchesStatus && matchesPriority && matchesAcknowledged; }); }, [allNotifications, searchTerm, statusFilter, priorityFilter, acknowledgedFilter]); const getStatusColor = (type: string) => { switch (type) { case 'critical': return '#b3261e'; case 'warning': return '#fd7c22'; case 'info': return '#00ff00'; default: return '#666'; } }; const getPriorityColor = (priority: string) => { switch (priority) { case 'high': return '#b3261e'; case 'medium': return '#fd7c22'; case 'low': return '#00ff00'; default: return '#666'; } }; const getStatusCounts = () => { const counts = { total: allNotifications.length, critical: allNotifications.filter(d => d.type === 'critical').length, warning: allNotifications.filter(d => d.type === 'warning').length, info: allNotifications.filter(d => d.type === 'info').length, acknowledged: allNotifications.filter(d => d.acknowledged).length, unacknowledged: allNotifications.filter(d => !d.acknowledged).length }; return counts; }; const counts = getStatusCounts(); return (
{/* Поиск и сортировка*/}
setSearchTerm(e.target.value)} className="bg-[#161824] text-white placeholder-gray-400 px-4 py-2 rounded-lg border border-gray-600 focus:border-blue-500 focus:outline-none w-64" />
{/* Табличка с детекторами*/}
{filteredDetectors.map((detector) => ( ))} {filteredDetectors.length === 0 && ( )}
Детектор Статус Сообщение Местоположение Приоритет Подтверждено Время
{detector.detector_name}
ID: {detector.detector_id}
{detector.type === 'critical' ? 'Критический' : detector.type === 'warning' ? 'Предупреждение' : 'Информация'}
{detector.message}
{detector.location}
{detector.priority === 'high' ? 'Высокий' : detector.priority === 'medium' ? 'Средний' : 'Низкий'} {detector.acknowledged ? 'Да' : 'Нет'}
{new Date(detector.timestamp).toLocaleString('ru-RU')}
Детекторы не найдены
{counts.total}
Всего
{counts.critical}
Критические
{counts.warning}
Предупреждения
{counts.info}
Информация
{counts.acknowledged}
Подтверждено
{counts.unacknowledged}
Не подтверждено
); }; export default ReportsList;