import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; import { getProfiles, deleteProfile } 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 { CertificateProfile } from '../api/types'; function formatTTL(seconds: number): string { if (seconds === 0) return 'No limit'; if (seconds < 60) return `${seconds}s`; if (seconds < 3600) return `${Math.floor(seconds / 60)}m`; if (seconds < 86400) return `${Math.floor(seconds / 3600)}h`; return `${Math.floor(seconds / 86400)}d`; } export default function ProfilesPage() { const queryClient = useQueryClient(); const { data, isLoading, error, refetch } = useQuery({ queryKey: ['profiles'], queryFn: () => getProfiles(), }); const deleteMutation = useMutation({ mutationFn: deleteProfile, onSuccess: () => queryClient.invalidateQueries({ queryKey: ['profiles'] }), }); const columns: Column[] = [ { key: 'name', label: 'Profile', render: (p) => (
{p.name}
{p.id}
{p.description && (
{p.description}
)}
), }, { key: 'algorithms', label: 'Key Algorithms', render: (p) => (
{(p.allowed_key_algorithms || []).map((alg, i) => ( {alg.algorithm} {alg.min_size}+ ))}
), }, { key: 'ttl', label: 'Max TTL', render: (p) => (
{formatTTL(p.max_ttl_seconds)} {p.allow_short_lived && ( short-lived )}
), }, { key: 'ekus', label: 'EKUs', render: (p) => (
{(p.allowed_ekus || []).map((eku, i) => ( {eku} ))}
), }, { key: 'spiffe', label: 'SPIFFE', render: (p) => ( p.spiffe_uri_pattern ? {p.spiffe_uri_pattern} : ), }, { key: 'enabled', label: 'Status', render: (p) => , }, { key: 'created', label: 'Created', render: (p) => {formatDateTime(p.created_at)}, }, { key: 'actions', label: '', render: (p) => ( ), }, ]; return ( <>
{error ? ( refetch()} /> ) : ( )}
); }