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

fix: isPopupVisible logic for AzureMapHtmlMarker #154

Merged
merged 1 commit into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions __mocks__/azure-maps-control.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ module.exports = {
isOpen: jest.fn(() => true),
open: jest.fn(() => false),
togglePopup: jest.fn(),
setOptions: jest.fn(),
close: jest.fn()
}
}))
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-azure-maps",
"version": "0.4.6",
"version": "0.4.7",
"description": "React Wrapper for Azure Maps",
"keywords": [
"react",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { render } from '@testing-library/react'
import { Map, Popup } from 'azure-maps-control'
import React from 'react'
import { AzureMapsContext } from '../../../contexts/AzureMapContext'
import AzureMaphtmlMarker from './AzureMapHtmlMarker'
import AzureMapHtmlMarker from './AzureMapHtmlMarker'
import { IAzureMapHtmlMarker } from '../../../types'
import atlas from 'azure-maps-control'

Expand All @@ -23,7 +23,7 @@ const wrapWithAzureMapContext = (props: IAzureMapHtmlMarker) => {
mapRef
}}
>
<AzureMaphtmlMarker {...{ ...props }} />
<AzureMapHtmlMarker {...{ ...props }} />
</AzureMapsContext.Provider>
)
}
Expand Down Expand Up @@ -81,13 +81,13 @@ describe('AzureMaphtmlMarker tests', () => {
expect(markerRef.setOptions).toHaveBeenCalledWith({ htmlContent: '<div></div>' })
})

it('should close marker popup', () => {
it('should open marker popup', () => {
render(wrapWithAzureMapContext({ isPopupVisible: true, markerContent: <div /> }))
// Currently we only check if getOptions get called @TODO
expect(markerRef.getOptions).toHaveBeenCalled()
})

it('should open marker popup', () => {
it('should close marker popup', () => {
render(wrapWithAzureMapContext({ isPopupVisible: false, markerContent: <div /> }))
// Currently we only check if getOptions get called @TODO
expect(markerRef.getOptions).toHaveBeenCalled()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const AzureMapHtmlMarker = memo(
)
const { mapRef } = useContext<IAzureMapsContextProps>(AzureMapsContext)

useCheckRefMount<MapType, boolean>(mapRef, true, mref => {
useCheckRefMount<MapType, boolean>(mapRef, true, (mref) => {
mref.markers.add(markerRef)
events &&
events.forEach(({ eventName, callback }) => {
Expand All @@ -38,13 +38,14 @@ const AzureMapHtmlMarker = memo(

useEffect(() => {
if (markerRef && markerRef.getOptions().popup && mapRef) {
const isMarkerPopupOpen = markerRef.getOptions().popup?.isOpen()
if (isMarkerPopupOpen && isPopupVisible) {
markerRef.getOptions().popup?.close()
} else if (isMarkerPopupOpen !== undefined) {
markerRef.getOptions().popup?.open()
} else if ((isPopupVisible && isMarkerPopupOpen) || isPopupVisible) {
markerRef.togglePopup()
const popupRef = markerRef.getOptions().popup
if (isPopupVisible) {
popupRef?.setOptions({
position: markerRef.getOptions().position
})
popupRef?.open(mapRef)
} else {
popupRef?.close()
}
}
}, [isPopupVisible, options, mapRef])
Expand Down