Harden raster detection manifest handoff
This commit is contained in:
@@ -4,6 +4,7 @@ import type {
|
||||
AreaRead,
|
||||
DatasetCreateResponse,
|
||||
JobRead,
|
||||
RasterTileHandoff,
|
||||
RasterMetadataResponse,
|
||||
RasterPreviewResponse,
|
||||
RasterStatsResponse,
|
||||
@@ -28,12 +29,39 @@ function toRasterMetadata(metadata: Record<string, unknown> | null | undefined):
|
||||
}
|
||||
|
||||
function extractRasterTileManifestPath(job: JobRead | null | undefined): string {
|
||||
const manifest = toRasterTileHandoff(job)
|
||||
return manifest?.manifest_path ?? ''
|
||||
}
|
||||
|
||||
function optionalString(value: unknown): string | null {
|
||||
return typeof value === 'string' && value.trim().length > 0 ? value : null
|
||||
}
|
||||
|
||||
function optionalNumber(value: unknown): number | null {
|
||||
return typeof value === 'number' && Number.isFinite(value) ? value : null
|
||||
}
|
||||
|
||||
function toRasterTileHandoff(job: JobRead | null | undefined): RasterTileHandoff | null {
|
||||
const result = job?.result_json
|
||||
if (!result) {
|
||||
return ''
|
||||
return null
|
||||
}
|
||||
const manifestPath = result.manifest_path
|
||||
return typeof manifestPath === 'string' ? manifestPath : ''
|
||||
if (typeof manifestPath !== 'string' || manifestPath.trim().length === 0) {
|
||||
return null
|
||||
}
|
||||
const manifest = typeof result.manifest === 'object' && result.manifest !== null
|
||||
? result.manifest as Record<string, unknown>
|
||||
: {}
|
||||
return {
|
||||
manifest_path: manifestPath,
|
||||
tile_set_id: optionalString(result.tile_set_id) ?? optionalString(manifest.tile_set_id),
|
||||
tile_size: optionalNumber(result.tile_size) ?? optionalNumber(manifest.tile_size),
|
||||
overlap: optionalNumber(result.overlap) ?? optionalNumber(manifest.overlap),
|
||||
count: optionalNumber(result.count) ?? optionalNumber(manifest.count),
|
||||
source_dataset_id: optionalString(result.source_dataset_id) ?? optionalString(manifest.source_dataset_id),
|
||||
created_at: optionalString(manifest.created_at),
|
||||
}
|
||||
}
|
||||
|
||||
export function useDatasetWorkflow({
|
||||
@@ -53,6 +81,7 @@ export function useDatasetWorkflow({
|
||||
const [jobs, setJobs] = useState<JobRead[]>([])
|
||||
const [rasterPreview, setRasterPreview] = useState<RasterPreviewResponse | null>(null)
|
||||
const [latestRasterTileManifestPath, setLatestRasterTileManifestPath] = useState('')
|
||||
const [latestRasterTileManifest, setLatestRasterTileManifest] = useState<RasterTileHandoff | null>(null)
|
||||
const [selectedIntersectTargetId, setSelectedIntersectTargetId] = useState('')
|
||||
const [selectedClipAreaId, setSelectedClipAreaId] = useState('')
|
||||
const [rasterTileSize, setRasterTileSize] = useState(512)
|
||||
@@ -113,7 +142,10 @@ export function useDatasetWorkflow({
|
||||
const latestRasterTileJob = response.items.find(
|
||||
(job) => job.job_type === 'raster.tile' && extractRasterTileManifestPath(job),
|
||||
)
|
||||
setLatestRasterTileManifestPath(extractRasterTileManifestPath(latestRasterTileJob))
|
||||
const manifest = toRasterTileHandoff(latestRasterTileJob)
|
||||
const manifestPath = manifest ? manifest.manifest_path : ''
|
||||
setLatestRasterTileManifest(manifest)
|
||||
setLatestRasterTileManifestPath(manifestPath)
|
||||
}
|
||||
|
||||
const loadDatasetDetails = async (projectId: string, dataset: DatasetCreateResponse) => {
|
||||
@@ -126,6 +158,7 @@ export function useDatasetWorkflow({
|
||||
setDatasetContent(null)
|
||||
setRasterPreview(null)
|
||||
setLatestRasterTileManifestPath('')
|
||||
setLatestRasterTileManifest(null)
|
||||
setSelectedDatasetId(dataset.id)
|
||||
setJobs([])
|
||||
try {
|
||||
@@ -372,10 +405,13 @@ export function useDatasetWorkflow({
|
||||
overlap: rasterTileOverlap,
|
||||
output_name: rasterTileOutputName || undefined,
|
||||
})
|
||||
const manifestPath = extractRasterTileManifestPath(job)
|
||||
const manifest = toRasterTileHandoff(job)
|
||||
const manifestPath = manifest?.manifest_path ?? ''
|
||||
setLatestRasterTileManifest(manifest)
|
||||
setLatestRasterTileManifestPath(manifestPath)
|
||||
await refreshSelectedDatasetAfterJob()
|
||||
if (manifestPath) {
|
||||
setLatestRasterTileManifest(manifest)
|
||||
setLatestRasterTileManifestPath(manifestPath)
|
||||
}
|
||||
setDatasetDetailError(null)
|
||||
@@ -465,6 +501,7 @@ export function useDatasetWorkflow({
|
||||
setDatasetContent(null)
|
||||
setRasterPreview(null)
|
||||
setLatestRasterTileManifestPath('')
|
||||
setLatestRasterTileManifest(null)
|
||||
setJobs([])
|
||||
}
|
||||
|
||||
@@ -478,6 +515,7 @@ export function useDatasetWorkflow({
|
||||
jobs,
|
||||
rasterPreview,
|
||||
latestRasterTileManifestPath,
|
||||
latestRasterTileManifest,
|
||||
selectedIntersectTargetId,
|
||||
selectedClipAreaId,
|
||||
rasterTileSize,
|
||||
|
||||
Reference in New Issue
Block a user