Skip to content

feat(search): a searched place the atlas holds opens its own page - #555

Merged
Ardnived merged 7 commits into
mainfrom
feat/search-region-redirect
Nov 28, 2026
Merged

Ardnived merged 7 commits into
mainfrom
feat/search-region-redirect

Conversation

@Ardnived

@Ardnived Ardnived commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Picking a country, region or town that SahajCloud holds as a Region now opens its page instead of /search.
  • The match compares Mapbox ids: the picked feature's mapbox_id against Region.mapboxId. There is no extra request.

Change outline

Flow — a pick from the search field

Today's pick always pushes /search. Now it first asks the cached region tree whether the place has a page.

 SearchField.handleSelect(feature)                       src/views/shared.tsx
+  kept = preserveSearchState(params)                    # filters + sort, as the search carries
+  ids = geocodeRegionIds(feature)                       src/lib/geocode.ts
+    [own mapbox_id, context.place.mapbox_id]            # town only for locality / neighborhood / postcode
+  match = searchedRegionRoute(                          src/config/api/fetch.ts
+    getQueryData(regionsQuery), getQueryData(geojsonQuery),   # cache only, never fetched
+    ids, filtersFromParams(kept))
+    either cache cold → undefined
+    first candidate region with ≥1 class passing the filters → { id, route }
+    else → undefined                                    # an empty region passes to the town
+  match, not this page (isCanonicalPath) → navigate(withQuery(match.route, kept))
+  match.id === ids[0] → stay put                        # the pick IS this page
   otherwise → navigate(placeSearchPath(...))            # no match, or a CLIMBED match to this page

Contract — the wholesale region read

The region tree every visitor reads once per stale window now selects one more field.

 GET /api/regions  select                               src/config/api/fetch.ts  REGIONS_SELECT
   slug, name, subtitle, level, parent, webPath, webUrl
+  mapboxId                                              # RegionNodeSchema: z.string().nullish()

Camera — a region page with no area of its own

A region's bounds are the bounds of the LOCATED classes under it, so a place whose only classes are online has none and frameRegion moved nothing.

 RegionView                                              src/views/RegionView/RegionView.tsx
+  framed = useFrameableRegion(slug)                     src/views/shared.tsx  # OnlineView's climb
-  frameRegion(region)
+  frameRegion(framed ?? region)                         # `region` still clears boundary + pin

Files — withQuery

 src/lib/shape/
-├── navigation.ts   # withQuery (module-private)
+├── path.ts         # withQuery, exported beside the other route builders
 └── navigation.ts   # imports it

Preview

  • App, a search from the first screen — preview pending
  • Component library — preview pending

Test results

  • Lean gate: ✓ lint, typecheck, test:run (2791 passed, 1 skipped)
  • Targeted specs: fetch.test.ts searchedRegionRoute (4), geocode.test.ts geocodeRegionIds (6), shared.search-pick.test.tsx (4), RegionView.test.tsx framing (2). Each new assertion was watched failing against its defect — the climb assertion against frameRegion(region), the fallback one against if (framed) frameRegion(framed).
  • Browser lane: ✓ 39 passed, re-run on this head
  • Build: N/A (CI)

Manual verification

  1. Search a town that has an atlas page (e.g. London) and pick it. Its page opens with any active filters kept.
  2. Search a neighbourhood or postcode inside it (e.g. Camden Town, SW1A 1AA). The town's page opens.
  3. Search a place with no page. The distance-ranked search opens as before.
  4. Set a filter that leaves a town with no class, then pick that town. The search opens.
  5. On a town's page, pick the same town in its own search field. Nothing navigates, and Back does not repeat the page.
  6. On that town's page, pick a neighbourhood or postcode inside it. The distance-ranked search opens on that point.
  7. Search a place whose only classes are online (e.g. Ghent) and pick it. Its page opens and the map moves to the surrounding area, rather than staying where it was.

Notes for reviewer

  • The three behaviour rules are the owner's decisions, made before implementation: match client-side on the cached tree, redirect only to a region with classes, and climb no higher than the town.
  • A region page with no area of its own now climbs to the nearest ancestor it can fit (option D on the framing thread, the reviewer's choice). The two sources the other options wanted do not exist: SahajCloud serves no region geometry, and an online class stores no coordinates.
  • The id match needs a temporary lookup to return the same id a permanent one stores. Measured identical on 2026-11-27 for country, region, place and locality, for a neighbourhood's and a postcode's context.place, and for a place asked in three languages.
Detail

Self-review (/code-review medium), dismissed findings:

  • Duplicate mapboxId picks the wrong region: SahajCloud's Region.mapboxId is unique: true, with a unique index (regions_mapbox_id_idx).
  • A postcode climbing to the town drops the picked point: that is the owner's "climb to the town" decision.
  • A same-page pick gives no feedback: the visitor is already on the page they asked for. The comparison uses isCanonicalPath, so encoded slugs match. ⚠ This holds for the pick's OWN id only — a neighbourhood or postcode that merely climbs to this page searches its point instead.
  • Ids measured only on London: settled by measuring every feature type the match reads (above).

Self-review, fixed:

  • An empty own region no longer stops the climb to the town.

Simplify pass, applied:

  • A pure searchedRegionRoute takes the cached reads as arguments, instead of an api member reading the module singleton. So it follows a provider-scoped client too, as the story harness uses.
  • A per-pick find replaces a module-level memo. That memo saved about 7 µs once per pick, at the 646 regions production holds.

Simplify pass, kept:

  • visibleFeatures plus countUnder, rather than an any short-circuit. It stays the one filter predicate. It costs 5–67 µs warm at today's sizes, and its cold occurrence cache is the one the next view fills anyway.

Security review (triggered by src/config/api/): no findings. The route passes safePath through regionRoute, and the ids are only compared.

Cost: mapboxId adds about 23 KB raw, 4–5 KB compressed, to the region tree at 646 regions. That is per visitor per stale window, and it reads beside the feed at boot.

🤖 Generated with Claude Code

Ardnived and others added 4 commits November 27, 2026 22:49
Picking a country, region or town from the search field now opens that
region's page instead of the distance-ranked results, when SahajCloud
stores the picked Mapbox feature as a Region's `mapboxId`. A locality,
neighbourhood or postcode tries the town around it too, never anything
coarser. A region holding no class that passes the current filters
keeps the search, which lists the nearest classes.

The region tree now selects `mapboxId`, so the match is a lookup in the
cached tree with no request of its own; a cold cache searches instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The match is a pure, exported `searchedRegionRoute` over the two cached
reads, which the field reads at its call site, so it leaves the async
`api` object and its module-level memo. It passes over an empty region
to the next candidate, so a pick whose own region holds no class still
opens the town around it. `withQuery` moves to `path.ts` beside the
other route builders, and the same-page guard uses `isCanonicalPath`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sydevs-dispatcher

sydevs-dispatcher Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

🤖 no session running

recent dispatches
  • 16:34Z address-review · attempt 1 · session · done
  • 16:34Z address-review · attempt 1 · session
  • 15:43Z address-review · attempt 1 · session · done
  • 15:43Z address-review · attempt 1 · session
  • 06:06Z address-review · attempt 1 · session · done

Written by the sydevs dispatcher. Sessions never edit this comment.

@sydevs-dispatcher sydevs-dispatcher Bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 28, 2026
@sydevs-dispatcher sydevs-dispatcher Bot moved this from Pending to Working in SYDevelopers Technical Roadmap Nov 28, 2026

@sydevs-bot sydevs-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧐 Adversarial review

The shape is right and the diff is the size of the problem: four new pieces, each with a caller, and the gate reuses the one visibleFeatures predicate rather than inventing a second. The contract holds — Region.mapboxId is required: true, unique: true upstream with no field-level client gate, so the extra select is readable.

What the redirect drops is the picked point: the geocoded bbox/center that placeSearchPath carried. Two reachable picks then leave the map where it was, one with no feedback at all.

Findings

  • should-fix — a climbed pick onto the page you are already on does nothing: src/views/shared.tsx:324.
  • should-fix — Streamline: fold WITHIN_TOWN into its one reader: src/lib/geocode.ts:97.
  • consider — an online-only region opens with no framing information: src/config/api/fetch.ts:507.

What was checked

Read whole on the branch: fetch.ts, geocode.ts, path.ts, shared.tsx, use-map-controller-mapbox.tsx, hierarchy.ts, RegionView.tsx. Both keys match what loadRegions/loadGeojson write, and Widget.tsx:148 provides that same module client, so getQueryData hits. preserveSearchState nulls region, so the gate's filters and the destination URL's agree exactly. Change outline matched line by line; both ## Preview lines read "pending" and this repo configures no preview surface.

Consumer side: SahajCloud Regions.ts and src/plugins/access. A city is geocoded as place,locality, covered by the own-id-first order. PLACE_TYPES admits district, which correctly climbs nowhere.

Ladder: no new dependency. Streamliner: 4 pieces, 2 kept, 1 posted. Dropped its other — reading the module queryClient inside searchedRegionRoute would lose the Ladle harness, which seeds regionsQuery().queryKey on its own client (story-harness.tsx:311).

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

Comment thread src/views/shared.tsx Resolved
Comment thread src/lib/geocode.ts Resolved
Comment thread src/config/api/fetch.ts Resolved
@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 28, 2026
@sydevs-dispatcher sydevs-dispatcher Bot moved this from Working to Pending in SYDevelopers Technical Roadmap Nov 28, 2026
@sydevs-dispatcher sydevs-dispatcher Bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 28, 2026
@sydevs-dispatcher sydevs-dispatcher Bot moved this from Pending to Working in SYDevelopers Technical Roadmap Nov 28, 2026
A pick of a neighbourhood or postcode inside the town whose page is open
resolved to that same page, and the same-page guard then returned: no
navigation, no map move, no feedback. Before the redirect that pick opened
the distance-ranked search on its point.

`searchedRegionRoute` now reports the id that matched beside the route, so
the field stays put only when the matched id is the pick's own. A match
reached by climbing falls through to `placeSearchPath`, as a pick with no
region page already did.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjY9E9Qf29pqPqL8yuK
The set had one reader two lines below it. It is a local now, keeping the
`FeatureTypes` literal so a typo fails to compile and the `ReadonlySet<string>`
read because the vendor types `feature_type` as a string — a plain
`Set<FeatureTypes>.has` of it does not compile.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjY9E9Qf29pqPqL8yuK
@sydevs-bot

Copy link
Copy Markdown
Contributor

Two of the three review threads adopted, one back to you.

  • Climbed pick does nothing — 7dd86ee. searchedRegionRoute reports the id that matched, so the field stays put only for the pick's own id. A climbed match searches its point.
  • Fold WITHIN_TOWN — 18a7e7c. Into a local, not the ternary's condition: feature_type is typed string, so Set<FeatureTypes>.has of it fails tsc.
  • Online-only region, no framing — asked. Three options there, recommendation first. Nothing built. The thread holds the merge.

Lean gate ✓ (2789 passed, 1 skipped). Security sweep of src/config/api/: no new sink. Browser lane ✓ (39 passed).

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 28, 2026
@sydevs-dispatcher sydevs-dispatcher Bot moved this from Working to Awaiting in SYDevelopers Technical Roadmap Nov 28, 2026
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
sahajatlas-design 374152d Nov 28 2026, 04:49 PM

@sydevs-dispatcher sydevs-dispatcher Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved for Ardnived, who wrote it: GitHub refuses an author's own approval. CI is green and the automated review has run. Enable auto-merge when you want it merged: the queue tests it against its base. 🤖 Written by the sydevs autonomous loop — see what this is

@sydevs-dispatcher sydevs-dispatcher Bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 28, 2026
@sydevs-dispatcher sydevs-dispatcher Bot moved this from Awaiting to Working in SYDevelopers Technical Roadmap Nov 28, 2026
@sydevs-bot

Copy link
Copy Markdown
Contributor

One thread, back to you. Nothing pushed, and the branch is already current with main.

  • Online-only region, no framing — answered. Neither source you asked about exists. bounds is derived here from the located classes under a region, not served by SahajCloud, and an online class stores no coordinates: its address fields are offline-only. Two options added there, recommendation first — reuse the ancestor climb OnlineView already has, or store a bbox upstream.

The thread holds the merge until you choose.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 28, 2026
@sydevs-dispatcher

Copy link
Copy Markdown
Contributor

Approved, but this thread still waits on you, and the ruleset will not merge until it is resolved: #555 (comment). Reply there, or resolve it.

🤖 sydevs dispatcher

@sydevs-dispatcher sydevs-dispatcher Bot moved this from Working to Awaiting in SYDevelopers Technical Roadmap Nov 28, 2026
@sydevs-dispatcher sydevs-dispatcher Bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 28, 2026
@sydevs-dispatcher sydevs-dispatcher Bot moved this from Awaiting to Working in SYDevelopers Technical Roadmap Nov 28, 2026
A region whose only classes are online has no bounds — `boundsUnder` drops
placeless points — so `frameRegion` moved nothing and the map stayed wherever
the visitor came from. Searching Ghent opened its page over the last camera.

`useFrameableRegion` already answered this for `OnlineView`; the region page
now reads it too. It falls back to the region itself rather than skipping the
call, because `frameRegion` is also what drops the boundary and the pin the
previous view left on the map.

Option D of the four offered on the review thread, chosen by the reviewer.
SahajCloud serves no region geometry and an online class stores no
coordinates, so neither source the other options wanted exists today.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjVtMdQvEDvPCuRHHq3
@sydevs-bot

Copy link
Copy Markdown
Contributor

One thread, built and resolved. Pushed to a relay branch for Actions to land.

  • Online-only region, no framing — D, your choice, in 374152d. The region page reads the ancestor climb OnlineView already had, so a place with no bounds of its own frames the nearest area that can be fitted. It passes the region itself when nothing above it fits either, because frameRegion is also what clears the boundary and the pin the previous view drew.

Lean gate green: 2791 passed, 1 skipped. Browser lane green, 39. Two new RegionView.test.tsx assertions, each watched failing against its own defect. The CHANGELOG.md entry gains the camera clause, and the body a ## Change outline section for it.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 28, 2026
@sydevs-dispatcher sydevs-dispatcher Bot moved this from Working to Awaiting in SYDevelopers Technical Roadmap Nov 28, 2026
@Ardnived
Ardnived added this pull request to the merge queue Nov 28, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 28, 2026
@Ardnived
Ardnived added this pull request to the merge queue Nov 28, 2026
Merged via the queue into main with commit 857658f Nov 28, 2026
14 checks passed
@Ardnived
Ardnived deleted the feat/search-region-redirect branch November 28, 2026 17:24
@sydevs-dispatcher sydevs-dispatcher Bot moved this from Awaiting to Done in SYDevelopers Technical Roadmap Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

3 participants