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

geosolutions-it / MapStore2 / 15422327504

03 Jun 2025 04:08PM UTC coverage: 76.952% (-0.04%) from 76.993%
15422327504

Pull #11024

github

web-flow
Merge 2ddc9a6d7 into 2dbe8dab2
Pull Request #11024: Update User Guide - Upload image on Text Widget

31021 of 48282 branches covered (64.25%)

38629 of 50199 relevant lines covered (76.95%)

36.23 hits per line

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

61.54
/web/client/plugins/MapTemplates.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 from 'react';
10
import { get } from 'lodash';
11
import { connect } from 'react-redux';
12
import { Glyphicon } from 'react-bootstrap';
13
import { createSelector } from 'reselect';
14
import { createPlugin } from '../utils/PluginsUtils';
15

16
import {setControlProperty, toggleControl} from '../actions/controls';
17
import { templatesSelector, mapTemplatesLoadedSelector } from '../selectors/maptemplates';
18
import { openMapTemplatesPanel, mergeTemplate, replaceTemplate, toggleFavouriteTemplate, setAllowedTemplates } from '../actions/maptemplates';
19

20
import Message from '../components/I18N/Message';
21
import Loader from '../components/misc/Loader';
22
import MapTemplatesPanel from '../components/maptemplates/MapTemplatesPanel';
23

24
import maptemplates from '../reducers/maptemplates';
25
import * as epics from '../epics/maptemplates';
26
import {mapLayoutValuesSelector} from "../selectors/maplayout";
27
import PropTypes from "prop-types";
28
import ResponsivePanel from "../components/misc/panels/ResponsivePanel";
29
import { DEFAULT_PANEL_WIDTH } from '../utils/LayoutUtils';
30

31
/**
32
 * Provides a list of map templates available inside of a currently loaded context.
33
 * Allows to merge their contents with the current map configuration or to replace it entirely.
34
 * Map templates can be of various formats(currently supported are MapStore JSON, OGC WMC)
35
 * @memberof plugins
36
 * @class
37
 * @name MapTemplates
38
 * @prop {object[]} cfg.allowedTemplates: A list of objects with map template ids used to load templates when not in context
39
 */
40
class MapTemplatesComponent extends React.Component {
41
    static propTypes = {
1✔
42
        active: PropTypes.bool,
43
        templatesLoaded: PropTypes.bool,
44
        templates: PropTypes.array,
45
        allowedTemplates: PropTypes.array,
46
        dockStyle: PropTypes.object,
47
        onToggleControl: PropTypes.func,
48
        onMergeTemplate: PropTypes.func,
49
        onReplaceTemplate: PropTypes.func,
50
        onToggleFavourite: PropTypes.func,
51
        onSetAllowedTemplates: PropTypes.func,
52
        size: PropTypes.number
53
    };
54

55
    static defaultProps = {
1✔
56
        active: false,
57
        templatesLoaded: false,
58
        templates: [],
59
        allowedTemplates: [],
60
        dockStyle: {},
61
        onToggleControl: () => {},
62
        onMergeTemplate: () => {},
63
        onReplaceTemplate: () => {},
64
        onToggleFavourite: () => {},
65
        onSetAllowedTemplates: () => {},
66
        size: DEFAULT_PANEL_WIDTH
67
    };
68

69
    componentDidUpdate(prevProps) {
70
        const { active, allowedTemplates, onSetAllowedTemplates } = this.props;
×
71
        const { active: prevActive } = prevProps;
×
72
        if (active !== prevActive) {
×
73
            if (active) {
×
74
                onSetAllowedTemplates(allowedTemplates);
×
75
            }
76
        }
77

78
    }
79

80
    render() {
81
        const {
82
            active,
83
            templates,
84
            templatesLoaded,
85
            onToggleControl,
86
            onMergeTemplate,
87
            onReplaceTemplate,
88
            onToggleFavourite,
89
            dockStyle,
90
            size
91
        } = this.props;
3✔
92
        return (
3✔
93
            <ResponsivePanel
94
                containerStyle={dockStyle}
95
                containerId="map-templates-container"
96
                containerClassName="dock-container"
97
                className="map-templates-dock-panel"
98
                open={active}
99
                position="right"
100
                size={size}
101
                title={<Message msgId="mapTemplates.title"/>}
102
                style={dockStyle}
103
                onClose={onToggleControl}
104
            >
105
                {!templatesLoaded && <div className="map-templates-loader"><Loader size={352}/></div>}
4✔
106
                {templatesLoaded && <MapTemplatesPanel
5✔
107
                    templates={templates}
108
                    onMergeTemplate={onMergeTemplate}
109
                    onReplaceTemplate={onReplaceTemplate}
110
                    onToggleFavourite={onToggleFavourite}/>}
111
            </ResponsivePanel>
112
        );
113
    }
114
}
115

116
const MapTemplatesPlugin = connect(createSelector(
1✔
117
    state => mapLayoutValuesSelector(state, { height: true, right: true }, true),
3✔
118
    state => get(state, 'controls.mapTemplates.enabled'),
3✔
119
    templatesSelector,
120
    mapTemplatesLoadedSelector,
121

122
    (dockStyle, active, templates, templatesLoaded) => ({
3✔
123
        active,
124
        templates,
125
        templatesLoaded,
126
        dockStyle
127
    })
128
), {
129
    onToggleControl: toggleControl.bind(null, 'mapTemplates', 'enabled'),
130
    onMergeTemplate: mergeTemplate,
131
    onReplaceTemplate: replaceTemplate,
132
    onToggleFavourite: toggleFavouriteTemplate,
133
    onSetAllowedTemplates: setAllowedTemplates
134
})(MapTemplatesComponent);
135

136
export default createPlugin('MapTemplates', {
137
    component: MapTemplatesPlugin,
138
    containers: {
139
        BurgerMenu: {
140
            name: 'MapTemplates',
141
            position: 998,
142
            text: <Message msgId="mapTemplates.title" />,
143
            icon: <Glyphicon glyph="1-map" />,
144
            action: openMapTemplatesPanel,
145
            priority: 2,
146
            doNotHide: true,
147
            tooltip: <Message msgId="mapTemplates.tooltip" />
148
        },
149
        SidebarMenu: {
150
            name: 'mapTemplates',
151
            position: 998,
152
            text: <Message msgId="mapTemplates.title" />,
153
            icon: <Glyphicon glyph="1-map" />,
154
            action: setControlProperty.bind(null, "mapTemplates", "enabled", true, true),
155
            toggle: true,
156
            priority: 1,
157
            doNotHide: true,
158
            tooltip: "mapTemplates.tooltip"
159
        }
160
    },
161
    reducers: {
162
        maptemplates
163
    },
164
    epics
165
});
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