-
Notifications
You must be signed in to change notification settings - Fork 391
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
#10545: Option to disable identify popup in case of no results #10557
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,11 +31,13 @@ export default class PopupSupport extends React.Component { | |
static propTypes = { | ||
map: PropTypes.object, | ||
popups: PropTypes.arrayOf(PropTypes.object), | ||
identifyPopupHidden: PropTypes.bool, | ||
onPopupClose: PropTypes.func | ||
} | ||
|
||
static defaultProps = { | ||
popups: [], | ||
identifyPopupHidden: false, | ||
onPopupClose: () => {} | ||
} | ||
UNSAFE_componentWillMount() { | ||
|
@@ -50,8 +52,8 @@ export default class PopupSupport extends React.Component { | |
this.props.map.on('resize', this.updatePopup); | ||
} | ||
} | ||
shouldComponentUpdate({popups}) { | ||
return popups !== this.props.popups; | ||
shouldComponentUpdate({popups, identifyPopupHidden}) { | ||
return popups !== this.props.popups || identifyPopupHidden !== this.props.identifyPopupHidden; | ||
} | ||
componentWillUnmount() { | ||
// Clean old popups without throwing event | ||
|
@@ -66,7 +68,15 @@ export default class PopupSupport extends React.Component { | |
} | ||
} | ||
renderPopups() { | ||
return this.preparePopups() | ||
const {identifyPopupHidden} = this.props; | ||
if (identifyPopupHidden) { | ||
(this._popups || []).forEach(({popup}) => { | ||
popup.off('remove', this.popupClose); | ||
popup && this.props.map.removeLayer(popup); | ||
}); | ||
return []; | ||
} | ||
return this.preparePopups() | ||
Comment on lines
+71
to
+79
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i have some doubts about this implementation too. |
||
.filter(({component}) => !!component) | ||
.map(({popup, props = {}, component, id}) => { | ||
const context = popup.getContent(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,11 +34,13 @@ export default class PopupSupport extends React.Component { | |
static propTypes = { | ||
map: PropTypes.object, | ||
popups: PropTypes.arrayOf(PropTypes.object), | ||
identifyPopupHidden: PropTypes.bool, | ||
onPopupClose: PropTypes.func | ||
} | ||
|
||
static defaultProps = { | ||
popups: [], | ||
identifyPopupHidden: false, | ||
onPopupClose: () => {} | ||
} | ||
UNSAFE_componentWillMount() { | ||
|
@@ -47,8 +49,8 @@ export default class PopupSupport extends React.Component { | |
this.props.map.getOverlayContainerStopEvent().addEventListener('pointermove', this.stopPropagationOnPointerMove); | ||
} | ||
} | ||
shouldComponentUpdate({popups}) { | ||
return popups !== this.props.popups; | ||
shouldComponentUpdate({popups, identifyPopupHidden}) { | ||
return popups !== this.props.popups || identifyPopupHidden !== this.props.identifyPopupHidden; | ||
} | ||
componentWillUnmount() { | ||
if (this.props.map) { | ||
|
@@ -59,6 +61,14 @@ export default class PopupSupport extends React.Component { | |
this.props.onPopupClose(id); | ||
} | ||
renderPopups = () => { | ||
const {identifyPopupHidden, map} = this.props; | ||
if (identifyPopupHidden) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe the flag hidePopupIfNoResults could have been used to filter out elements? |
||
(this._popups || []).forEach(({popup, observer}) => { | ||
!!observer && observer.disconnect(); | ||
!!popup && map.removeOverlay(popup); | ||
}); | ||
return []; | ||
} | ||
return this.preparePopups().map(({ popup, id, component, content, props, containerStyle}) => { | ||
const context = popup.getElement(); | ||
const PopupContent = isString(component) && popupsComponents[component] || component; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,8 @@ import { projectionDefsSelector, isMouseMoveActiveSelector } from '../../selecto | |
import { | ||
snappingLayerSelector | ||
} from "../../selectors/draw"; | ||
import { getDefaultInfoFormatValue, getValidator } from '../../utils/MapInfoUtils'; | ||
import { mapInfoRequestsSelector, responsesSelector } from '../../selectors/mapInfo'; | ||
|
||
const Empty = () => { return <span/>; }; | ||
|
||
|
@@ -105,9 +107,26 @@ const pluginsCreator = (mapType, actions) => { | |
const PopupSupport = connect( | ||
createSelector( | ||
(state) => state.mapPopups && state.mapPopups.popups || EMPTY_POPUPS, | ||
(popups) => ({ | ||
popups | ||
})), { | ||
(state) => state.mapPopups && state.mapPopups.hideEmptyPopupOption || false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a dedicated selector must be created when you add a new one |
||
isMouseMoveActiveSelector, | ||
mapInfoRequestsSelector, | ||
responsesSelector, | ||
(popups, hideEmptyPopupOption, isMouseMoveActive, mapInfoRequests, mapInfoResponses) => { | ||
// create a flag for hide the identify popup in case no results in hover mode | ||
let identifyPopupHidden = false; | ||
if (isMouseMoveActive && mapInfoRequests?.length && mapInfoResponses?.length && hideEmptyPopupOption) { | ||
const format = getDefaultInfoFormatValue(); | ||
const invalidResponses = getValidator(format).getNoValidResponses(mapInfoResponses); | ||
const emptyResponses = mapInfoRequests?.length === invalidResponses?.length; | ||
const missingResponses = (mapInfoRequests || []).length - (mapInfoResponses || []).length; | ||
identifyPopupHidden = missingResponses === 0 && emptyResponses && isMouseMoveActive && hideEmptyPopupOption; | ||
} | ||
return { | ||
popups, | ||
identifyPopupHidden | ||
Comment on lines
+110
to
+126
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have also some doubts here tbh, i will deeply check this |
||
}; | ||
} | ||
), { | ||
onPopupClose: removePopup | ||
} | ||
)(components.PopupSupport || Empty); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't you just use the hidePopupIfNoResults prop instead of calling enableHideEmptyPopupOption and updating state?