Skip to content

Commit

Permalink
Fix geosolutions-it#9638 ui issue with context when adding all plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
MV88 committed Oct 20, 2023
1 parent 05754ef commit 324d3b9
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 38 deletions.
11 changes: 11 additions & 0 deletions web/client/plugins/GeoProcessing.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ const GeoProcessing = createPlugin(
action: toggleControl.bind(null, 'GeoProcessing', null),
priority: 10,
toggle: true
},
BurgerMenu: {
name: 'GeoProcessing',
position: 2100,
doNotHide: true,
tooltip: "GeoProcessing.tooltip.siderBarBtn",
text: <Message msgId="GeoProcessing.title" />,
icon: <Glyphicon glyph="globe-settings" />,
action: toggleControl.bind(null, 'GeoProcessing', null),
priority: 12,
toggle: true
}
},
reducers: {
Expand Down
15 changes: 11 additions & 4 deletions web/client/plugins/LongitudinalProfileTool.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { createSelector } from 'reselect';

import GlobalSpinner from '../components/misc/spinners/GlobalSpinner/GlobalSpinner';
import Main from './longitudinalProfile/Main';
import UserMenuConnected from './longitudinalProfile/Menu';
import MenuConnected from './longitudinalProfile/Menu';
import MenuForBurger from './longitudinalProfile/MenuForBurger';
import { setControlProperty } from "../actions/controls";
import {
addMarker,
Expand Down Expand Up @@ -97,10 +98,9 @@ import { createPlugin } from '../utils/PluginsUtils';
* "filterAllowedCRS": ["EPSG:4326", "EPSG:3857"],
* "additionalCRS": {
* "EPSG:3003": { "label": "EPSG:3003" }
* },
* }
* }
* }
* `
*/
const MainComponent = connect(
createSelector(
Expand Down Expand Up @@ -202,9 +202,16 @@ export default createPlugin(
name: 'LongitudinalProfileTool',
position: 2100,
doNotHide: true,
tool: UserMenuConnected,
tool: MenuConnected,
priority: 1
},
BurgerMenu: {
tool: MenuForBurger,
name: 'LongitudinalProfileTool',
position: 2100,
doNotHide: true,
priority: 2
},
Toolbar: {
name: "LongitudinalProfileTool-spinner",
alwaysVisible: true,
Expand Down
42 changes: 8 additions & 34 deletions web/client/plugins/longitudinalProfile/Menu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ const TDropdownButton = tooltip(DropdownButton);
/**
* A DropDown menu for longitudinal profile
*/
const UserMenu = ({
const Menu = ({
className,
dataSourceMode,
initialized,
menuItem,
isParametersOpen,
menuIsActive,
nav,
Expand Down Expand Up @@ -75,7 +74,7 @@ const UserMenu = ({
<Glyphicon glyph="cog"/> <Message msgId="longitudinalProfile.parameters"/>
</MenuItem>
</>);
const DropDownMenu = (<DropDown
return initialized ? (<DropDown
dropup={dropUp}
open={open}
onToggle={(val) => setMenuOpen(val)}
Expand All @@ -89,35 +88,10 @@ const UserMenu = ({
noCaret
>
{body}
</DropDown>);

let Menu;
if (menuItem) {
// inside extra tools
Menu = (<> {
open ? <>
<div className="open dropup btn-group btn-group-tray" style={{display: "inline"}}>
<ul role="menu" className="dropdown-menu dropdown-menu-right" aria-labelledby="longitudinal-tool">
{body}
</ul>
</div>
<MenuItem active={menuIsActive || open} key="menu" onClick={() => setMenuOpen(!open)}>
<Glyphicon glyph="1-line"/>
<Message msgId="longitudinalProfile.title"/>
</MenuItem></> :
<MenuItem active={menuIsActive || open} key="menu" onClick={() => setMenuOpen(!open)}>
<Glyphicon glyph="1-line"/>
<Message msgId="longitudinalProfile.title"/>
</MenuItem> }
</>);
} else {
Menu = DropDownMenu;
}

return initialized ? Menu : false;
</DropDown>) : false;
};

UserMenu.propTypes = {
Menu.propTypes = {
className: PropTypes.string,
dataSourceMode: PropTypes.string,
initialized: PropTypes.bool,
Expand All @@ -132,7 +106,7 @@ UserMenu.propTypes = {
onToggleSourceMode: PropTypes.func
};

UserMenu.defaultProps = {
Menu.defaultProps = {
className: "square-button",
menuIsActive: false,
nav: false,
Expand All @@ -143,7 +117,7 @@ UserMenu.defaultProps = {
tooltipPosition: 'left'
};

const UserMenuConnected = connect((state) => ({
const MenuConnected = connect((state) => ({
menuIsActive: isActiveMenuSelector(state),
dataSourceMode: dataSourceModeSelector(state),
isParametersOpen: isParametersOpenSelector(state),
Expand All @@ -153,6 +127,6 @@ const UserMenuConnected = connect((state) => ({
onActivateTool: setControlProperty.bind(null, "longitudinalProfileTool", "enabled", true),
onToggleSourceMode: toggleMode,
onToggleParameters: setControlProperty.bind(null, "LongitudinalProfileToolParameters", "enabled", true, true)
})(UserMenu);
})(Menu);

export default UserMenuConnected;
export default MenuConnected;
119 changes: 119 additions & 0 deletions web/client/plugins/longitudinalProfile/MenuForBurger.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* 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, useCallback } from 'react';
import PropTypes from 'prop-types';
import {Glyphicon, MenuItem} 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 onToggleTool = useCallback((toolName) => () => {
onActivateTool();
onToggleSourceMode(toolName);
}, []);
const [open, setMenuOpen ] = useState(false);
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 ? <>
<div className="open dropup btn-group btn-group-tray" style={{ position: "absolute", display: "inline"}}>
<ul role="menu" className="dropdown-menu dropdown-menu-right" aria-labelledby="longitudinal-tool">
{body}
</ul>
</div>
<MenuItem active={menuIsActive || open} key="menu" onClick={() => setMenuOpen(!open)}>
<Glyphicon glyph="1-line"/>
<Message msgId="longitudinalProfile.title"/>
</MenuItem></> :
<MenuItem 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;

0 comments on commit 324d3b9

Please sign in to comment.