-
Notifications
You must be signed in to change notification settings - Fork 453
Expand file tree
/
Copy pathDrawerMenu.jsx
More file actions
191 lines (174 loc) · 6.5 KB
/
Copy pathDrawerMenu.jsx
File metadata and controls
191 lines (174 loc) · 6.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
* Copyright 2016, 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 './drawer/drawer.css';
import { partialRight } from 'lodash';
import PropTypes from 'prop-types';
import React from 'react';
import { Glyphicon, Panel } from 'react-bootstrap';
import { connect } from 'react-redux';
import { createSelector } from 'reselect';
import { setControlProperty, toggleControl } from '../actions/controls';
import { changeMapStyle } from '../actions/map';
import tooltip from '../components/misc/enhancers/tooltip';
import { mapLayoutValuesSelector } from '../selectors/maplayout';
import MenuComp from './drawer/Menu';
import Section from './drawer/Section';
import Message from './locale/Message';
import ButtonB from '../components/misc/Button';
const Button = tooltip(ButtonB);
const menuSelector = createSelector([
state => state.controls.drawer && state.controls.drawer.enabled,
state => state.controls.drawer && state.controls.drawer.menu || "1",
state => state.controls.queryPanel && state.controls.queryPanel.enabled && state.controls.drawer && state.controls.drawer.width || state.controls.drawer && state.controls.drawer.resizedWidth || undefined,
state => mapLayoutValuesSelector(state, {height: true})
], (show, activeKey, dynamicWidth, layout) => ({
show,
activeKey,
dynamicWidth,
layout
}));
const Menu = connect(menuSelector, {
onToggle: toggleControl.bind(null, 'drawer', null),
onResize: setControlProperty.bind(null, 'drawer', 'resizedWidth'),
onChoose: partialRight(setControlProperty.bind(null, 'drawer', 'menu'), true),
changeMapStyle: changeMapStyle
})(MenuComp);
const DrawerButton = connect(state => ({
disabled: state.controls && state.controls.drawer && state.controls.drawer.disabled
}), {
toggleMenu: toggleControl.bind(null, 'drawer', null)
})(({
id = '',
menuButtonStyle = {},
buttonStyle = 'primary',
buttonClassName = 'square-button ms-drawer-menu-button',
toggleMenu = () => {},
disabled = false,
glyph = '1-layer',
tooltipId = 'toc.drawerButton',
tooltipPosition = 'bottom'
}) =>
<Button
id={id}
cy-data="drawer-menu-button"
style={menuButtonStyle}
bsStyle={buttonStyle}
key="menu-button"
className={buttonClassName}
onClick={toggleMenu}
disabled={disabled}
tooltipId={tooltipId}
tooltipPosition={tooltipPosition}>
<Glyphicon glyph={glyph}/>
</Button>
);
/**
* DrawerMenu plugin. It is a container for other plugins.
* It shows a collapsible panel on the left with some plugins rendered inside it (typically the {@link #plugins.TOC|TOC})
* and a button on the top-left corner to open this panel.
* @prop {string} cfg.glyph glyph icon to use for the button
* @prop {object} cfg.menuButtonStyle Css inline style for the button. Display property will be overridden by the hideButton/forceDrawer options.
* @prop {string} cfg.buttonClassName class for the toggle button
* @prop {object} cfg.menuOptions options for the drawer menu
* @prop {boolean} cfg.menuOptions.docked
* @prop {number} cfg.menuOptions.width
* @prop {boolean} cfg.menuOptions.resizable enables horizontal resizing
* @memberof plugins
* @class
* @example
* {
* "name": "DrawerMenu",
* "cfg": {
* "hideButton": true
* }
* }
*/
class DrawerMenu extends React.Component {
static propTypes = {
items: PropTypes.array,
active: PropTypes.string,
toggleMenu: PropTypes.func,
id: PropTypes.string,
glyph: PropTypes.string,
buttonStyle: PropTypes.string,
menuOptions: PropTypes.object,
singleSection: PropTypes.bool,
buttonClassName: PropTypes.string,
menuButtonStyle: PropTypes.object,
disabled: PropTypes.bool
};
static contextTypes = {
messages: PropTypes.object,
router: PropTypes.object
};
static defaultProps = {
id: "mapstore-drawermenu",
items: [],
toggleMenu: () => {},
glyph: "1-layer",
buttonStyle: "primary",
menuOptions: {},
singleSection: true,
buttonClassName: "square-button ms-drawer-menu-button",
disabled: false
};
getTools = () => {
const unsorted = this.props.items
.map((item, index) => Object.assign({}, item, {position: item.position || index}));
return unsorted.sort((a, b) => a.position - b.position);
};
renderItems = () => {
return this.getTools().map((tool, index) => {
const Plugin = tool.panel || tool.plugin;
const plugin = (<Plugin
isPanel
{...tool.cfg}
items={tool.items || []}
groupStyle={{style: {
marginBottom: "0px",
cursor: "pointer"
}}}
/>);
const header = tool.title ? <div className={'drawer-menu-head drawer-menu-head-' + tool.name}><Message msgId={tool.title}/></div> : null;
return this.props.singleSection ?
<Panel icon={tool.icon} glyph={tool.glyph} buttonConfig={tool.buttonConfig} key={tool.name} eventKey={index + 1 + ""} header={header}>
{plugin}
</Panel>
: <Section key={tool.name} renderInModal={tool.renderInModal || false} eventKey={index + 1 + ""} header={header}>
{plugin}
</Section>;
});
};
render() {
return this.getTools().length > 0 ? (
<div id={this.props.id}>
<DrawerButton {...this.props} id="drawer-menu-button"/>
<Menu single={this.props.singleSection} {...this.props.menuOptions} title={<Message msgId="menu" />} alignment="left">
{this.renderItems()}
</Menu>
</div>
) : null;
}
}
const DrawerMenuPlugin = connect((state) => ({
active: state.controls && state.controls.drawer && state.controls.drawer.active,
disabled: state.controls && state.controls.drawer && state.controls.drawer.disabled
}), {
toggleMenu: toggleControl.bind(null, 'drawer', null)
})(DrawerMenu);
export default {
DrawerMenuPlugin: Object.assign(DrawerMenuPlugin, {
disablePluginIf: "{state('featuregridmode') === 'EDIT'}",
FloatingLegend: {
priority: 1,
name: 'drawer-menu',
button: DrawerButton
}
}),
reducers: {}
};