fix(deckgl-map): update legend visibility when layer toggles change#2371
fix(deckgl-map): update legend visibility when layer toggles change#2371koala73 merged 4 commits intokoala73:mainfrom
Conversation
Previously the legend was created once in createLegend() and never updated when layer toggles changed. Legend items would always show all 5 tech variant items regardless of which layers were enabled. Changes: - Added data-layer attribute to each legend item linking it to the corresponding layer key (startupHubs, techHQs, accelerators, etc.) - Added updateLegend() method that shows/hides legend items based on this.state.layers visibility - updateLegend() is called from createLegend() on init and from the layer toggle change handler on each toggle Fixes koala73#1967
|
Someone is attempting to deploy a commit to the Elie Team on Vercel. A member of the Team first needs to authorize it. |
Greptile SummaryThis PR fixes legend visibility in the Map/Globe view by adding Confidence Score: 4/5Safe to merge for the tech variant (the reported bug), but the fix is incomplete for the happy variant and all programmatic layer-change paths. Two P1 defects remain: setLayers/enableLayer/toggleLayer never call updateLegend(), and the Aircraft legend entry in the happy variant has an empty layerKey keeping it permanently visible. Both are straightforward one-line fixes, but they represent genuine incorrect behavior on currently reachable paths. src/components/DeckGLMap.ts — specifically the setLayers, enableLayer, toggleLayer methods and the happy variant legend item for Aircraft. Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant CheckboxHandler
participant setLayers
participant enableLayer
participant toggleLayer
participant updateLegend
participant Legend DOM
User->>CheckboxHandler: Toggle layer checkbox
CheckboxHandler->>updateLegend: updateLegend() ✅
updateLegend->>Legend DOM: Show/hide .legend-item[data-layer]
Note over setLayers,Legend DOM: Programmatic paths — legend NOT updated ❌
setLayers->>setLayers: this.state.layers = {...layers}
setLayers->>setLayers: this.render()
setLayers--xLegend DOM: updateLegend() never called
enableLayer->>enableLayer: this.state.layers[layer] = true
enableLayer->>enableLayer: this.render()
enableLayer--xLegend DOM: updateLegend() never called
toggleLayer->>toggleLayer: this.state.layers[layer] = !prev
toggleLayer->>toggleLayer: this.render()
toggleLayer--xLegend DOM: updateLegend() never called
|
…y layerKeys - Breakthrough layerKey: '' → 'positiveEvents' - Aircraft layerKey: '' (happy variant) → 'flights' - Call updateLegend() from setLayers(), enableLayer(), toggleLayer() so legend stays in sync after programmatic changes (URL restore, presets)
…ontainer field
- legendItems array now typed as { shape: string; label: string; layerKey: keyof MapLayers }[]
so typos in layer keys are caught at compile time
- Remove unnecessary legendContainer field — updateLegend() queries this.container directly
- Add runtime guard in updateLegend() with 'in' check before cast
- Remove dead conditional (layerKey ? ...) since all items now have a key
- Remove dead ?? false (state.layers values are always boolean)
…ty() PR koala73#2370 had landed updateLegendVisibility() (text-matching approach) on main. PR koala73#2371 supersedes it with the data-layer attribute approach (updateLegend()). - Resolve 3 conflict markers, keeping updateLegend() calls - Remove redundant updateLegendVisibility() call from constructor - Remove redundant updateLegendVisibility() call from setLayers() - Delete the entire updateLegendVisibility() method and layerToLabels map
Summary
Fixes the Map/Globe legend so it updates immediately when layer toggles are changed.
Type of change
Affected areas
/api/*)Bug description
The legend at the bottom of the Map/Globe was created once via
createLegend()and never updated when layer toggles in the side panel changed. This caused all 5 legend items (Startup Hub, Tech HQ, Accelerator, Cloud Region, Datacenter for tech variant) to always display regardless of which layers were actually enabled.Fix
data-layerattribute to each legend item increateLegend()linking it to the corresponding layer key (e.g.startupHubs,techHQs,accelerators,cloudRegions,datacenters)updateLegend()method that shows/hides legend items based onthis.state.layersvisibilityupdateLegend()is called fromcreateLegend()on init and from the layer toggle change handler on every toggleChecklist
npm run typecheck)Fixes #1967
🤖 Generated with Claude Code