[WC-3450] Complete LeafletMap MobX migration with ViewModel#2276
[WC-3450] Complete LeafletMap MobX migration with ViewModel#2276iobuhov wants to merge 28 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
| - We migrated the widget's internal state management to a MobX container architecture, in line with other data widgets. | ||
|
|
||
| - We replaced the react-leaflet wrapper with a direct Leaflet integration, reducing dependencies while keeping the same map behavior. |
There was a problem hiding this comment.
This is too technical and internal, I believe. We describe to customers, so what is changing from their perspective and what they can expect.
- Replace all setTimeout/Promise delays with MobX when() helper - Mock convertAddressToLatLng at module level for deterministic tests - Add waitForLocations() helper using when() for observable changes - Configure MobX with enforceActions: 'never' for testing - Add timeout handling for error cases - Improve test reliability and speed (3.5s vs 13s) - All 42 tests still passing with 100% model layer coverage
Split 598-line test file into 3 self-contained files: - LocationResolver.unit.spec.ts (247 lines) - Basic functionality, empty inputs, API keys - LocationResolver.integration.spec.ts (321 lines) - Mixed markers, caching, errors, integration - LocationResolver.reactivity.spec.ts (226 lines) - MobX reactions and observable behavior Benefits: - Each file self-contained with inline setup (no helpers folder) - Follows Gallery/Datagrid patterns in the repo - Easy to locate specific test types - Can run test files independently - No abstraction layers to learn - Clear test intent without jumping to other files All 45 tests passing with 100% model layer coverage maintained
Add 26 unit tests for convertStaticModeledMarker and convertDynamicModeledMarker: convertStaticModeledMarker (5 tests): - All fields present - Undefined optional fields - Number parsing with comma/period decimal separators - Custom marker image handling convertDynamicModeledMarker (21 tests): - Datasource availability (undefined, Loading, Unavailable, empty) - Coordinates location type (single/multiple markers, missing attributes) - Address location type (with/without address attribute) - Optional fields (title, onClick action, custom marker) - Edge cases (item IDs, NaN handling, empty strings, mixed attributes) Test results: - 26/26 tests passing - 100% code coverage on data.ts - Self-contained tests using @mendix/widget-plugin-test-utils - Uses list(), obj(), listAttribute(), listAction(), dynamic() helpers
Remove test 'should handle NaN from invalid coordinate strings' because: - Dynamic markers use ListAttributeValue<Big>, not string attributes - Mendix runtime ensures type safety - we never receive invalid coordinate types - The scenario being tested doesn't occur in practice Tests: 70 passed (was 71) Coverage: Still 100% on data.ts
Remove 'should handle multiple markers with different attributes' test because: - Already covered by 'should convert multiple markers with coordinates' test - Doesn't add unique value - tests same scenario with different attribute values - Simplifies test suite without losing coverage Tests: 69 passed (was 70) Coverage: Still 100% on data.ts
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Wire MapsContainer into Maps.tsx via useMapsContainer + ContainerProvider - Add MapsWidget observer component reading gate props and services - Add CurrentLocationService (reactive showCurrentLocation handling, stale-request guard, clears location when disabled) - Add injection-hooks following the gallery-web pattern - Rewrite LeafletMap on the imperative Leaflet API; drop react-leaflet and @types/react-leaflet; add explicit mobx + mobx-react-lite - Remove legacy useLocationResolver from utils/geodecode.ts - Replace react-leaflet snapshots with structural LeafletMap tests (15), add CurrentLocationService tests (6) and Maps integration tests (2) - Add OpenSpec change complete-mobx-migration (tdd-refactor schema) Tests: 77 passed across 9 suites; tsc and eslint clean; Maps.mpk builds Co-Authored-By: Claude <noreply@anthropic.com>
…ct marker utils, fix linting Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…package" This reverts commit a8ed724.
…ived in maps-web) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…emove baseMapLayer utility Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
… cleanup Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…/tile-layer.ts Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…fect Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…tile-layer utility Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…c apiKey Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
10f854b to
8ff28a2
Compare
AI Code Review
What was reviewed
Skipped (out of scope): Findings
|
Pull request type
Refactoring (e.g. file rename, variable rename, etc.)
Description
This PR completes the MobX migration for the LeafletMap component by:
Key Changes:
LeafletMapViewModelto handle all map logic with MobX reactionsLeafletMap.tsxcomponent (removed 184 lines) to focus on renderingsrc/utils/leaflet-markers.tsuseLeafletMapVMinjection hookArchitecture:
LeafletMapViewModel): Manages map instance, tile layer, markers, and reactivityLeafletMap): Pure presentational component using ref callback for setupLocationResolverServiceandCurrentLocationServiceTesting:
Impact:
This PR builds on the existing MobX infrastructure and completes the migration started in the parent branch.
What should be covered while testing?
Test in Mendix Studio Pro:
🤖 Generated with Claude Code