-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Fix #9638 ui issue with context when adding all plugins * Fixed the menu to be visible. * Fix behaviour in every case * Simplified logic behind menu --------- Co-authored-by: Lorenzo Natali <[email protected]>
- Loading branch information
1 parent
61bc556
commit 0651726
Showing
5 changed files
with
194 additions
and
34 deletions.
There are no files selected for viewing
This file contains 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 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 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
137 changes: 137 additions & 0 deletions
137
web/client/plugins/longitudinalProfile/MenuForBurger.jsx
This file contains 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,137 @@ | ||
/* | ||
* Copyright 2023, GeoSolutions Sas. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
import React, { useState, useEffect, useCallback, useRef } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import Overlay from '../../components/misc/Overlay'; | ||
|
||
import {Glyphicon, MenuItem, Popover} from 'react-bootstrap'; | ||
import {connect} from "react-redux"; | ||
|
||
import Message from '../../components/I18N/Message'; | ||
import { setControlProperty } from "../../actions/controls"; | ||
import { | ||
toggleMode | ||
} from "../../actions/longitudinalProfile"; | ||
import { | ||
dataSourceModeSelector, | ||
isActiveMenuSelector, | ||
isInitializedSelector, | ||
isParametersOpenSelector | ||
} from "../../selectors/longitudinalProfile"; | ||
import { isCesium } from '../../selectors/maptype'; | ||
|
||
/** | ||
* A DropDown menu for longitudinal profile | ||
*/ | ||
const UserMenu = ({ | ||
dataSourceMode, | ||
initialized, | ||
isParametersOpen, | ||
menuIsActive, | ||
showDrawOption, | ||
onActivateTool, | ||
onToggleParameters, | ||
onToggleSourceMode | ||
}) => { | ||
|
||
const [open, setMenuOpen ] = useState(false); | ||
useEffect(() => { | ||
const burgerButton = document.querySelector("#mapstore-burger-menu-container"); | ||
burgerButton?.addEventListener("click", () => { | ||
setMenuOpen(false); | ||
}); | ||
return () => { | ||
setMenuOpen(false); | ||
}; | ||
}, []); | ||
const onToggleTool = useCallback((toolName) => () => { | ||
onActivateTool(); | ||
setMenuOpen(false); | ||
onToggleSourceMode(toolName); | ||
}, []); | ||
const ref = useRef(); | ||
const body = (<> | ||
{showDrawOption ? <MenuItem active={dataSourceMode === 'draw'} key="draw" onClick={onToggleTool('draw')}> | ||
<Glyphicon glyph="pencil"/><Message msgId="longitudinalProfile.draw"/> | ||
</MenuItem> : null} | ||
<MenuItem active={dataSourceMode === 'import'} key="import" onClick={onToggleTool('import')}> | ||
<Glyphicon glyph="upload"/> <Message msgId="longitudinalProfile.import"/> | ||
</MenuItem> | ||
<MenuItem active={dataSourceMode === 'select'} key="select" onClick={onToggleTool('select')}> | ||
<Glyphicon glyph="1-layer"/> <Message msgId="longitudinalProfile.select"/> | ||
</MenuItem> | ||
<MenuItem key="divider" divider/> | ||
<MenuItem active={isParametersOpen} key="parameters" onClick={onToggleParameters}> | ||
<Glyphicon glyph="cog"/> <Message msgId="longitudinalProfile.parameters"/> | ||
</MenuItem> | ||
</>); | ||
|
||
// inside extra tools | ||
const Menu = (<> | ||
{open && <Overlay | ||
show={open} | ||
target={ref.current} | ||
placement="left" | ||
container={this} | ||
containerPadding={20} | ||
> | ||
<Popover id="longitudinal-profile-burger-menu" placement="left" style={{margin: 0, padding: 0}}> | ||
<div className="dropdown-menu open" style={{display: "block", position: "relative"}}> | ||
{body} | ||
</div> | ||
</Popover> | ||
</Overlay> | ||
} | ||
<MenuItem ref={ref} active={menuIsActive || open} key="menu" onClick={() => { setMenuOpen(!open);}}> | ||
<Glyphicon glyph="1-line"/> | ||
<Message msgId="longitudinalProfile.title"/> | ||
</MenuItem> | ||
</>); | ||
|
||
return initialized ? Menu : false; | ||
}; | ||
|
||
UserMenu.propTypes = { | ||
className: PropTypes.string, | ||
dataSourceMode: PropTypes.string, | ||
initialized: PropTypes.bool, | ||
isParametersOpen: PropTypes.bool, | ||
menuIsActive: PropTypes.bool, | ||
menuItem: PropTypes.bool, | ||
nav: PropTypes.bool, | ||
showDrawOption: PropTypes.bool, | ||
tooltipPosition: PropTypes.string, | ||
onActivateTool: PropTypes.func, | ||
onToggleParameters: PropTypes.func, | ||
onToggleSourceMode: PropTypes.func | ||
}; | ||
|
||
UserMenu.defaultProps = { | ||
className: "square-button", | ||
menuIsActive: false, | ||
nav: false, | ||
showDrawOption: true, | ||
onActivateTool: () => {}, | ||
onToggleParameters: () => {}, | ||
onToggleSourceMode: () => {}, | ||
tooltipPosition: 'left' | ||
}; | ||
|
||
const MenuForBurger = connect((state) => ({ | ||
menuIsActive: isActiveMenuSelector(state), | ||
dataSourceMode: dataSourceModeSelector(state), | ||
isParametersOpen: isParametersOpenSelector(state), | ||
showDrawOption: !isCesium(state), | ||
initialized: isInitializedSelector(state) | ||
}), { | ||
onActivateTool: setControlProperty.bind(null, "longitudinalProfileTool", "enabled", true), | ||
onToggleSourceMode: toggleMode, | ||
onToggleParameters: setControlProperty.bind(null, "LongitudinalProfileToolParameters", "enabled", true, true) | ||
})(UserMenu); | ||
|
||
export default MenuForBurger; |
This file contains 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