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

geosolutions-it / MapStore2 / 13858667147

14 Mar 2025 02:23PM UTC coverage: 76.975% (+0.004%) from 76.971%
13858667147

Pull #10921

github

web-flow
Merge 857f245f9 into c7f7aa09a
Pull Request #10921: Fix #10899 About Plugin content

30969 of 48200 branches covered (64.25%)

38486 of 49998 relevant lines covered (76.98%)

35.82 hits per line

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

92.86
/web/client/plugins/AddGroup.jsx
1
/*
2
* Copyright 2019, GeoSolutions Sas.
3
* All rights reserved.
4
*
5
* This source code is licensed under the BSD-style license found in the
6
* LICENSE file in the root directory of this source tree.
7
*/
8

9
import React, { useState, useEffect } from 'react';
10
import PropTypes from 'prop-types';
11
import { connect } from 'react-redux';
12
import get from 'lodash/get';
13
import Portal from '../components/misc/Portal';
14
import ResizableModal from '../components/misc/ResizableModal';
15
import Message from '../components/I18N/Message';
16
import { FormControl, FormGroup } from 'react-bootstrap';
17
import { setControlProperties } from '../actions/controls';
18
import { addGroup } from '../actions/layers';
19
import { createPlugin } from '../utils/PluginsUtils';
20
import FlexBox from '../components/layout/FlexBox';
21
import Button from '../components/layout/Button';
22

23
function AddGroup({
24
    enabled,
25
    parent,
26
    onClose,
27
    onAdd
28
}) {
29

30
    const [groupName, setGroupName] = useState('');
11✔
31

32
    useEffect(() => {
11✔
33
        setGroupName('');
7✔
34
    }, [enabled]);
35

36
    const isValid = (name) => {
11✔
37
        return name !== '';
11✔
38
    };
39

40
    const changeName = (el) => {
11✔
41
        setGroupName(el.target.value);
2✔
42
    };
43

44
    return (
11✔
45
        <Portal>
46
            <ResizableModal
47
                enableFooter={false}
48
                size="xs"
49
                clickOutEnabled={false}
50
                showClose={false}
51
                title={<Message msgId="toc.addGroup" />}
52
                show={enabled}
53
                fitContent>
54
                <div id="mapstore-add-toc-group">
55
                    <FormGroup>
56
                        <label htmlFor="groupName"><Message msgId="addgroup.groupName"/></label>
57
                        <FormControl name="groupName" onChange={changeName} value={groupName}/>
58
                    </FormGroup>
59
                </div>
60
                <FlexBox style={{padding: 8}} centerChildrenVertically  gap="sm">
61
                    <FlexBox.Fill/>
62
                    <Button
63
                        onClick={onClose}><Message msgId="cancel"/>
64
                    </Button>
65
                    <Button
66
                        disabled= {!isValid(groupName)}
67
                        variant="success"
68
                        onClick={() => {
69
                            onAdd(groupName, parent);
2✔
70
                            onClose();
2✔
71
                        }}>
72
                        <Message msgId="addgroup.addbtn" />
73
                    </Button>
74
                </FlexBox>
75
            </ResizableModal>
76
        </Portal>
77
    );
78
}
79

80
AddGroup.propTypes = {
1✔
81
    enabled: PropTypes.bool,
82
    parent: PropTypes.string,
83
    onClose: PropTypes.func,
84
    onAdd: PropTypes.func
85
};
86

87
AddGroup.defaultProps = {
1✔
88
    enabled: false,
89
    parent: null,
90
    onClose: () => {},
91
    onAdd: () => {}
92
};
93

94
const selector = (state) => ({
13✔
95
    enabled: get(state, "controls.addgroup.enabled", false),
96
    parent: get(state, "controls.addgroup.parent", null)
97
});
98

99
const AddGroupPlugin = connect(selector, {
1✔
100
    onClose: setControlProperties.bind(null, "addgroup", "enabled", false, "parent", null),
101
    onAdd: addGroup
102
})(AddGroup);
103

104
const AddGroupButton = connect(selector, {
1✔
105
    onClick: setControlProperties.bind(null, 'addgroup', 'enabled', true, 'parent')
106
})(({
107
    onClick,
108
    status,
109
    itemComponent,
110
    selectedNodes,
111
    statusTypes,
112
    rootGroupId,
113
    defaultGroupId,
114
    nodeTypes,
115
    config,
116
    ...props
117
}) => {
118

119
    const ItemComponent = itemComponent;
6✔
120

121
    // deprecated TOC configuration
122
    if (config.activateAddGroupButton === false) {
6!
123
        return null;
×
124
    }
125

126
    if ([statusTypes.DESELECT, statusTypes.GROUP].includes(status)) {
6✔
127
        const parseParent = (value) => {
3✔
128
            return value === rootGroupId ? undefined : value;
3!
129
        };
130
        const node = selectedNodes?.[0];
3✔
131
        const group = node?.type === nodeTypes.GROUP
3!
132
            ? node?.id
133
            : node?.parentId;
134
        const parsedGroup = parseParent(group);
3✔
135
        const value = parsedGroup
3!
136
            ? parsedGroup
137
            : config.singleDefaultGroup
3✔
138
                ? defaultGroupId
139
                : undefined;
140
        return (
3✔
141
            <ItemComponent
142
                {...props}
143
                glyph="add-folder"
144
                labelId={node?.type === nodeTypes.GROUP ? 'toc.addSubGroup' : 'toc.addGroup'}
3!
145
                tooltipId={node?.type === nodeTypes.GROUP ? 'toc.addSubGroup' : 'toc.addGroup'}
3!
146
                onClick={() => onClick(value)}
×
147
            />
148
        );
149
    }
150
    return null;
3✔
151
});
152

153
/**
154
 * Adds to the {@link #plugins.TOC|TOC} plugin a button for creating new layer groups.
155
 * @name AddGroup
156
 * @class
157
 * @memberof plugins
158
 * @requires plugins.TOC
159
 */
160
export default createPlugin('AddGroup', {
161
    component: AddGroupPlugin,
162
    containers: {
163
        TOC: [{
164
            name: "AddGroup",
165
            target: 'toolbar',
166
            Component: AddGroupButton,
167
            position: 3
168
        }, {
169
            name: "AddGroup",
170
            target: 'context-menu',
171
            Component: AddGroupButton,
172
            position: 3
173
        }]
174
    }
175
});
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

© 2026 Coveralls, Inc