Skip to content

Commit

Permalink
recursive count children for remove layer warning
Browse files Browse the repository at this point in the history
  • Loading branch information
nreese committed Oct 11, 2022
1 parent 9959df7 commit cd1447c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/maps/public/actions/layer_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ export function showThisLayerOnly(layerId: string) {
}
});

// show target layer after hiding all other layers
// show target layer after hiding all other layers
// since hiding layer group will hide its children
const targetLayer = getLayerById(layerId, getState());
if (targetLayer && !targetLayer.isVisible()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,28 @@ export interface Props {
}

export function RemoveLayerConfirmModal(props: Props) {
function getChildrenCount(layerGroup: LayerGroup) {
let count = 0;
layerGroup.getChildren().forEach((childLayer) => {
count++;
if (isLayerGroup(childLayer)) {
count = count + getChildrenCount(childLayer as LayerGroup);
}
});
return count;
}

function renderMultiLayerWarning() {
if (!isLayerGroup(props.layer)) {
return null;
}

const children = (props.layer as LayerGroup).getChildren();
return children.length > 0 ? (
const numChildren = getChildrenCount(props.layer as LayerGroup);
return numChildren > 0 ? (
<p>
{i18n.translate('xpack.maps.deleteLayerConfirmModal.multiLayerWarning', {
defaultMessage: `Removing this layer will also remove {numChildren} nested layers.`,
values: { numChildren: children.length },
values: { numChildren },
})}
</p>
) : null;
Expand Down

0 comments on commit cd1447c

Please sign in to comment.