'use client' import React, { useState } from 'react' interface AlertType { id: number detector_id: number detector_name: string type: string status: string message: string timestamp: string location: string object: string acknowledged: boolean priority: string } interface DetectorType { detector_id: number name: string serial_number: string object: string status: string type: string detector_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 SensorsProps { objectId?: string detectorsData: DetectorsDataType onAlertClick: (alert: AlertType) => void onClose?: () => void is3DReady?: boolean } const Sensors: React.FC = ({ objectId, detectorsData, onAlertClick, onClose, is3DReady = true }) => { const [searchTerm, setSearchTerm] = useState('') // Получаем все уведомления (как в компоненте Notifications) const alerts = React.useMemo(() => { const notifications: AlertType[] = []; 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, status: detector.status }); }); } }); // Фильтруем по objectId const filteredAlerts = objectId ? notifications.filter(alert => alert.object && alert.object.toString() === objectId.toString()) : notifications // Дополнительная фильтрация по поиску const finalAlerts = filteredAlerts.filter(alert => { return searchTerm === '' || (alert.detector_name && alert.detector_name.toLowerCase().includes(searchTerm.toLowerCase())) || (alert.message && alert.message.toLowerCase().includes(searchTerm.toLowerCase())) || (alert.location && alert.location.toLowerCase().includes(searchTerm.toLowerCase())) }) // Сортируем по timestamp (новые сверху) return finalAlerts.sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime()) }, [detectorsData, objectId, searchTerm]) const getStatusColor = (type: string) => { switch (type.toLowerCase()) { case 'critical': return 'bg-red-500' case 'warning': return 'bg-orange-500' case 'info': return 'bg-green-500' default: return 'bg-gray-500' } } return (

Сенсоры - Уведомления

setSearchTerm(e.target.value)} className="w-full bg-[rgb(27,30,40)] text-white placeholder-gray-400 px-4 py-2 rounded-lg border border-gray-600 focus:border-blue-500 focus:outline-none" />
{alerts.length === 0 ? (

Уведомления не найдены

) : ( alerts.map(alert => (
{alert.detector_name}
{alert.message}
)) )}
) } export default Sensors