-
Notifications
You must be signed in to change notification settings - Fork 9
[OSDEV-2373] Add geographic information section #904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
VadimKovalenkoSNF
merged 43 commits into
main
from
OSDEV-2373-geographic-information-section
Mar 11, 2026
Merged
Changes from 36 commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
7fcd7bc
Add interactive map (partial impl)
VadimKovalenkoSNF 174533e
Connect Map component
VadimKovalenkoSNF 2cef5c0
Test different Map layout
VadimKovalenkoSNF 130ad33
Connect satellite layout
VadimKovalenkoSNF 374374d
Connect back to location button
VadimKovalenkoSNF b037689
Adjust map control buttons
VadimKovalenkoSNF b400e2f
Adjust map to show multiple facilities
VadimKovalenkoSNF 24b0197
Refactor map grid layout to render green circles
VadimKovalenkoSNF c9038fc
Fix infinite production location re-render on marker click
VadimKovalenkoSNF 7007ba6
Refactor styles for Open in Google Maps button
VadimKovalenkoSNF b55cbec
Add Drag to Pan info element
VadimKovalenkoSNF 46cca6e
Add legend for the map grid view
VadimKovalenkoSNF adadd8b
Add styles to subsection title
VadimKovalenkoSNF 078d444
Set adaptive height to the Map component
VadimKovalenkoSNF 21ddb2a
Merge branch 'main' into OSDEV-2373-geographic-information-section
VadimKovalenkoSNF 972b109
Connect data points to Geographic Information section
VadimKovalenkoSNF 0a874a5
Show date for coordinates contribution
VadimKovalenkoSNF 8b464c7
Add tooltip
VadimKovalenkoSNF e80bb61
Refactor field items count for address field
VadimKovalenkoSNF 99fde42
Update release notes
VadimKovalenkoSNF b69467a
Remove redundant code
VadimKovalenkoSNF d6d7488
Add unit tests
VadimKovalenkoSNF 386c6b1
Prevent mismatched date provenance for coordinates contributor
VadimKovalenkoSNF 9bd7ce8
Preserve all canonical entries in address and coordinates contributions
VadimKovalenkoSNF 4a30015
Hide Google Maps button and align zoom when facility has no coordinates
VadimKovalenkoSNF e5d8f9e
Remove unused leaflet settings
VadimKovalenkoSNF 1548eb6
Fix lint issues for setupTests
VadimKovalenkoSNF 13f778c
Fix unit test
VadimKovalenkoSNF e16b266
Require coordinate match for canonical other_location selection
VadimKovalenkoSNF a775e6f
Show no attribution when no address field matches the canonical address
VadimKovalenkoSNF 2ce3762
Minor refactoring of the formatClaimDate
VadimKovalenkoSNF 8106e6a
fix: use created_at || updated_at fallback for address date in utils.js
VadimKovalenkoSNF ecd9809
Remove utc() from the claim date
VadimKovalenkoSNF 3aad9cf
fix: use epsilon tolerance for coordinate matching to handle float pr…
VadimKovalenkoSNF 0f93d62
fix: remove contributors from fetchFacility useEffect dependency array
VadimKovalenkoSNF d392060
Remove coordinates date based on contributor info
VadimKovalenkoSNF b26ef9e
Remove redundant comments, minor fixes
VadimKovalenkoSNF 24bae24
Only show the spinner for stale data if the fetch hasnt failed
VadimKovalenkoSNF a93fc97
Merge branch 'main' into OSDEV-2373-geographic-information-section
VadimKovalenkoSNF 7fbc45f
Fix geomarker overlap
VadimKovalenkoSNF a8be8bb
Fix unit test
VadimKovalenkoSNF 0ea1b36
Add resetAllFilters
VadimKovalenkoSNF 7025124
Do not count null promotedContribution as an anonymous contributor
VadimKovalenkoSNF File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
279 changes: 279 additions & 0 deletions
279
src/react/src/__tests__/components/ProductionLocationDetailsMap.test.jsx
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,279 @@ | ||
| import React from 'react'; | ||
| import { MemoryRouter, Route } from 'react-router-dom'; | ||
| import { render, screen, fireEvent } from '@testing-library/react'; | ||
| import { createStore } from 'redux'; | ||
| import { Provider } from 'react-redux'; | ||
|
|
||
| import ProductionLocationDetailsMap from '../../components/ProductionLocation/ProductionLocationDetailsMap/ProductionLocationDetailsMap'; | ||
|
|
||
| // constants.js calls L.icon() at module initialisation time. | ||
| jest.mock('leaflet', () => ({ icon: jest.fn(() => ({})) })); | ||
| jest.mock('leaflet/dist/leaflet.css', () => {}); | ||
|
|
||
| // react-leaflet's Map receives a ref. Explicit React.xxx calls inside jest.mock | ||
| // factories are blocked by babel-plugin-jest-hoist (which runs before the JSX | ||
| // transform), so we use a plain functional component here — the ref warning | ||
| // in tests is acceptable. | ||
| jest.mock('react-leaflet', () => ({ | ||
| Map: ({ children }) => <div data-testid="leaflet-map">{children}</div>, | ||
|
Check warning on line 18 in src/react/src/__tests__/components/ProductionLocationDetailsMap.test.jsx
|
||
| TileLayer: () => null, | ||
| })); | ||
|
|
||
| jest.mock('react-leaflet-control', () => ({ children }) => <>{children}</>); | ||
|
Check warning on line 22 in src/react/src/__tests__/components/ProductionLocationDetailsMap.test.jsx
|
||
|
|
||
| jest.mock('../../components/VectorTileFacilitiesLayer', () => () => null); | ||
| jest.mock('../../components/VectorTileFacilityGridLayer', () => () => null); | ||
| jest.mock('../../components/VectorTileGridLegend', () => () => null); | ||
|
|
||
| // DataPoint and ContributionsDrawer transitively import util.js which depends | ||
| // on packages not installed in the test environment. Stub them with lightweight | ||
| // components that preserve the behaviour under test. | ||
| jest.mock( | ||
| '../../components/ProductionLocation/DataPoint/DataPoint', | ||
| () => ({ | ||
| __esModule: true, | ||
| default: ({ label, value, drawerData, onOpenDrawer, renderDrawer }) => { | ||
| const hasContributions = | ||
| Array.isArray(drawerData?.contributions) && | ||
| drawerData.contributions.length > 0 && | ||
| !!onOpenDrawer; | ||
| return ( | ||
| <div data-testid="data-point"> | ||
| <span data-testid="data-point-label">{label}</span> | ||
| <span data-testid="data-point-value">{value}</span> | ||
| {hasContributions && ( | ||
| <button | ||
| type="button" | ||
| data-testid="data-point-sources-button" | ||
| onClick={onOpenDrawer} | ||
| > | ||
| {`+${drawerData.contributions.length} data sources`} | ||
| </button> | ||
| )} | ||
| {typeof renderDrawer === 'function' && renderDrawer()} | ||
| </div> | ||
| ); | ||
| }, | ||
| }), | ||
| ); | ||
|
|
||
| jest.mock( | ||
| '../../components/ProductionLocation/ContributionsDrawer/ContributionsDrawer', | ||
| () => ({ | ||
| __esModule: true, | ||
| default: ({ open }) => | ||
| open ? <div data-testid="contributions-drawer" /> : null, | ||
| }), | ||
| ); | ||
|
|
||
| const FACILITY_ADDRESS = '123 Main St, New York'; | ||
| const FACILITY_LNG = -73.8314318; | ||
| const FACILITY_LAT = 40.762569; | ||
| const EXPECTED_COORD_DISPLAY = `${FACILITY_LAT}, ${FACILITY_LNG}`; | ||
|
|
||
| const makeFacility = (overrides = {}) => ({ | ||
| type: 'Feature', | ||
| geometry: { | ||
| type: 'Point', | ||
| coordinates: [FACILITY_LNG, FACILITY_LAT], | ||
| }, | ||
| properties: { | ||
| address: FACILITY_ADDRESS, | ||
| other_locations: [], | ||
| created_from: { | ||
| contributor: 'Test Org', | ||
| created_at: '2023-01-01T00:00:00Z', | ||
| }, | ||
| extended_fields: { | ||
| address: [ | ||
| { | ||
| value: FACILITY_ADDRESS, | ||
| contributor_name: 'Test Org', | ||
| contributor_id: 1, | ||
| created_at: '2023-01-01T00:00:00Z', | ||
| updated_at: '2023-01-01T00:00:00Z', | ||
| is_from_claim: false, | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| ...overrides, | ||
| }); | ||
|
|
||
| // Use a minimal store instead of the full configureStore to avoid pulling in | ||
| // reducers that transitively import util.js. | ||
| const makeStore = facilityData => | ||
| createStore(() => ({ | ||
| facilities: { singleFacility: { data: facilityData } }, | ||
| vectorTileLayer: { gridColorRamp: [] }, | ||
| })); | ||
|
|
||
| const renderMap = (facilityData = null) => | ||
| render( | ||
| <Provider store={makeStore(facilityData)}> | ||
| <MemoryRouter initialEntries={['/production-locations/OS12345']}> | ||
| <Route | ||
| path="/production-locations/:osID" | ||
| component={ProductionLocationDetailsMap} | ||
| /> | ||
| </MemoryRouter> | ||
| </Provider>, | ||
| ); | ||
|
|
||
| describe('ProductionLocationDetailsMap', () => { | ||
| describe('section header', () => { | ||
| it('renders the "Geographic information" section title', () => { | ||
| renderMap(makeFacility()); | ||
|
|
||
| expect( | ||
| screen.getByText('Geographic information'), | ||
| ).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('info grid', () => { | ||
| it('renders the info grid container', () => { | ||
| renderMap(makeFacility()); | ||
|
|
||
| expect( | ||
| screen.getByTestId('production-location-info-grid'), | ||
| ).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders an address row and a coordinates row', () => { | ||
| renderMap(makeFacility()); | ||
|
|
||
| expect( | ||
| screen.getByTestId('production-location-address-row'), | ||
| ).toBeInTheDocument(); | ||
| expect( | ||
| screen.getByTestId('production-location-coordinates-row'), | ||
| ).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('address DataPoint', () => { | ||
| it('renders the "Address" label', () => { | ||
| renderMap(makeFacility()); | ||
|
|
||
| const addressRow = screen.getByTestId( | ||
| 'production-location-address-row', | ||
| ); | ||
| expect(addressRow).toHaveTextContent('Address'); | ||
| }); | ||
|
|
||
| it('displays the facility address', () => { | ||
| renderMap(makeFacility()); | ||
|
|
||
| const addressRow = screen.getByTestId( | ||
| 'production-location-address-row', | ||
| ); | ||
| expect(addressRow).toHaveTextContent(FACILITY_ADDRESS); | ||
| }); | ||
|
|
||
| it('shows "—" when properties.address is empty', () => { | ||
| const facility = makeFacility(); | ||
| facility.properties.address = ''; | ||
| facility.properties.extended_fields.address = []; | ||
| renderMap(facility); | ||
|
|
||
| const addressRow = screen.getByTestId( | ||
| 'production-location-address-row', | ||
| ); | ||
| expect(addressRow).toHaveTextContent('—'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('coordinates DataPoint', () => { | ||
| it('renders the "Coordinates" label', () => { | ||
| renderMap(makeFacility()); | ||
|
|
||
| const coordRow = screen.getByTestId( | ||
| 'production-location-coordinates-row', | ||
| ); | ||
| expect(coordRow).toHaveTextContent('Coordinates'); | ||
| }); | ||
|
|
||
| it('displays coordinates formatted as "lat, lng"', () => { | ||
| renderMap(makeFacility()); | ||
|
|
||
| const coordRow = screen.getByTestId( | ||
| 'production-location-coordinates-row', | ||
| ); | ||
| expect(coordRow).toHaveTextContent(EXPECTED_COORD_DISPLAY); | ||
| }); | ||
|
|
||
| it('shows "—" when geometry.coordinates is absent', () => { | ||
| const facility = makeFacility({ geometry: null }); | ||
| renderMap(facility); | ||
|
|
||
| const coordRow = screen.getByTestId( | ||
| 'production-location-coordinates-row', | ||
| ); | ||
| expect(coordRow).toHaveTextContent('—'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('sources button and drawer', () => { | ||
| const facilityWithMultipleAddresses = makeFacility({ | ||
| properties: { | ||
| address: FACILITY_ADDRESS, | ||
| other_locations: [], | ||
| created_from: { | ||
| contributor: 'Test Org', | ||
| created_at: '2023-01-01T00:00:00Z', | ||
| }, | ||
| extended_fields: { | ||
| address: [ | ||
| { | ||
| value: FACILITY_ADDRESS, | ||
| contributor_name: 'Test Org', | ||
| contributor_id: 1, | ||
| created_at: '2023-01-01T00:00:00Z', | ||
| updated_at: '2023-01-01T00:00:00Z', | ||
| is_from_claim: false, | ||
| }, | ||
| { | ||
| value: '456 Second Ave', | ||
| contributor_name: 'Second Org', | ||
| contributor_id: 2, | ||
| created_at: '2023-03-01T00:00:00Z', | ||
| updated_at: '2023-03-01T00:00:00Z', | ||
| is_from_claim: false, | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| it('shows the sources button when there are address contributions', () => { | ||
| renderMap(facilityWithMultipleAddresses); | ||
|
|
||
| expect( | ||
| screen.getByTestId('data-point-sources-button'), | ||
| ).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('does not show the sources button when there is only one address entry', () => { | ||
| renderMap(makeFacility()); | ||
|
|
||
| expect( | ||
| screen.queryByTestId('data-point-sources-button'), | ||
| ).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('opens the ContributionsDrawer when the sources button is clicked', () => { | ||
| renderMap(facilityWithMultipleAddresses); | ||
|
|
||
| expect( | ||
| screen.queryByTestId('contributions-drawer'), | ||
| ).not.toBeInTheDocument(); | ||
|
|
||
| fireEvent.click(screen.getByTestId('data-point-sources-button')); | ||
|
|
||
| expect( | ||
| screen.getByTestId('contributions-drawer'), | ||
| ).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.