• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

geosolutions-it / MapStore2 / 14217089396

02 Apr 2025 10:11AM UTC coverage: 92.673% (+15.7%) from 76.984%
14217089396

push

github

web-flow
Fix #10819 Manager menu is merged into Login/user menu and Manager menu is now deprecated  (#10963)

245 of 385 branches covered (63.64%)

66 of 77 new or added lines in 3 files covered. (85.71%)

18 existing lines in 5 files now uncovered.

2011 of 2170 relevant lines covered (92.67%)

825.05 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.65
/web/client/components/security/UserMenu.jsx
1
import PropTypes from 'prop-types';
2

3
/**
4
 * Copyright 2016, GeoSolutions Sas.
5
 * All rights reserved.
6
 *
7
 * This source code is licensed under the BSD-style license found in the
8
 * LICENSE file in the root directory of this source tree.
9
 */
10

11
import React, {useState} from 'react';
12
import { DropdownButton, MenuItem, Glyphicon } from 'react-bootstrap';
13
import Message from '../I18N/Message';
14
import tooltip from "../misc/enhancers/tooltip";
15
import ConfirmModal from '../misc/ResizableModal';
16

17
const TDropdownButton = tooltip(DropdownButton);
1✔
18
function UserMenuItem({
19
    href,
20
    glyph,
21
    msgId,
22
    text,
23
    onClick
24
}) {
25
    return (<>
35✔
26
        <MenuItem {...(href ? { href } : {})} onClick={onClick}>
35✔
27
            <Glyphicon glyph={glyph} />{  msgId ? <Message msgId={msgId} /> : text}
35!
28
        </MenuItem>
29
    </>
30
    );
31
}
32

33

34
UserMenuItem.propTypes = {
1✔
35
    href: PropTypes.string,
36
    onClick: PropTypes.func,
37
    glyph: PropTypes.string,
38
    msgId: PropTypes.string,
39
    text: PropTypes.string,
40
    children: PropTypes.node
41
};
42

43
const UserMenu = (props) => {
1✔
44
    const [isOpen, setIsOpen] = useState(false);
17✔
45
    const {
46
        menuItems,
47
        bsStyle,
48
        tooltipPosition,
49
        className,
50
        id,
51
        title,
52
        hidden,
53
        displayUnsavedDialog,
54
        onCloseUnsavedDialog,
55
        onLogoutConfirm,
56
        ...other
57
    } = props;
17✔
58

59
    if (hidden) return null;
17!
60

61
    const handleItemClick = (onClick) => {
17✔
62
        setIsOpen(false);
1✔
63
        if (onClick) {
1!
64
            onClick();
1✔
65
        }
66
    };
67

68
    return (
17✔
69
        <>
70
            <TDropdownButton
71
                id={id}
72
                noCaret
73
                pullRight
74
                bsStyle={bsStyle}
75
                title={<Glyphicon glyph="user"/>}
76
                tooltipId="user.userMenu"
77
                tooltipPosition={tooltipPosition}
78
                className={className}
79
                open={isOpen}
NEW
80
                onToggle={(open) => setIsOpen(open)}
×
81
            >
82
                {title ? <MenuItem header>{title}</MenuItem> : null}
17✔
83
                {menuItems.map((entry, key) => {
84
                    if (entry.type === 'divider') {
55✔
85
                        return <MenuItem key={key} divider />;
13✔
86
                    }
87
                    const href = entry.path ? `#${entry.path}` : null;
42✔
88
                    if (entry.Component) {
42✔
89
                        return (
41✔
90
                            <entry.Component
91
                                key={entry.name || key}
41!
92
                                itemComponent={(properties) => (
93
                                    <UserMenuItem
34✔
94
                                        {...properties}
95
                                        onClick={() => handleItemClick(properties.onClick)}
1✔
96
                                    />
97
                                )}
98
                                {...other}
99
                            />
100
                        );
101
                    }
102
                    return (
1✔
103
                        <UserMenuItem
104
                            key={entry.name || key}
1!
105
                            href={href}
106
                            glyph={entry.glyph}
107
                            msgId={entry.msgId}
108
                            text={entry.name}
109
                        />
110
                    );
111
                })}
112
            </TDropdownButton>
113
            <ConfirmModal
114
                show={displayUnsavedDialog || false}
31✔
115
                onClose={onCloseUnsavedDialog}
116
                title={<Message msgId="resources.maps.unsavedMapConfirmTitle" />}
117
                buttons={[{
118
                    bsStyle: "primary",
119
                    text: <Message msgId="resources.maps.unsavedMapConfirmButtonText" />,
120
                    onClick: onLogoutConfirm
121
                }, {
122
                    text: <Message msgId="resources.maps.unsavedMapCancelButtonText" />,
123
                    onClick: onCloseUnsavedDialog
124
                }]}
125
                fitContent
126
            >
127
                <div className="ms-detail-body">
128
                    <Message msgId="resources.maps.unsavedMapConfirmMessage" />
129
                </div>
130
            </ConfirmModal>
131
        </>
132

133
    );
134
};
135

136
UserMenu.propTypes = {
1✔
137
    menuItems: PropTypes.array,
138
    bsStyle: PropTypes.string,
139
    tooltipPosition: PropTypes.string,
140
    className: PropTypes.string,
141
    id: PropTypes.string,
142
    title: PropTypes.node,
143
    hidden: PropTypes.bool,
144
    displayUnsavedDialog: PropTypes.bool,
145
    onCloseUnsavedDialog: PropTypes.func,
146
    onLogoutConfirm: PropTypes.func
147
};
148

149
UserMenu.defaultProps = {
1✔
150
    menuItems: [],
151
    bsStyle: "primary",
152
    tooltipPosition: "bottom",
153
    className: "user-menu",
154
    id: "user-menu",
155
    title: null,
156
    hidden: false,
157
    displayUnsavedDialog: false,
158
    onCloseUnsavedDialog: () => {},
159
    onLogoutConfirm: ()=>{}
160
};
161

162
export default UserMenu;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc