• 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

87.1
/web/client/components/data/featuregrid/editors/NumberEditor.jsx
1
/*
2
 * Copyright 2020, 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 from 'react';
10
import PropTypes from 'prop-types';
11
import { isNumber, castArray } from 'lodash';
12
import IntlNumberFormControl from '../../../I18N/IntlNumberFormControl';
13
import { editors } from 'react-data-grid';
14

15
const parsers = {
1✔
16
    "int": v => parseInt(v, 10),
2✔
17
    "number": v => parseFloat(v, 10)
9✔
18
};
19

20
/**
21
 * Editor of the FeatureGrid, that allows to insert a number, limited by `minValue` and `maxValue`
22
 * @memberof components.data.featuregrid.editors
23
 * @name NumberEditor
24
 * @class
25
 * @prop {number} editorProps.minValue the lower boundary of valid numbers
26
 * @prop {number} editorProps.maxValue the upper boundary of valid numbers
27
 */
28
export default class NumberEditor extends editors.SimpleTextEditor {
29
    static propTypes = {
1✔
30
        value: PropTypes.oneOfType([
31
            PropTypes.string,
32
            PropTypes.number,
33
            PropTypes.null
34
        ]),
35
        inputProps: PropTypes.object,
36
        dataType: PropTypes.string,
37
        minValue: PropTypes.number,
38
        maxValue: PropTypes.number,
39
        column: PropTypes.object,
40
        onTemporaryChanges: PropTypes.func
41
    };
42

43
    static defaultProps = {
1✔
44
        dataType: "number",
45
        column: {}
46
    };
47

48
    constructor(props) {
49
        super(props);
5✔
50
        const value = props.value?.toString?.() ?? '';
5!
51
        this.state = {
5✔
52
            inputText: value,
53
            isValid: this.validateTextValue(value),
54
            validated: true
55
        };
56
    }
57

58
    componentDidMount() {
59
        this.props.onTemporaryChanges?.(true);
5✔
60
    }
61

62
    componentWillUnmount() {
63
        this.props.onTemporaryChanges?.(false);
5✔
64

65
    }
66

67
    getValue() {
68
        try {
4✔
69
            const numberValue = this.state.inputText === '' ? null : parsers[this.props.dataType](this.state.inputText);
4!
70
            return {
4✔
71
                [this.props.column.key]: numberValue
72
            };
73
        } catch (e) {
UNCOV
74
            return {
×
75
                [this.props.column.key]: this.props.value
76
            };
77
        }
78
    }
79

80
    getMinValue() {
81
        return this.props?.column?.schema?.minimum ?? this.props.minValue;
16✔
82
    }
83

84
    getMaxValue() {
85
        return this.props?.column?.schema?.maximum ?? this.props.maxValue;
16✔
86
    }
87

88
    render() {
89
        return (<div className={`ms-cell-editor ${!this.state.validated || this.state.isValid ? '' : 'invalid'}`}><IntlNumberFormControl
7✔
90
            {...this.props.inputProps}
91
            value={this.state.inputText}
92
            type="number"
93
            min={this.getMinValue()}
94
            max={this.getMaxValue()}
95
            className="form-control"
96
            defaultValue={this.props.value}
97
            onKeyDown={this.props.onKeyDown}
98
            onBlur={this.props.onBlur}
99
            onChange={(val) => {
100
                this.setState({
2✔
101
                    inputText: val,
102
                    isValid: this.validateTextValue(val),
103
                    validated: true
104
                });
105
            }}
106
        /></div>);
107
    }
108

109
    validateTextValue = (value) => {
5✔
110
        if (value === '') {
7!
UNCOV
111
            return castArray(this.props?.column?.schema?.type || []).includes('null');
×
112
        }
113
        if (!parsers[this.props.dataType]) {
7!
UNCOV
114
            return false;
×
115
        }
116
        try {
7✔
117
            const numberValue = parsers[this.props.dataType](value);
7✔
118

119
            return this.validateNumberValue(numberValue);
7✔
120
        } catch (e) {
UNCOV
121
            return false;
×
122
        }
123
    };
124

125
    validateNumberValue = (value) => {
5✔
126
        const minValue = this.getMinValue();
9✔
127
        const maxValue = this.getMaxValue();
9✔
128
        return isNumber(value) &&
9!
129
            !isNaN(value) &&
130
            (!isNumber(minValue) || minValue <= value) &&
131
            (!isNumber(maxValue) || maxValue >= value);
132
    };
133
}
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