Visually Group User Visits with Work Areas on Microplanning Map#1144
Visually Group User Visits with Work Areas on Microplanning Map#1144zandre-eng wants to merge 7 commits intomainfrom
Conversation
WalkthroughThe pull request adds work-area attribution to the user-visit MVT tiles and implements corresponding client-side visualization. The backend changes extend the Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
commcare_connect/templates/microplanning/map_handler.html (1)
45-59: Minor:buildVisitCirclePaint()duplicates opacity logic withrefreshVisitStyling().
hasSelection ? 0.2 : 0.7is set here at layer creation and then immediately re-applied byrefreshVisitStyling()on line 651. Consider droppingcircle-opacityfrombuildVisitCirclePaint()(or havingrefreshVisitStyling()be the single source of truth) to avoid drift if the thresholds change.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@commcare_connect/templates/microplanning/map_handler.html` around lines 45 - 59, buildVisitCirclePaint currently hardcodes 'circle-opacity' (hasSelection ? 0.2 : 0.7) which duplicates the logic applied later in refreshVisitStyling; remove the 'circle-opacity' entry from buildVisitCirclePaint so refreshVisitStyling remains the single source of truth for opacity, and ensure refreshVisitStyling still sets the correct opacity based on highlightedWorkAreaId (no other callers rely on the removed property).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@commcare_connect/templates/microplanning/map_handler.html`:
- Around line 88-111: refreshVisitStyling() currently makes
'user-visits-highlight' visible whenever highlightedWorkAreaId is non-null,
ignoring this.showVisits; update the logic in refreshVisitStyling to only set
the 'user-visits-highlight' visibility to 'visible' when this.showVisits is true
and highlightedWorkAreaId is not null, otherwise set visibility to 'none' (keep
the existing filter behavior for setting the layer filter by work_area_id).
Ensure the check uses the component property this.showVisits and the layer name
'user-visits-highlight' so toggling Show Visits always keeps highlights hidden.
---
Nitpick comments:
In `@commcare_connect/templates/microplanning/map_handler.html`:
- Around line 45-59: buildVisitCirclePaint currently hardcodes 'circle-opacity'
(hasSelection ? 0.2 : 0.7) which duplicates the logic applied later in
refreshVisitStyling; remove the 'circle-opacity' entry from
buildVisitCirclePaint so refreshVisitStyling remains the single source of truth
for opacity, and ensure refreshVisitStyling still sets the correct opacity based
on highlightedWorkAreaId (no other callers rely on the removed property).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ab8b896c-1733-4872-bcb0-3129e0997e45
📒 Files selected for processing (3)
commcare_connect/microplanning/tests/test_views.pycommcare_connect/microplanning/views.pycommcare_connect/templates/microplanning/map_handler.html
9948e34 to
f6b48a1
Compare
pxwxnvermx
left a comment
There was a problem hiding this comment.
Just a small nit. Rest of the changes look good to me.
| 8, 13, | ||
| 14, 22, | ||
| ], | ||
| 'text-font': ['DIN Pro Medium', 'Arial Unicode MS Regular'], |
There was a problem hiding this comment.
nit: Can these be replaced with commonly available fonts or browser generics like "Sans", "Serif" etc?
There was a problem hiding this comment.
I got the following response after investigating it with Claude:
text-font here isn't a CSS font — Mapbox GL renders text from SDF glyphs served by the style's glyphs endpoint, so the value has to match a font the active style actually ships. Generics like Sans/Serif aren't resolved and the layer would fail to render glyphs. DIN Pro Medium + Arial Unicode MS Regular are the fonts bundled with the mapbox://styles/mapbox/standard style we're using (Arial Unicode is the standard CJK fallback). Happy to swap to another Mapbox-hosted stack if you'd prefer, but browser generics won't work here.
Given the above, I'm opted to keep the current font as it ships with the Mapbox style. For verification I did switch it to Sans font and received a 404 error in the browser's dev console which confirms that generic fonts won't work.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
💠 |
Product Description
When a work area is selected on the microplanning map, its linked user visits are now highlighted as green diamonds rendered on top of the existing red dots. All unrelated visits simultaneously fade to 20% opacity so the selected work area's visits visually pop out. Clearing the selection returns visits to their normal red-dot appearance.
An example of a work area selected, showing green diamonds overlaid on its visits with other visits dimmed:

An example of the default state (no selection) for comparison:

This only applies in normal mode — assignment mode does not support showing user visits and so highlighting of user visits does not apply to that mode.
Technical Summary
Link to ticket here
This is a release path 3 feature — Experiments & early stage iterations of product area.
Implementation is frontend-first with one small backend change. The existing
selectedFeaturein themapControllerAlpine component remains the single source of truth; a derivedhighlightedWorkAreaId(synced via a$watchonselectedFeature) drives styling on two Mapbox layers. Asymbollayer type is required for the diamond shape because Mapbox'scirclelayer can only render circles.work_area_idon visit tiles:UserVisitVectorLayernow includeswork_area_idintile_fieldsand in the queryset values so the client can filter features without re-fetching tiles.highlightedWorkAreaId, updated byupdateHighlightedWorkAreaId()which returnsnullin assignment mode or when nothing is selected, otherwise the selected feature's id. Wired via$watch('selectedFeature', ...).user-visits-highlightlayer (symbol type,◆text-field, green fill, white halo) added alongsideuser-visits-circle. Added viaaddVisitHighlightLayer()when visits are first shown; starts hidden.refreshVisitStyling(), wired via$watch('highlightedWorkAreaId', ...), setscircle-opacityon the base circles (0.2 dimmed / 0.7 default) and toggles + filters the highlight layer (["==", ["get", "work_area_id"], id]).buildVisitCirclePaint()so layer creation and styling refresh stay in sync.Safety Assurance
Safety story
This change is purely additive:
tile_fieldsand.values()additions ship one extra column (work_area_id) in tiles. Existing clients that don't reference the property ignore it.showVisitsand start hidden; in the default (no-selection) state the map looks and behaves exactly as before.updateHighlightedWorkAreaId, so the assignment-mode UX is unaffected.Automated test coverage
TestUserVisitVectorLayer.test_queryset_annotates_location_pointin commcare_connect/microplanning/tests/test_views.py was extended to assertvisit["work_area_id"] == visit_data.work_area.id. Catches regressions intile_fieldsor the queryset.values()that would stripwork_area_idfrom emitted tiles.Frontend interaction changes are verified manually (see QA Plan).
QA Plan
QA will not be performed for this change. Below is the testing plan for reference:
work_area_idmatches the selected work area.Labels & Review