• 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

97.37
/web/client/components/misc/enhancers/withResizeSpy.js
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

9
import React from 'react';
10

11
import { debounce } from 'lodash';
12
import PropTypes from 'prop-types';
13
import ReactDom from 'react-dom';
14

15
/**
16
 * Enhancer that calls the prop handler `onResize` when the div has been resized.
17
 * @param {String}  querySelector           selector to get the element from the current component DOM element
18
 * @param {Boolean} [closest=false]         if true, the querySelector will be used to search 1st parent. see [closest](https://developer.mozilla.org/en-US/docs/Web/API/Element/closest)
19
 * @param {debounceTime}
20
 * @return {HOC} An Higher Order Component that will call `onResize` when the item has been resized
21
 * @example
22
 * const Cmp = withResizeSpy({querySelector: "div"})(MyComponent);
23
 * //... layer in a render
24
 * <Cmp onResize={() => console.log("Resized")} />;
25
 *
26
 */
27
export default ({
1✔
28
    debounceTime,
29
    querySelector,
30
    closest = false
7✔
31
} = {}) => (Component) =>
8✔
32
    (class WithResizeSpy extends React.Component {
8✔
33
    static propTypes = {
8✔
34
        handleWidth: PropTypes.bool,
35
        handleHeight: PropTypes.bool,
36
        onResize: PropTypes.func
37
    }
38
    static defaultProps = {
8✔
39
        onResize: () => { },
40
        handleWidth: true,
41
        handleHeight: true
42
    }
43
    constructor(props) {
44
        super(props);
38✔
45
        this.width = undefined;
38✔
46
        this.height = undefined;
38✔
47
        this.skipOnMount = props.skipOnMount;
38✔
48
        this.div = null;
38✔
49
        this.onResize = debounce((...args) => this.props.onResize(...args), debounceTime !== undefined ? debounceTime : props.debounceTime || 1000);
38✔
50
        this.ro = new ResizeObserver((entries) => {
38✔
51
            entries.forEach((entry) => {
3✔
52
                const { width, height } = entry.contentRect;
3✔
53
                const notifyWidth = this.props.handleWidth && this.width !== width;
3✔
54
                const notifyHeight = this.props.handleHeight && this.height !== height;
3✔
55
                if (!this.skipOnMount && (notifyWidth || notifyHeight)) {
3!
56
                    this.onResize({width, height});
3✔
57
                }
58

59
                this.width = width;
3✔
60
                this.height = height;
3✔
61
                this.skipOnMount = false;
3✔
62
            });
63
        });
64
    }
65
    findDomNode = () => {
38✔
66
        if (!this.isMounded) {
90!
UNCOV
67
            return null;
×
68
        }
69
        let node = ReactDom.findDOMNode(this);
90✔
70
        if (node && closest && querySelector) {
90✔
71
            return node.closest(querySelector || "*");
9!
72
        }
73
        return node && (querySelector ? node.querySelector(querySelector) : node);
81!
74
    }
75
    componentDidMount() {
76
        this.isMounded = true;
38✔
77
        this.div = this.findDomNode();
38✔
78
        if (this.div) {
38✔
79
            this.ro.observe(this.div);
2✔
80
        }
81
    }
82
    componentDidUpdate() {
83
        this.div = this.findDomNode();
14✔
84
        if (this.div) {
14✔
85
            this.ro.observe(this.div);
11✔
86
        }
87
    }
88
    componentWillUnmount() {
89
        const div = this.findDomNode();
38✔
90
        if (div && this.ro && this.ro.unobserve) {
38✔
91
            this.ro.unobserve(div);
32✔
92
        }
93
    }
94

95

96
    render() {
97
        return <Component {...this.props} />;
52✔
98
    }
99
    });
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