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

geosolutions-it / MapStore2 / 14262319268

04 Apr 2025 09:28AM UTC coverage: 76.918% (-0.05%) from 76.963%
14262319268

push

github

web-flow
#10923, #10924: Disabling GeoFence Rules and Add filter by IP for GeoFence rules (#10925)

* #10923: Add filter by IP for GeoFence rules
#10924: Disabling GeoFence Rules

Description:
- adding IPAddress filter in rules manage grid
- adding Date filter  in rules manage grid for validity period fields
- add validity period fields for rule insertion/update
- add unit tests
- add translations

* #10923: Add filter by IP for GeoFence rules
#10924: Disabling GeoFence Rules

Description:
- fix FE failure unit test

* #10923: Add filter by IP for GeoFence rules
#10924: Disabling GeoFence Rules

Description:
- fix bug of change date filter manually
- add tooltip for date fields in insert new rule or date filter in rules manager
- fix the crashing app issue of remove add rules in the grid
- add translations

* #10923, 10924: resolve review comments for editing tooltips of any field checkbox in rule managers, handles cases of check/uncheck
Description:
- handles these cases in check/uncheck any field in rules manager grid:
* with no value, the flag should not be send
* When value is set:
   - When checked, the flag should be send with value false
   - When unchecked the flag should be sent with value true.
- add unit tests
- edit tooltips + translations for check/uncheck in rules manager

* Fixed translation and label position

* Update web/client/translations/data.it-IT.json

Co-authored-by: Tobia Di Pisa <tobia.dipisa@geosolutionsgroup.com>

* Update web/client/translations/data.it-IT.json

* Update web/client/translations/data.it-IT.json

* Updated other languages

---------

Co-authored-by: Lorenzo Natali <lorenzo.natali@geosolutionsgroup.com>
Co-authored-by: Tobia Di Pisa <tobia.dipisa@geosolutionsgroup.com>

31062 of 48387 branches covered (64.19%)

61 of 109 new or added lines in 10 files covered. (55.96%)

4 existing lines in 3 files now uncovered.

38586 of 50165 relevant lines covered (76.92%)

35.72 hits per line

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

41.38
/web/client/components/manager/rulesmanager/rulesgrid/filterRenderers/IPAddressFilter.jsx
1
/**
2
* Copyright 2025, 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, { useState } from 'react';
9
import { compose, defaultProps, withHandlers } from 'recompose';
10
import localizedProps from '../../../../misc/enhancers/localizedProps';
11
import { connect } from 'react-redux';
12
import { createSelector } from 'reselect';
13
import { filterSelector } from '../../../../../selectors/rulesmanager';
14
import { error } from '../../../../../actions/notifications';
15
import { FormGroup, Tooltip } from 'react-bootstrap';
16
import OverlayTrigger from '../../../../misc/OverlayTrigger';
17
import { checkIpV4Range } from '../../../../../utils/RulesEditorUtils';
18
import DebouncedFormControl from '../../../../misc/DebouncedFormControl';
19
const selector = createSelector(filterSelector, (filter) => ({
1✔
20
    selected: filter.ipAddress,
21
    anyFieldVal: filter.ipAddressAny
22
}));
23

24
const IPAddressFilter = (props) => {
1✔
25
    const [ipAddressRangeValid, setIpAddressRangeValid] = useState(false);
1✔
26
    const {disabled, onReset, label: l, clearable = true, onFilterChange, placeholder, selected: selectedValue, onChange } = props;
1✔
27
    let label = l ? (<label>{l}</label>) :  null;
1!
28
    const renderTooltipCheckbox = () => {
1✔
29
        const { anyFieldVal } = props;
1✔
30

31
        let checkboxInput = (
32
            <input onChange={(evt)=>{
1✔
NEW
33
                onFilterChange({column: {key: evt.target.name}, filterTerm: !evt.target.checked});
×
34
            }} type="checkbox" checked={!!(typeof anyFieldVal === 'boolean' && !anyFieldVal)}
1!
35
            name={props.anyFilterRuleMode} />
36
        );
37
        const tooltip = (<Tooltip id={props?.tooltip?.id + anyFieldVal ? "checked" : "unchecked"}>
1!
38
            { !!(typeof anyFieldVal === 'boolean' && !anyFieldVal) ? props?.checkedAnyField : props?.unCheckedAnyField }</Tooltip>);
2!
39
        return (<OverlayTrigger key={props?.tooltip?.overlayTriggerKey} placement={props?.tooltip?.placement} overlay={tooltip}>
1✔
40
            { checkboxInput }
41
        </OverlayTrigger>);
42
    };
43
    const setIpAddressRangeValidHandler = (selectedVal) => {
1✔
NEW
44
        if (selectedVal && selectedVal.length > 0) {
×
NEW
45
            return selectedVal.match(checkIpV4Range) && "success" || "error";
×
46
        }
NEW
47
        return null;
×
48
    };
49
    return (
1✔
50
        <div className={`autocompleteField ${props.anyFilterRuleMode ? 'd-flex' : ''}`}>
1!
51
            {label}
52
            {clearable ? (
1!
53
                <div className={`input-clearable ${disabled && 'disabled' || ''}`}>
2!
54
                    <FormGroup style={{margin: 0}} validationState={ipAddressRangeValid} className="rw-widget">
55
                        <DebouncedFormControl
56
                            type="text"
57
                            className={"form-control input-sm"}
58
                            value={selectedValue || ""}
2✔
59
                            placeholder={placeholder}
60
                            onChange={(value) => {
NEW
61
                                const isValid = setIpAddressRangeValidHandler(value);
×
NEW
62
                                setIpAddressRangeValid(isValid);
×
NEW
63
                                if (isValid !== 'error') {
×
NEW
64
                                    onChange({column: {key: "ipAddress"}, filterTerm: value});
×
65
                                }
66
                            }}
67
                        />
68
                    </FormGroup>
69
                    <span className={`clear-btn ${!selectedValue && 'hidden' || ''}`} onClick={()=>{
2!
NEW
70
                        if (props.anyFilterRuleMode) {
×
71
                            // reset the checkbox as well
NEW
72
                            onFilterChange({column: {key: "ipAddress"}, filterTerm: undefined, isResetField: true});
×
73
                        } else {
NEW
74
                            onReset();
×
75
                        }
76
                    }}>x</span>
77
                </div>) :
78
                <FormGroup style={{margin: 0}} validationState={ipAddressRangeValid} className="rw-widget">
79
                    <DebouncedFormControl
80
                        type="text"
81
                        className={"form-control input-sm"}
82
                        value={selectedValue || ""}
×
83
                        placeholder={placeholder}
84
                        onChange={(value) => {
NEW
85
                            const isValid = setIpAddressRangeValidHandler(value);
×
NEW
86
                            setIpAddressRangeValid(isValid);
×
NEW
87
                            if (isValid !== 'error') {
×
NEW
88
                                onChange({column: {key: "ipAddress"}, filterTerm: value});
×
89
                            }
90
                        }}
91
                    />
92
                </FormGroup>
93
            }
94
            { props.anyFilterRuleMode ?
1!
95
                <>
96
                    &nbsp;
97
                    <div className="checkbox-any-field">
98
                        {renderTooltipCheckbox()}
99
                    </div>
100
                </> : null}
101
        </div>);
102
};
103
export default compose(
104
    connect(selector, {onError: error}),
105
    defaultProps({
106
        size: 5,
107
        textField: "ipAddress",
108
        valueField: "ipAddress",
109
        parentsFilter: {},
110
        filter: false,
111
        placeholder: "rulesmanager.placeholders.ipRange",
112
        unCheckedAnyField: "rulesmanager.tooltip.filterRuleList",
113
        checkedAnyField: "rulesmanager.tooltip.showAllRules",
114
        anyFilterRuleMode: 'ipAddressAny'
115
    }),
116
    withHandlers({
NEW
117
        onChangeHeaderFilter: ({column = {}, onFilterChange = () => {}}) => filterTerm => {
×
NEW
118
            onFilterChange({column, filterTerm});
×
119
        }
120
    }),
121
    localizedProps(["placeholder", "checkedAnyField", "unCheckedAnyField"])
122
)(IPAddressFilter);
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