Skip to content
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

EDSC-4346: Make the entire map to be visible when I select data #1855

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3c46798
EDSC-4346 Creating MapLayoutContainer
dpesall Feb 3, 2025
0f02498
EDSC-4346 Refactoring
dpesall Feb 3, 2025
09ac0cd
EDSC-4346 Fixing Projects endpoint map resizing
dpesall Feb 3, 2025
faf53c8
EDSC-4346 Fixing map tile rendering
dpesall Feb 4, 2025
639a3aa
EDSC-4346 Mering main into current
dpesall Feb 6, 2025
753965a
EDSC-4346 Test updates
dpesall Feb 7, 2025
50d94f5
EDSC-4346 Removing unused vars
dpesall Feb 7, 2025
99ade41
EDSC-4346 Adding test coverage
dpesall Feb 10, 2025
7f26e84
EDSC-4346 Test coverage Panels.jsx
dpesall Feb 10, 2025
5e30282
EDSC-4346 Creating test file
dpesall Feb 10, 2025
b56d286
EDSC-4346 eslint fix
dpesall Feb 10, 2025
f53f052
Merge branch 'main' into EDSC-4346
dpesall Feb 11, 2025
8d7f9a7
EDSC-4346 Updating tour.spec.js
dpesall Feb 12, 2025
c35051f
EDSC-4346 Updating search and map interactions playwright tests
dpesall Feb 12, 2025
373e16c
EDSC-4346 Updating map_granules.spec
dpesall Feb 12, 2025
43dec59
EDSC-4346 updating map_shapefile.spec.js
dpesall Feb 12, 2025
254c157
EDSC-4346 Updating map_spatial.spec.js
dpesall Feb 12, 2025
5e64604
EDSC-4346 Updating map_spatial.spec.js
dpesall Feb 12, 2025
eb891e2
EDSC-4346 Test updates
dpesall Feb 12, 2025
61cd282
EDSC-4346 Updating click position
dpesall Feb 12, 2025
c79cccc
EDSC-4346 Playwright fixes
dpesall Feb 12, 2025
7f53722
EDSC-4346 String selection
dpesall Feb 12, 2025
28aa0a7
EDSC-4346 Playwright test update
dpesall Feb 13, 2025
c9c77f2
Merge branch 'main' into EDSC-4346
dpesall Feb 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions static/src/js/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ const Admin = lazy(() => import('./routes/Admin/Admin'))
const ContactInfo = lazy(() => import('./routes/ContactInfo/ContactInfo'))
const Downloads = lazy(() => import('./routes/Downloads/Downloads'))
const EarthdataDownloadRedirect = lazy(() => import('./routes/EarthdataDownloadRedirect/EarthdataDownloadRedirect'))
const EdscMapContainer = lazy(() => import('./containers/MapContainer/MapContainer'))
const Preferences = lazy(() => import('./routes/Preferences/Preferences'))
const Project = lazy(() => import('./routes/Project/Project'))
const Subscriptions = lazy(() => import('./routes/Subscriptions/Subscriptions'))
Expand Down Expand Up @@ -218,9 +217,6 @@ class App extends Component {
<>
<SearchTour />
<Search />
<Suspense fallback={<Spinner type="dots" className="root__spinner spinner spinner--dots spinner--white spinner--small" />}>
<EdscMapContainer />
</Suspense>
</>
)
}
Expand Down
15 changes: 1 addition & 14 deletions static/src/js/__tests__/App.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import React from 'react'
import nock from 'nock'
import { Helmet } from 'react-helmet'

import {
render,
waitFor,
screen
} from '@testing-library/react'
import { render, waitFor } from '@testing-library/react'

import * as AppConfig from '../../../../sharedUtils/config'
import App from '../App'
Expand Down Expand Up @@ -285,13 +281,4 @@ describe('App component', () => {
expect(canonical).toBeDefined()
expect(canonical.href).toBe('https://search.earthdata.nasa.gov/search')
})

// https://stackoverflow.com/questions/66667827/react-testing-library-to-cover-the-lazy-load/66690463
test('renders loaded lazy components', async () => {
setup()

await waitFor(() => {
expect(screen.getByTestId('mocked-map-container')).toBeInTheDocument()
})
})
})
36 changes: 36 additions & 0 deletions static/src/js/components/Panels/Panels.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,22 @@ export class Panels extends PureComponent {

event.preventDefault()
event.stopPropagation()

// Get the main panel's (project-collections) width
const mainPanelEl = document.querySelector('.project-collections')
const mainPanelWidth = mainPanelEl ? mainPanelEl.clientWidth : 0

// Determine the collapsible panel width:
// When open, use this.width; when collapsed, assume a width of 0
const collapsiblePanelWidth = !show ? this.width : 0

// Calculate the total offset to be applied to the map
const totalOffset = mainPanelWidth + collapsiblePanelWidth

this.updateMapOffset(totalOffset)

// Update the CSS variable so the map shifts accordingly
document.documentElement.style.setProperty('--map-offset', `${totalOffset}px`)
}

onMouseDown(event) {
Expand Down Expand Up @@ -428,6 +444,14 @@ export class Panels extends PureComponent {
}
}

updateMapOffset(totalOffset) {
// First update the CSS variable
document.documentElement.style.setProperty('--map-offset', `${totalOffset}px`)

// Then dispatch the event
window.dispatchEvent(new CustomEvent('mapOffsetChanged'))
}

disableHandleClickEvent() {
this.handleClickIsValid = false
}
Expand All @@ -446,6 +470,18 @@ export class Panels extends PureComponent {
updatePanelWidth(width) {
this.width = width
this.container.style.width = `${width}px`

// Get the width of the main panel (project-collections)
const mainPanelEl = document.querySelector('.project-collections')
const mainPanelWidth = mainPanelEl ? mainPanelEl.clientWidth : 0

// Calculate the total offset: main panel + collapsible panel
const totalOffset = mainPanelWidth + width

// Update the CSS variable used by the map
document.documentElement.style.setProperty('--map-offset', `${totalOffset}px`)

this.updateMapOffset(totalOffset)
this.updateResponsiveClassNames()
}

Expand Down
178 changes: 177 additions & 1 deletion static/src/js/components/Panels/__tests__/Panels.test.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import React from 'react'
import { render, screen } from '@testing-library/react'
import {
render,
screen,
fireEvent
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try user interaction instead of fireEvent

} from '@testing-library/react'

import Panels from '../Panels'
import { PanelSection } from '../PanelSection'
Expand Down Expand Up @@ -468,4 +472,176 @@ describe('Panels component', () => {
expect(screen.getByTestId('panels-section')).not.toHaveClass('panels--is-open')
})
})

describe('Panels handle click map offset update', () => {
let mainPanelEl

beforeEach(() => {
mainPanelEl = document.createElement('div')
mainPanelEl.className = 'project-collections'
Object.defineProperty(mainPanelEl, 'clientWidth', {
configurable: true,
value: 500
})

document.body.appendChild(mainPanelEl)
})

Comment on lines +477 to +489
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update this to test the way a user would test

afterEach(() => {
document.body.removeChild(mainPanelEl)
})

test('clicking handle when panel is open sets map offset correctly (panel closes)', () => {
setup(render, { show: true })

const dispatchSpy = jest.spyOn(window, 'dispatchEvent')

const handle = screen.getByTestId('panels__handle')
fireEvent.click(handle)

expect(document.documentElement.style.getPropertyValue('--map-offset')).toBe('500px')
expect(dispatchSpy).toHaveBeenCalledWith(expect.any(CustomEvent))

dispatchSpy.mockRestore()
})

test('clicking handle when panel is closed sets map offset correctly (panel opens)', () => {
setup(render, { show: false })

const dispatchSpy = jest.spyOn(window, 'dispatchEvent')
const handle = screen.getByTestId('panels__handle')
fireEvent.click(handle)

expect(document.documentElement.style.getPropertyValue('--map-offset')).toBe('1100px')
expect(dispatchSpy).toHaveBeenCalledWith(expect.any(CustomEvent))

dispatchSpy.mockRestore()
})
})

describe('updatePanelWidth', () => {
let mainPanelEl
let panelsRef

beforeEach(() => {
// Create and setup the main panel element
mainPanelEl = document.createElement('div')
mainPanelEl.className = 'project-collections'
Object.defineProperty(mainPanelEl, 'clientWidth', {
configurable: true,
value: 500
})

document.body.appendChild(mainPanelEl)
})

afterEach(() => {
mainPanelEl?.remove()
})

test('correctly updates panel width and map offset', () => {
// Create a ref to capture the Panels component instance
let panelsInstance
const TestWrapper = () => {
panelsRef = (ref) => {
panelsInstance = ref
}

return (
<Panels
ref={panelsRef}
show
activePanel="0.0.0"
draggable
>
<PanelSection>
<PanelGroup>
<PanelItem>Content</PanelItem>
</PanelGroup>
</PanelSection>
</Panels>
)
}

render(<TestWrapper />)

// Spy on the updateMapOffset method
const dispatchSpy = jest.spyOn(window, 'dispatchEvent')

// Call updatePanelWidth with a new width
const newWidth = 800
panelsInstance.updatePanelWidth(newWidth)

// Check if the panel width was updated correctly
expect(screen.getByTestId('panels-section')).toHaveStyle(`width: ${newWidth}px`)

// Check if the map offset was calculated and set correctly
const expectedOffset = 500 + newWidth // MainPanelWidth + newWidth
expect(document.documentElement.style.getPropertyValue('--map-offset'))
.toBe(`${expectedOffset}px`)

// Verify that the custom event was dispatched
expect(dispatchSpy).toHaveBeenCalledWith(
expect.any(CustomEvent)
)

// Verify the event details
const dispatchedEvent = dispatchSpy.mock.calls[0][0]
expect(dispatchedEvent.type).toBe('mapOffsetChanged')

dispatchSpy.mockRestore()
})

test('handles missing main panel element', () => {
// Create a ref to capture the Panels component instance
let panelsInstance
const TestWrapper = () => {
panelsRef = (ref) => {
panelsInstance = ref
}

return (
<Panels
ref={panelsRef}
show
activePanel="0.0.0"
draggable
>
<PanelSection>
<PanelGroup>
<PanelItem>Content</PanelItem>
</PanelGroup>
</PanelSection>
</Panels>
)
}

render(<TestWrapper />)

// Remove the main panel element to test the fallback
mainPanelEl?.remove()

// Spy on the updateMapOffset method
const dispatchSpy = jest.spyOn(window, 'dispatchEvent')

// Call updatePanelWidth with a new width
const newWidth = 800
panelsInstance.updatePanelWidth(newWidth)

// Check if the panel width was updated correctly
expect(screen.getByTestId('panels-section')).toHaveStyle(`width: ${newWidth}px`)

// Check if the map offset was calculated correctly with 0 for mainPanelWidth
const expectedOffset = newWidth // 0 + newWidth
expect(document.documentElement.style.getPropertyValue('--map-offset'))
.toBe(`${expectedOffset}px`)

// Verify that the custom event was still dispatched
expect(dispatchSpy).toHaveBeenCalledWith(
expect.any(CustomEvent)
)

dispatchSpy.mockRestore()
})
})
})
10 changes: 6 additions & 4 deletions static/src/js/components/Sidebar/Sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ import SimpleBar from 'simplebar-react'

import './Sidebar.scss'

const Sidebar = ({
const Sidebar = React.forwardRef(({
children,
panels,
visible,
headerChildren
}) => {
}, ref) => {
const className = classNames({
sidebar: true,
'sidebar--hidden': !visible
})

return (
<section className={className}>
<section className={className} ref={ref}>
<div className="sidebar__inner">
{ headerChildren }
<SimpleBar
Expand All @@ -34,7 +34,7 @@ const Sidebar = ({
{panels && panels}
</section>
)
}
})

Sidebar.defaultProps = {
panels: null,
Expand All @@ -48,4 +48,6 @@ Sidebar.propTypes = {
headerChildren: PropTypes.node
}

Sidebar.displayName = 'Sidebar'

export default Sidebar
6 changes: 3 additions & 3 deletions static/src/js/containers/MapContainer/MapContainer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

.map {
position: absolute;
left: 0;
left: var(--map-offset, 0);
bottom: 0;
top: 0;
right: 0;
width: 100%;
width: calc(100% - var(--map-offset, 0));
align-items: center;
justify-content: center;
flex-basis: auto;
Expand All @@ -19,4 +19,4 @@
.is-panels-dragging & {
pointer-events: none;
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline

14 changes: 13 additions & 1 deletion static/src/js/containers/MapContainer/MapEvents.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useLayoutEffect } from 'react'
import { useLayoutEffect, useEffect } from 'react'
import PropTypes from 'prop-types'
import { useMap, useMapEvents } from 'react-leaflet'

Expand All @@ -25,6 +25,18 @@ const MapEvents = (props) => {
}
})

useEffect(() => {
const handleMapOffsetChange = () => {
map.invalidateSize()
}

window.addEventListener('mapOffsetChanged', handleMapOffsetChange)

return () => {
window.removeEventListener('mapOffsetChanged', handleMapOffsetChange)
}
}, [map])

const handleOverlayChange = (event) => {
Comment on lines +28 to +39
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comments for why this is needed

const enabled = event.type === 'overlayadd'
switch (event.name) {
Expand Down
Loading
Loading