Repository navigation
Show sync health per district on a map - #41
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3.
What changes for you
/syncsnow opens on a map of the thirteen districts, coloured by the share of each district's devices that synced in the last seven days, with a legend. Hovering outlines a district; clicking opens a popup with its name, device count and sync percentage, and filters the table underneath to that district. The selection is in the URL —/syncs?district=143— so the page can be sent to someone.On the seeded data the map shows what the table could not: Bo, Kambia and Port Loko at 94%, and Kono, Western Area and Pujehun at 0% — the two districts the seed stops ten days ago plus the nearly silent one.
How it works
districtSyncHealthreturns one row per district: the two counts and thegeometrycolumn as it is. It starts from the districts and joins outwards, so a district with no devices comes back with zeroes instead of disappearing. No PostGIS:geometryis plainjsonband MapLibre consumes it directly (ADR 0007).ui/health.tsturns the counts into a percentage, a colour bucket, the GeoJSON MapLibre draws, and the bounds it frames. Pure, so the boundaries are pinned by tests.react-map-gl, loaded with a dynamicimport()— see ADR 0015. That keeps its megabyte in its own chunk, fetched by the page that draws a map and no other, and keeps it away from the server render.Two things found on the way
A latent bug in
listRecentSyncs. It already matched a facility to its district withsplit_part(facility.path, '.', 2)::int. Adding awhereon the district makes Postgres reorder the join and evaluate that expression before it knows which rows are facilities — including the country, whose path is one segment, so the cast gets''and the query raisesinvalid input syntax for type integer: "". The expression is nownullif(split_part(...), '')::int, shared by both queries with a comment saying why. Any futurewhereon that join would have hit it.An out-of-range district id 500'd.
?district=3000000000reachedwhere district.id = $1against anint4. Bounded now in the route schema and in the procedure.Tests
79 pass. The query on in-process Postgres; the pure module and the legend in Node and jsdom.
DistrictMap.tsxhas no test: jsdom has no WebGL andpnpm testruns no browser. Everything decidable without a canvas was moved out of it so the exemption stays narrow — that boundary is the subject of ADR 0015. The preview deployment is the check for this PR, and it is the one thing I could not verify locally.Two notes for the reviewer:
Documents
docs/superpowers/specs/2026-09-18-district-sync-map-design.mddocs/superpowers/plans/2026-09-18-district-sync-map.mddocs/adr/0015-maplibre-directly-and-an-untested-canvas.md