Prefer complete Mol analysis workspaces
This commit is contained in:
@@ -21,6 +21,10 @@ def test_frontend_declares_mol_as_primary_operating_focus() -> None:
|
|||||||
assert "[5.1167, 51.1919]" in focus
|
assert "[5.1167, 51.1919]" in focus
|
||||||
assert "isPrimaryFocusProjectData" in focus
|
assert "isPrimaryFocusProjectData" in focus
|
||||||
assert "isPrimaryFocusProjectData(project, data.datasets)" in project_hook
|
assert "isPrimaryFocusProjectData(project, data.datasets)" in project_hook
|
||||||
|
assert "hasMappedAnalysisContext(data)" in project_hook
|
||||||
|
assert "dataset.dataset_type === 'raster'" in project_hook
|
||||||
|
assert "dataset.dataset_type === 'vector' || dataset.dataset_type === 'geojson'" in project_hook
|
||||||
|
assert "const primaryContext = inspectedCandidates.find" in project_hook
|
||||||
assert "PRIMARY_FOCUS_AREA_NAME" in project_hook
|
assert "PRIMARY_FOCUS_AREA_NAME" in project_hook
|
||||||
assert "PRIMARY_FOCUS_AREA_GEOJSON" in project_hook
|
assert "PRIMARY_FOCUS_AREA_GEOJSON" in project_hook
|
||||||
assert "4.35,51.28" not in project_hook
|
assert "4.35,51.28" not in project_hook
|
||||||
|
|||||||
@@ -25,6 +25,16 @@ function isDemoProject(project: ProjectRead): boolean {
|
|||||||
return project.name === DEMO_PROJECT_NAME
|
return project.name === DEMO_PROJECT_NAME
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hasMappedAnalysisContext(
|
||||||
|
data: { areas: AreaRead[]; datasets: DatasetCreateResponse[] },
|
||||||
|
): boolean {
|
||||||
|
const hasRasterDataset = data.datasets.some((dataset) => dataset.dataset_type === 'raster')
|
||||||
|
const hasVectorDataset = data.datasets.some(
|
||||||
|
(dataset) => dataset.dataset_type === 'vector' || dataset.dataset_type === 'geojson',
|
||||||
|
)
|
||||||
|
return data.areas.length > 0 && hasRasterDataset && hasVectorDataset
|
||||||
|
}
|
||||||
|
|
||||||
export function useProjectWorkspace() {
|
export function useProjectWorkspace() {
|
||||||
const [projects, setProjects] = useState<ProjectRead[]>([])
|
const [projects, setProjects] = useState<ProjectRead[]>([])
|
||||||
const [selectedProjectId, setSelectedProjectId] = useState<string | null>(null)
|
const [selectedProjectId, setSelectedProjectId] = useState<string | null>(null)
|
||||||
@@ -81,13 +91,23 @@ export function useProjectWorkspace() {
|
|||||||
try {
|
try {
|
||||||
const data = await fetchProjectData(project.id)
|
const data = await fetchProjectData(project.id)
|
||||||
inspectedCandidates.push({ project, data })
|
inspectedCandidates.push({ project, data })
|
||||||
if (data.datasets.length > 0 && isPrimaryFocusProjectData(project, data.datasets)) {
|
if (
|
||||||
|
isPrimaryFocusProjectData(project, data.datasets) &&
|
||||||
|
hasMappedAnalysisContext(data)
|
||||||
|
) {
|
||||||
return project.id
|
return project.id
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// Project list should still render if a candidate's detail endpoints are temporarily unavailable.
|
// Project list should still render if a candidate's detail endpoints are temporarily unavailable.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const primaryContext = inspectedCandidates.find(
|
||||||
|
({ project, data }) =>
|
||||||
|
data.datasets.length > 0 && isPrimaryFocusProjectData(project, data.datasets),
|
||||||
|
)
|
||||||
|
if (primaryContext) {
|
||||||
|
return primaryContext.project.id
|
||||||
|
}
|
||||||
const completeContext = inspectedCandidates.find(
|
const completeContext = inspectedCandidates.find(
|
||||||
({ data }) => data.areas.length > 0 && data.datasets.length > 0,
|
({ data }) => data.areas.length > 0 && data.datasets.length > 0,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user