send the map selection to change detection and show the modified class
The comparison hook runs before the selection state is declared in App, so the selection is read through a getter at the moment the run starts rather than captured at render. The panel gains the modified count, which until now was folded into removed plus added. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,18 +1,29 @@
|
||||
import { useState } from 'react'
|
||||
import { analysisApi } from '../services/api'
|
||||
import type { ChangeDetectionSummary, DatasetCreateResponse } from '../types'
|
||||
import type { ChangeDetectionSummary, DatasetCreateResponse, VectorSelectionBBox } from '../types'
|
||||
import { formatError } from '../lib/formatError'
|
||||
|
||||
interface ChangeDetectionWorkflowOptions {
|
||||
selectedProjectId: string | null
|
||||
availableVectorDatasets: DatasetCreateResponse[]
|
||||
loadDatasetJobs: (projectId: string, datasetId: string) => Promise<void>
|
||||
/**
|
||||
* Reads the active map selection when the comparison is started. Without a
|
||||
* selection the comparison covers both datasets entire, which is rarely the
|
||||
* question being asked and returns a payload no map can draw.
|
||||
*
|
||||
* A getter rather than a value because this hook runs before the selection
|
||||
* state is declared in the component; it is only ever called from a user
|
||||
* event, long after that binding is initialised.
|
||||
*/
|
||||
getSelection?: () => { bbox: VectorSelectionBBox | null; areaId: string | null }
|
||||
}
|
||||
|
||||
export function useChangeDetectionWorkflow({
|
||||
selectedProjectId,
|
||||
availableVectorDatasets,
|
||||
loadDatasetJobs,
|
||||
getSelection,
|
||||
}: ChangeDetectionWorkflowOptions) {
|
||||
const [changeSourceDatasetId, setChangeSourceDatasetId] = useState('')
|
||||
const [changeTargetDatasetId, setChangeTargetDatasetId] = useState('')
|
||||
@@ -41,12 +52,15 @@ export function useChangeDetectionWorkflow({
|
||||
setChangeDetectionError(null)
|
||||
setChangeDetectionResult(null)
|
||||
setRunningChangeDetection(true)
|
||||
const selection = getSelection?.() ?? { bbox: null, areaId: null }
|
||||
try {
|
||||
const job = await analysisApi.runChangeDetection({
|
||||
source_dataset_id: sourceDatasetId,
|
||||
target_dataset_id: targetDatasetId,
|
||||
iou_threshold: changeIouThreshold,
|
||||
include_unchanged: changeIncludeUnchanged,
|
||||
...(selection.bbox ? { bbox: selection.bbox } : {}),
|
||||
...(selection.areaId ? { area_id: selection.areaId } : {}),
|
||||
})
|
||||
if (job.status !== 'success') {
|
||||
throw new Error(job.error_message || 'Change detection job failed')
|
||||
|
||||
Reference in New Issue
Block a user