import { useEffect, useState, useCallback } from 'react' import { Box, Button, Chip, CircularProgress, Container, IconButton, Paper, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, TextField, Toolbar, Tooltip, Typography, } from '@mui/material' import { Add as AddIcon, Refresh as RefreshIcon, Delete as DeleteIcon } from '@mui/icons-material' import { useNavigate } from 'react-router-dom' import { apiClient } from '../api/client' import { hostsApi } from '../api/client' import type { Host, HostHealthStatus } from '../types' const statusColor = (s: HostHealthStatus) => s === 'healthy' ? 'success' : s === 'degraded' ? 'warning' : s === 'unreachable' ? 'error' : 'default' export default function HostsPage() { const navigate = useNavigate() const [hosts, setHosts] = useState([]) const [total, setTotal] = useState(0) const [loading, setLoading] = useState(true) const [search, setSearch] = useState('') const [refreshing, setRefreshing] = useState(null) const load = useCallback(async () => { setLoading(true) try { const res = await apiClient.get('/hosts', { params: { limit: 100 } }) setHosts(res.data.hosts) setTotal(res.data.total) } catch { /* handled by interceptor */ } finally { setLoading(false) } }, []) const handleRefresh = async (e: React.MouseEvent, hostId: string) => { e.stopPropagation() setRefreshing(hostId) try { await hostsApi.refresh(hostId) setTimeout(() => { load(); setRefreshing(null) }, 2000) } catch { setRefreshing(null) } } useEffect(() => { load() }, []) const filtered = hosts.filter(h => h.fqdn.toLowerCase().includes(search.toLowerCase()) || h.display_name.toLowerCase().includes(search.toLowerCase()) ) return ( Hosts setSearch(e.target.value)} sx={{ mr: 2 }} /> {loading ? : ( FQDN Display Name IP Address OS Health Agent Actions {filtered.map(h => ( navigate(`/hosts/${h.id}`)}> {h.fqdn} {h.display_name} {h.ip_address} {h.os_name ?? h.os_family ?? '—'} {h.agent_version ?? '—'} e.stopPropagation()}> handleRefresh(e, h.id)}> {refreshing === h.id ? : } ))}
)} Showing {filtered.length} of {total} hosts
) }