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

geosolutions-it / MapStore2 / 13569334073

27 Feb 2025 02:59PM UTC coverage: 76.809% (+0.005%) from 76.804%
13569334073

Pull #10851

github

web-flow
Merge 5a415ccd2 into 7e54e5bbd
Pull Request #10851: Fix #10818 Review and uniform all confirmation modals according to a common design.

31304 of 48878 branches covered (64.05%)

3 of 7 new or added lines in 5 files covered. (42.86%)

6 existing lines in 2 files now uncovered.

38853 of 50584 relevant lines covered (76.81%)

35.76 hits per line

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

47.62
/web/client/plugins/TOC/containers/RemoveNodesButton.jsx
1
/*
2
 * Copyright 2024, 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, { useState } from 'react';
10
import { connect } from 'react-redux';
11
import { removeNode } from '../../../actions/layers';
12
import ConfirmModal from '../../../components/layout/ConfirmDialog';
13
import Portal from '../../../components/misc/Portal';
14

15

16
const getRemoveNodes = (node) => {
1✔
17
    return [
×
18
        ...(node?.id ? [ node ] : []),
×
19
        ...(node?.nodes || []).map(getRemoveNodes).flat()
×
20
    ];
21
};
22
/**
23
 * This component provides the remove node actions to make them available inside the toolbar or context menu
24
 */
25
const RemoveNodesButton = connect(() => ({}), {
42✔
26
    onRemove: removeNode
27
})(({
28
    onRemove,
29
    status,
30
    itemComponent,
31
    selectedNodes,
32
    statusTypes,
33
    nodeTypes,
34
    config,
35
    rootGroupId,
36
    ...props
37
}) => {
38

39
    const ItemComponent = itemComponent;
42✔
40
    const [showDeleteDialog, setShowDeleteDialog] = useState(null);
42✔
41

42
    function handleRemoveNodes() {
43
        const { nodes } = showDeleteDialog || {};
×
44
        const nodesToRemove = getRemoveNodes({ id: null, nodes });
×
45
        nodesToRemove.forEach((node) => {
×
46
            onRemove(node.id, node?.nodes ? nodeTypes.GROUP : nodeTypes.LAYER);
×
47
        });
48
        setShowDeleteDialog(null);
×
49
    }
50

51
    if (selectedNodes?.[0]?.id === rootGroupId) {
42!
52
        return null;
×
53
    }
54

55
    if (config.activateRemoveLayer === false && [statusTypes.LAYER, statusTypes.LAYERS].includes(status)) {
42!
56
        return null;
×
57
    }
58

59
    if (config.activateRemoveGroup === false && [statusTypes.GROUP, statusTypes.GROUPS].includes(status)) {
42!
60
        return null;
×
61
    }
62

63
    const isSelectedGroup = [statusTypes.GROUP, statusTypes.GROUPS, statusTypes.BOTH].includes(status);
42✔
64
    const isSingleLayer = statusTypes.LAYER === status;
42✔
65
    return (
42✔
66
        <>
67
            {[statusTypes.LAYER, statusTypes.LAYERS, statusTypes.GROUP, statusTypes.GROUPS, statusTypes.BOTH].includes(status) ? <ItemComponent
42✔
68
                {...props}
69
                glyph="trash"
70
                active={showDeleteDialog}
71
                labelId={
72
                    isSelectedGroup
8!
73
                        ? 'toc.toolTrashGroupTooltip'
74
                        : isSingleLayer
8!
75
                            ? 'toc.toolTrashLayerTooltip'
76
                            : 'toc.toolTrashLayersTooltip'
77
                }
78
                tooltipId={
79
                    isSelectedGroup
8!
80
                        ? 'toc.toolTrashGroupTooltip'
81
                        : isSingleLayer
8!
82
                            ? 'toc.toolTrashLayerTooltip'
83
                            : 'toc.toolTrashLayersTooltip'
84
                }
85
                onClick={() => setShowDeleteDialog({ nodes: selectedNodes.map(({ node }) => node) })}
×
86
            /> : null}
87
            <Portal>
88
                <ConfirmModal
89
                    show= {!!showDeleteDialog}
NEW
90
                    onCancel={() => setShowDeleteDialog(null)}
×
91
                    onConfirm={handleRemoveNodes}
92
                    preventHide
93
                    titleId= { isSelectedGroup ? "layerProperties.deleteLayerGroupMessage" : "layerProperties.deleteLayerMessage" }
42!
94
                    confirmId={`layerProperties.delete`}
95
                    cancelId={`cancel`}
96
                    variant="danger"
97
                />
98
            </Portal>
99
        </>
100
    );
101
});
102

103
export default RemoveNodesButton;
104

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