import { Globe, Pencil, Trash2, Upload } from 'lucide-react'; import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { usePageTitle } from '../../hooks/usePageTitle'; import { useNavigate, useParams } from 'react-router-dom'; import { stringify as yamlStringify } from 'yaml'; import type { Environment } from '../../api'; import { environments } from '../../api'; import { DeleteConfirmationModal } from '../../components/modals'; import { Breadcrumbs, Button, Card, DescriptionList, Timestamp, UuidBadge, MarkdownContent, useToast, } from '../../ui'; import styles from '../Page.module.css'; export function EnvironmentDetailPage() { const { t } = useTranslation(); const toast = useToast(); const { id } = useParams<{ id: string }>(); const navigate = useNavigate(); const [env, setEnv] = useState(null); const [loading, setLoading] = useState(true); usePageTitle(env?.name ?? null); const [confirmDeleteOpen, setConfirmDeleteOpen] = useState(false); const [deleting, setDeleting] = useState(false); const dataEntries = Object.entries(env?.data ?? {}).filter(([, v]) => v); useEffect(() => { if (!id) return; environments .get(id) .then(setEnv) .catch((err: Error) => toast.error((err as Error).message)) .finally(() => setLoading(false)); }, [id, toast]); const handleDelete = async () => { if (!env) return; setDeleting(true); try { await environments.remove(env.id); navigate('/environments'); } finally { setDeleting(false); setConfirmDeleteOpen(false); } }; const handleExport = async () => { if (!env) return; const data = await environments.exportEnvironment(env.id); const blob = new Blob([yamlStringify(data)], { type: 'application/yaml' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `environment-${env.name}.yaml`; a.click(); URL.revokeObjectURL(url); }; return (
, onClick: () => navigate('/environments'), }, { label: env?.name ?? `#${id}` }, ]} /> {env && (
)}
{loading &&

{t('environments.loading')}

} {env && ( <> }, { term: t('environments.field_created'), detail: , }, { term: t('environments.field_updated'), detail: , }, ]} /> {env.description && (

{t('environments.field_description')}

)}

{t('environments.section_data')}

{dataEntries.length === 0 ? (

{t('environments.no_data')}

) : ( ({ term: key, detail: ( {value} ), }))} /> )}
)} setConfirmDeleteOpen(false)} onConfirm={handleDelete} isDeleting={deleting} />
); }