split the map workspace into a view model and two views
MapWorkspace.tsx was 3.157 lines: a props interface, 1.200 lines of derived state and handlers, and two complete render paths — the map-first explorer and the advanced workbench behind it. It is now five modules, and the container is nineteen lines that choose between the two. The obstacle was the props signature. The explorer reads 97 derived values and the workbench 40, so passing them individually would have produced a 97-field interface — worse than the file it replaced. Extracting the derived state into a hook that returns one object solves it: MapWorkspaceViewModel is ReturnType<typeof useMapWorkspaceViewModel>, so the shape is derived from what the hook actually produces and cannot drift from it. Each view then names two typed objects, and the JSX moved unchanged. The contract tests found the one place where widening a negative assertion is wrong. "The map workspace performs no transport" was true of the old file and false of the whole feature, because the hooks call the API by design. It is now scoped to the presentational modules, which is what it always meant. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ from __future__ import annotations
|
||||
|
||||
import re
|
||||
from pathlib import Path
|
||||
from tests.frontend_contract import read_feature
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
@@ -47,9 +48,7 @@ def test_quality_results_panel_owns_persisted_quality_check_markup() -> None:
|
||||
|
||||
|
||||
def test_map_workspace_owns_map_controls_and_feature_inspector_markup() -> None:
|
||||
map_workspace = (
|
||||
ROOT / "frontend" / "src" / "components" / "map" / "MapWorkspace.tsx"
|
||||
).read_text(encoding="utf-8")
|
||||
map_workspace = read_feature("map_workspace")
|
||||
|
||||
assert "GeoMap" in map_workspace
|
||||
assert "map-toolbar" in map_workspace
|
||||
@@ -58,8 +57,11 @@ def test_map_workspace_owns_map_controls_and_feature_inspector_markup() -> None:
|
||||
assert "Actieve kaartlaag" in map_workspace
|
||||
assert "Objectinspectie" in map_workspace
|
||||
assert "onFeatureSelect={onSelectMapFeature}" in map_workspace
|
||||
assert "fetch(" not in map_workspace
|
||||
# The component owns markup and interaction, never transport. A bare "api"
|
||||
# substring also matches useMapImageOverlays, so name what is forbidden.
|
||||
assert "services/api" not in map_workspace
|
||||
assert not re.search(r"\w*[Aa]pi\.(get|post|put|delete)\(", map_workspace)
|
||||
# The markup layer owns interaction, never transport. Scoped to the
|
||||
# presentational modules because the workspace's hooks do perform
|
||||
# transport, by design. A bare "api" substring also matches
|
||||
# useMapImageOverlays, so name what is actually forbidden.
|
||||
presentation = read_feature("map_workspace_presentation")
|
||||
assert "fetch(" not in presentation
|
||||
assert "services/api" not in presentation
|
||||
assert not re.search(r"\w*[Aa]pi\.(get|post|put|delete)\(", presentation)
|
||||
|
||||
Reference in New Issue
Block a user