import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; import { getAgentGroups, deleteAgentGroup } from '../api/client'; import PageHeader from '../components/PageHeader'; import DataTable from '../components/DataTable'; import type { Column } from '../components/DataTable'; import StatusBadge from '../components/StatusBadge'; import ErrorState from '../components/ErrorState'; import { formatDateTime } from '../api/utils'; import type { AgentGroup } from '../api/types'; export default function AgentGroupsPage() { const queryClient = useQueryClient(); const { data, isLoading, error, refetch } = useQuery({ queryKey: ['agent-groups'], queryFn: () => getAgentGroups(), }); const deleteMutation = useMutation({ mutationFn: deleteAgentGroup, onSuccess: () => queryClient.invalidateQueries({ queryKey: ['agent-groups'] }), }); const columns: Column[] = [ { key: 'name', label: 'Group', render: (g) => (
{g.name}
{g.id}
{g.description && (
{g.description}
)}
), }, { key: 'criteria', label: 'Match Criteria', render: (g) => { const criteria: string[] = []; if (g.match_os) criteria.push(`OS: ${g.match_os}`); if (g.match_architecture) criteria.push(`Arch: ${g.match_architecture}`); if (g.match_ip_cidr) criteria.push(`IP: ${g.match_ip_cidr}`); if (g.match_version) criteria.push(`Ver: ${g.match_version}`); return criteria.length > 0 ? (
{criteria.map((c, i) => ( {c} ))}
) : ( Manual only ); }, }, { key: 'enabled', label: 'Status', render: (g) => , }, { key: 'created', label: 'Created', render: (g) => {formatDateTime(g.created_at)}, }, { key: 'actions', label: '', render: (g) => ( ), }, ]; return ( <>
{error ? ( refetch()} /> ) : ( )}
); }