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

geosolutions-it / MapStore2 / 19710972030

26 Nov 2025 03:38PM UTC coverage: 76.665% (-0.3%) from 76.929%
19710972030

Pull #11119

github

web-flow
Fix maven publish (#11739)
Pull Request #11119: Layer Selection Plugin on ArcGIS, WFS & WMS layers

32272 of 50209 branches covered (64.28%)

3 of 3 new or added lines in 2 files covered. (100.0%)

3018 existing lines in 249 files now uncovered.

40157 of 52380 relevant lines covered (76.66%)

37.9 hits per line

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

7.41
/web/client/components/data/featuregrid/editors/DropDownEditor.jsx
1
/*
2
 * Copyright 2017, 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
import React from 'react';
9

10
import PropTypes from 'prop-types';
11
import AttributeEditor from './AttributeEditor';
12
import ControlledCombobox from '../../../misc/combobox/ControlledCombobox';
13
import { forceSelection } from '../../../../utils/FeatureGridEditorUtils';
14
import { head } from 'lodash';
15
/**
16
 * Editor that provides a DropDown menu of a list of elements passed.
17
 * @memberof components.data.featuregrid.editors
18
 * @class
19
 * @name DropDownEditor
20
 * @prop {string[]} values list of valid values
21
 * @prop {boolean} forceSelection forces the editor to use a `defaultOption` as value
22
 * @prop {string} defaultOption value used as default if forceSelection is true
23
 * @prop {boolean} allowEmpty if true it accept empty string as value
24
 * @prop {string} emptyValue is an empty string
25
 *
26
 */
27
class DropDownEditor extends AttributeEditor {
28
    static propTypes = {
1✔
29
        column: PropTypes.object,
30
        dataType: PropTypes.string,
31
        defaultOption: PropTypes.string,
32
        forceSelection: PropTypes.bool,
33
        allowEmpty: PropTypes.bool,
34
        inputProps: PropTypes.object,
35
        isValid: PropTypes.func,
36
        onBlur: PropTypes.func,
37
        typeName: PropTypes.string,
38
        value: PropTypes.string,
39
        filter: PropTypes.string,
40
        values: PropTypes.array,
41
        labels: PropTypes.array,
42
        emptyValue: PropTypes.string
43
    };
44
    static defaultProps = {
1✔
UNCOV
45
        isValid: () => true,
×
46
        dataType: "string",
47
        filter: "contains",
48
        values: [],
49
        forceSelection: true,
50
        allowEmpty: true,
51
        emptyValue: ""
52
    };
53
    constructor(props) {
UNCOV
54
        super(props);
×
55
        this.validate = (value) => {
×
56
            try {
×
57
                return this.props.isValid(value[this.props.column && this.props.column.key]);
×
58
            } catch (e) {
UNCOV
59
                return false;
×
60
            }
61
        };
UNCOV
62
        this.getValueByLabel = (label) => {
×
63
            try {
×
64
                return this.props.values[this.props.labels.indexOf(label)];
×
65
            } catch (e) {
UNCOV
66
                return label;
×
67
            }
68
        };
UNCOV
69
        this.getValue = () => {
×
70
            const updated = super.getValue();
×
71
            if (this.props.forceSelection) {
×
72
                return {[this.props.column.key]: forceSelection({
×
73
                    oldValue: this.props.defaultOption,
74
                    changedValue: this.getValueByLabel(updated[this.props.column && this.props.column.key]),
×
75
                    data: this.props.values,
76
                    allowEmpty: this.props.allowEmpty,
77
                    emptyValue: this.props.emptyValue
78
                })};
79
            }
UNCOV
80
            if (this.props.allowEmpty) {
×
81
                return updated;
×
82
            }
83
            // this case is only when forceSelection and allowEmpty are falsy, but this is contractidtory!! so the default option is used
UNCOV
84
            return {[this.props.column.key]: forceSelection({
×
85
                oldValue: this.props.defaultOption,
86
                changedValue: this.getValueByLabel(updated[this.props.column && this.props.column.key]),
×
87
                data: this.props.values,
88
                allowEmpty: this.props.allowEmpty,
89
                emptyValue: this.props.emptyValue
90
            })};
91
        };
92
    }
93
    render() {
UNCOV
94
        const self = this;
×
95
        var data = [];
×
96
        if (this.props.values && this.props.labels && this.props.values.lenght === this.props.labels.lenght) {
×
97
            this.props.values.forEach(function(value, id) {
×
98
                data.push({label: self.props.labels[id], value: value});
×
99
            });
100
        } else {
UNCOV
101
            data = this.props.values.map(v => {return {label: v, value: v}; });
×
102
        }
103

UNCOV
104
        const props = Object.assign({}, {...this.props}, {
×
105
            data,
106
            defaultOption: this.props.defaultOption || head(this.props.values)
×
107
        });
UNCOV
108
        return <ControlledCombobox {...props} filter={this.props.filter}/>;
×
109
    }
110
}
111

112
export default DropDownEditor;
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