Skip to content

Commit

Permalink
[Maps] dd remove layer button (#48581)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasneirynck authored Oct 22, 2019
1 parent beeed8d commit 4939d14
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 4 deletions.
17 changes: 14 additions & 3 deletions x-pack/legacy/plugins/maps/public/actions/map_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export function removeTrackedLayerStateForSelectedLayer() {
export function replaceLayerList(newLayerList) {
return (dispatch, getState) => {
getLayerListRaw(getState()).forEach(({ id }) => {
dispatch(removeLayer(id));
dispatch(removeLayerFromLayerList(id));
});

newLayerList.forEach(layerDescriptor => {
Expand Down Expand Up @@ -282,7 +282,7 @@ export function removeTransientLayer() {
return async (dispatch, getState) => {
const transientLayerId = getTransientLayerId(getState());
if (transientLayerId) {
await dispatch(removeLayer(transientLayerId));
await dispatch(removeLayerFromLayerList(transientLayerId));
await dispatch(setTransientLayer(null));
}
};
Expand Down Expand Up @@ -611,11 +611,22 @@ export function removeSelectedLayer() {
const state = getState();
const layerId = getSelectedLayerId(state);
dispatch(removeLayer(layerId));
dispatch(setSelectedLayer(null));
};
}

export function removeLayer(layerId) {
return async (dispatch, getState) => {
const state = getState();
const selectedLayerId = getSelectedLayerId(state);
if (layerId === selectedLayerId) {
dispatch(updateFlyout(FLYOUT_STATE.NONE));
await dispatch(setSelectedLayer(null));
}
dispatch(removeLayerFromLayerList(layerId));
};
}

function removeLayerFromLayerList(layerId) {
return (dispatch, getState) => {
const layerGettingRemoved = getLayerById(layerId, getState());
if (!layerGettingRemoved) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions x-pack/legacy/plugins/maps/public/components/layer_toc_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,22 @@ export class LayerTocActions extends Component {
this.props.cloneLayer();
}
});
actionItems.push({
name: i18n.translate('xpack.maps.layerTocActions.removeLayerTitle', {
defaultMessage: 'Remove layer',
}),
icon: (
<EuiIcon
type="trash"
size="m"
/>
),
'data-test-subj': 'removeLayerButton',
onClick: () => {
this._closePopover();
this.props.removeLayer();
}
});
}

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const mapDispatchToProps = (dispatch) => {
dispatch(setSelectedLayer(null));
},
removeLayer: () => {
dispatch(updateFlyout(FLYOUT_STATE.NONE));
dispatch(removeSelectedLayer());
}
};
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
toggleLayerVisible,
removeTransientLayer,
cloneLayer,
removeLayer
} from '../../../../../actions/map_actions';

import { hasDirtyState, getSelectedLayer, isUsingSearch } from '../../../../../selectors/map_selectors';
Expand Down Expand Up @@ -51,6 +52,9 @@ function mapDispatchToProps(dispatch) {
cloneLayer: layerId => {
dispatch(cloneLayer(layerId));
},
removeLayer: layerId => {
dispatch(removeLayer(layerId));
},
hideTOCDetails: layerId => {
dispatch(hideTOCDetails(layerId));
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ export class TOCEntry extends React.Component {

_renderLayerHeader() {
const {
removeLayer,
cloneLayer,
isReadOnly,
layer,
Expand Down Expand Up @@ -211,6 +212,9 @@ export class TOCEntry extends React.Component {
}}
editLayer={this._openLayerPanelWithCheck}
isReadOnly={isReadOnly}
removeLayer={() => {
removeLayer(layer.getId());
}}
/>

{this._renderLayerIcons()}
Expand Down

0 comments on commit 4939d14

Please sign in to comment.