Range param step updates#1580
Conversation
🚀 PR Environment Deployed
Access: https://era-13007.dev.pamdas.org |
There was a problem hiding this comment.
Pull request overview
Updates vector-tile range parameter handling to match API step buckets, and refactors map overlay/tiles integration to simplify source management and realtime overlay fetching behavior.
Changes:
- Add
getVtRangeParam+buildVtTileUrlutilities and update track/subject tile layers to use steppedrangebuckets. - Adjust realtime overlay fetching to paginate and remove bbox dependency; add segment eviction to prevent unbounded growth.
- Improve Mapbox layer/source cleanup safety (
safeRemoveMapLayer) and update related layer cleanup logic/tests.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/withSocketConnection/useRealTimeImplementation/config.js | Clarifies ordering requirement for overlay update vs subject store overwrite. |
| src/utils/tracks.js | Adds stepped range bucket logic and centralizes VT tile URL builder. |
| src/utils/tracks.test.js | Adds unit tests for getVtRangeParam bucket selection. |
| src/utils/map.js | Makes safeRemoveMapLayer resilient by checking layer existence first. |
| src/TrackSegmentsLayer/index.js | Uses getVtRangeParam/buildVtTileUrl, memoizes visible IDs, and cleans up map source on unmount/range change. |
| src/TrackSegmentsLayer/index.test.js | Updates expected range behavior and adds parametrized range tests (but mock needs fixing). |
| src/SubjectTrackLegend/index.js | Removes per-item description field from legend items. |
| src/SubjectTileLayer/index.test.js | Adds getVtRangeParam mock (but mock needs fixing). |
| src/SubjectTileLayer/index.js | Switches to its own vector tile source and cleans up that source on unmount/range change. |
| src/Map/index.js | Refactors overlay fetch into callback and removes map dependency from overlay refresh. |
| src/ducks/realtime-overlay.js | Changes overlay subject fetch to paginate and adds eviction of stale segments in reducer. |
| jest.mock('../utils/tracks', () => ({ | ||
| getVtRangeParam: (days) => { | ||
| const steps = [30, 45, 60, 90, 150, 210, 365, 500]; | ||
| const step = steps.find((s) => days <= s); | ||
| return step !== undefined ? String(step) : 'all'; | ||
| }, | ||
| })); |
| // Ensure the shared vector tile source exists (TrackSegmentsLayer may | ||
| // have already created it with the same range param). |
| // Evict segments outside the overlay window before appending; discard | ||
| // entries with no start_time to prevent unbounded growth from malformed payloads. | ||
| const cutoff = new Date(Date.now() - REALTIME_OVERLAY_WINDOW_MS).toISOString(); | ||
| const features = [ | ||
| ...(state.segments.features || []).filter( |
| [500, '500'], | ||
| [501, 'all'], | ||
| [999, 'all'], | ||
| ])('returns %s for %i days', (days, expected) => { |
| [500, '500'], | ||
| [501, 'all'], | ||
| [999, 'all'], | ||
| ])('uses range=%s in tile URL when track length is %i days', (trackLengthInDays, expectedRange) => { |
| @@ -363,7 +393,6 @@ describe('TrackSegmentsLayer', () => { | |||
|
|
|||
| expect(safeRemoveMapLayer).toHaveBeenCalledWith(mockMap, 'track-segments-layer'); | |||
| expect(safeRemoveMapLayer).toHaveBeenCalledWith(mockMap, 'track-segments-start-layer'); | |||
| // Source must NOT be removed — it is shared with SubjectTileLayer | |||
| expect(safeRemoveMapLayer).toHaveBeenCalledTimes(2); | |||
| // Discard segments (existing or incoming) with no start_time or outside | ||
| // the overlay window to prevent unbounded growth from malformed payloads. | ||
| const cutoff = new Date(Date.now() - REALTIME_OVERLAY_WINDOW_MS).toISOString(); | ||
| const isWithinWindow = (f) => f.properties?.start_time && f.properties.start_time >= cutoff; |
| jest.mock('../utils/tracks', () => ({ | ||
| getVtRangeParam: (days) => { | ||
| const steps = [30, 45, 60, 90, 150, 210, 365, 500]; | ||
| const step = steps.find((s) => days <= s); | ||
| return step !== undefined ? String(step) : 'all'; | ||
| }, | ||
| buildVtTileUrl: (rangeParam) => `http://test-api.com/observations/segments/tiles/{z}/{x}/{y}.pbf?range=${rangeParam}`, | ||
| })); |
| jest.mock('../utils/tracks', () => ({ | ||
| getVtRangeParam: (days) => { | ||
| const steps = [30, 45, 60, 90, 150, 210, 365, 500]; | ||
| const step = steps.find((s) => days <= s); | ||
| return step !== undefined ? String(step) : 'all'; | ||
| }, | ||
| buildVtTileUrl: (rangeParam) => `http://test-api.com/observations/segments/tiles/{z}/{x}/{y}.pbf?range=${rangeParam}`, | ||
| })); |
|
To keep the environment alive:
|
|
🗑️ Environment torn down due to inactivity |
8 similar comments
|
🗑️ Environment torn down due to inactivity |
|
🗑️ Environment torn down due to inactivity |
|
🗑️ Environment torn down due to inactivity |
|
🗑️ Environment torn down due to inactivity |
|
🗑️ Environment torn down due to inactivity |
|
🗑️ Environment torn down due to inactivity |
|
🗑️ Environment torn down due to inactivity |
|
🗑️ Environment torn down due to inactivity |
|
🗑️ Environment torn down due to inactivity |
feat: new range param steps, as per API updates.
feat: updating/simplifing geojson overlay, unbinding map moveend events to match.
What does this PR do?
https://allenai.atlassian.net/browse/ERA-13007
Evidence
N/A
Relevant link(s)
Notes
N/A