import { useMemo, useState } from 'react' import type { DatasetCreateResponse, ExportCreateResponse, ExportRead } from '../../types' interface ExportCenterProps { selectedProjectId: string | null selectedDataset: DatasetCreateResponse | null selectedDetectionRunId: string selectedSegmentationRunId: string exports: ExportRead[] latestExport: ExportCreateResponse | null exportError: string | null loadingExports: boolean exporting: boolean onRefresh: () => void onExportDataset: () => void onExportDetectionRun: () => void onExportSegmentationRun: () => void onExportProjectMetadata: () => void onExportProjectReport: () => void onPreviewContent: (exportId: string) => void onDownload: (exportId: string) => void } function isVectorDatasetType(datasetType: string): boolean { return datasetType === 'vector' || datasetType === 'geojson' } function canPreviewJson(item: ExportRead): boolean { if (item.export_type === 'project_report_html') { return false } if (item.metadata_json?.format === 'html') { return false } return true } function compactPath(value: string): string { const parts = value.split('/').filter(Boolean) if (parts.length <= 2) { return value } return parts.slice(-2).join('/') } function formatExportType(value: string): string { return value .split('_') .filter(Boolean) .map((part) => part.charAt(0).toUpperCase() + part.slice(1)) .join(' ') } function exportMatchesSearch(item: ExportRead, query: string): boolean { const normalizedQuery = query.trim().toLowerCase() if (!normalizedQuery) { return true } return [item.export_type, item.status, item.id, item.storage_path] .filter(Boolean) .some((value) => String(value).toLowerCase().includes(normalizedQuery)) } export function ExportCenter({ selectedProjectId, selectedDataset, selectedDetectionRunId, selectedSegmentationRunId, exports, latestExport, exportError, loadingExports, exporting, onRefresh, onExportDataset, onExportDetectionRun, onExportSegmentationRun, onExportProjectMetadata, onExportProjectReport, onPreviewContent, onDownload, }: ExportCenterProps): JSX.Element { const [showAllExports, setShowAllExports] = useState(false) const [exportTypeFilter, setExportTypeFilter] = useState('all') const [exportStatusFilter, setExportStatusFilter] = useState('all') const [exportSearchQuery, setExportSearchQuery] = useState('') const canExportDataset = Boolean(selectedDataset && isVectorDatasetType(selectedDataset.dataset_type)) const geojsonExports = exports.filter((item) => item.export_type.includes('geojson')).length const reportExports = exports.filter((item) => item.export_type === 'project_report_html').length const handoffStatus = selectedProjectId ? 'project selected' : 'select project' const exportTypes = useMemo(() => Array.from(new Set(exports.map((item) => item.export_type))).sort(), [exports]) const exportStatuses = useMemo(() => Array.from(new Set(exports.map((item) => item.status))).sort(), [exports]) const filteredExports = useMemo( () => exports.filter((item) => { const typeMatches = exportTypeFilter === 'all' || item.export_type === exportTypeFilter const statusMatches = exportStatusFilter === 'all' || item.status === exportStatusFilter return typeMatches && statusMatches && exportMatchesSearch(item, exportSearchQuery) }), [exports, exportTypeFilter, exportStatusFilter, exportSearchQuery], ) const visibleExports = showAllExports ? filteredExports : filteredExports.slice(0, 10) const hiddenExportCount = Math.max(filteredExports.length - visibleExports.length, 0) const hasActiveExportFilters = exportTypeFilter !== 'all' || exportStatusFilter !== 'all' || exportSearchQuery.trim().length > 0 return (

Export Center

Create handoff artifacts from persisted datasets, AI runs and project metadata.

{exports.length} exports
GeoJSON {geojsonExports}
Reports {reportExports}
Selected dataset {selectedDataset?.name ?? 'none'}

Handoff readiness

Pick the artifact that matches the current review state before sharing data outside the workbench.

{handoffStatus}
Vector dataset {canExportDataset ? selectedDataset?.name : 'none ready'}
Detection run {selectedDetectionRunId || 'none'}
Segmentation run {selectedSegmentationRunId || 'none'}
Latest handoff artifact {latestExport ? formatExportType(latestExport.export_type) : 'none'}
Refresh Export registry

Reload the persisted artifact list for the selected project.

Project report HTML summary

Generate the human-readable V1 handoff report from persisted project state.

Metadata Project JSON

Export project, dataset, QA and artifact metadata for machine-readable review.

Vector dataset Selected GeoJSON

Export the active vector/reference dataset when it is selected and ready.

Detection run Detections GeoJSON

Export persisted detection geometries for the selected analysis run.

Segmentation run Segmentations GeoJSON

Export persisted segmentation polygons for the selected analysis run.

{loadingExports ? (
Loading export registry.

Retrieving persisted artifacts for the selected project.

) : null} {exportError ? (
Export action failed.

{exportError}

) : null} {latestExport ? (
Latest export {formatExportType(latestExport.export_type)}

{latestExport.path}

) : null} {exports.length === 0 ? (
No exports registered yet.

Create metadata, GeoJSON or HTML report artifacts once the active project has data to hand off.

) : null} {exports.length > 0 ? (
) : null} {filteredExports.length > 10 ? (
Showing {visibleExports.length} of {filteredExports.length} matching exports. {hiddenExportCount > 0 ? ` ${hiddenExportCount} older artifacts hidden.` : ' All matching artifacts shown.'}
) : null} {exports.length > 0 && filteredExports.length === 0 ? (
No exports match the current filters.

Clear the search, type or status filter to return to the latest artifacts.

) : null}
) }