[Maps] add ungroup layers action (#144574)

* [Maps] add ungroup layers action

* [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix'

* tslint

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Nathan Reese 2022-11-07 11:47:05 -07:00 committed by GitHub
parent ce9a253796
commit adfa8f7ddd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 16 deletions

View file

@ -876,7 +876,7 @@ export function createLayerGroup(draggedLayerId: string, combineLayerId: string)
};
}
function ungroupLayer(layerId: string) {
export function ungroupLayer(layerId: string) {
return (
dispatch: ThunkDispatch<MapStoreState, void, AnyAction>,
getState: () => MapStoreState

View file

@ -16,6 +16,7 @@ import {
setDrawMode,
showThisLayerOnly,
toggleLayerVisible,
ungroupLayer,
updateEditLayer,
} from '../../../../../../actions';
import { getLayerListRaw } from '../../../../../../selectors/map_selectors';
@ -55,6 +56,9 @@ function mapDispatchToProps(dispatch: ThunkDispatch<MapStoreState, void, AnyActi
showThisLayerOnly: (layerId: string) => {
dispatch(showThisLayerOnly(layerId));
},
ungroupLayer: (layerId: string) => {
dispatch(ungroupLayer(layerId));
},
};
}

View file

@ -50,6 +50,7 @@ const defaultProps = {
openLayerSettings: () => {},
numLayers: 2,
showThisLayerOnly: () => {},
ungroupLayer: () => {},
};
describe('TOCEntryActionsPopover', () => {

View file

@ -21,6 +21,7 @@ import { ESSearchSource } from '../../../../../../classes/sources/es_search_sour
import { isVectorLayer, IVectorLayer } from '../../../../../../classes/layers/vector_layer';
import { SCALING_TYPES, VECTOR_SHAPE_TYPE } from '../../../../../../../common/constants';
import { RemoveLayerConfirmModal } from '../../../../../../components/remove_layer_confirm_modal';
import { isLayerGroup, LayerGroup } from '../../../../../../classes/layers/layer_group';
export interface Props {
cloneLayer: (layerId: string) => void;
@ -38,6 +39,7 @@ export interface Props {
supportsFitToBounds: boolean;
toggleVisible: (layerId: string) => void;
numLayers: number;
ungroupLayer: (layerId: string) => void;
}
interface State {
@ -114,18 +116,6 @@ export class TOCEntryActionsPopover extends Component<Props, State> {
}));
};
_cloneLayer() {
this.props.cloneLayer(this.props.layer.getId());
}
_fitToBounds() {
this.props.fitToBounds(this.props.layer.getId());
}
_toggleVisible() {
this.props.toggleVisible(this.props.layer.getId());
}
_getActionsPanel() {
const actionItems = [
{
@ -140,7 +130,7 @@ export class TOCEntryActionsPopover extends Component<Props, State> {
disabled: !this.props.supportsFitToBounds,
onClick: () => {
this._closePopover();
this._fitToBounds();
this.props.fitToBounds(this.props.layer.getId());
},
},
{
@ -150,7 +140,7 @@ export class TOCEntryActionsPopover extends Component<Props, State> {
toolTipContent: null,
onClick: () => {
this._closePopover();
this._toggleVisible();
this.props.toggleVisible(this.props.layer.getId());
},
},
];
@ -218,9 +208,27 @@ export class TOCEntryActionsPopover extends Component<Props, State> {
'data-test-subj': 'cloneLayerButton',
onClick: () => {
this._closePopover();
this._cloneLayer();
this.props.cloneLayer(this.props.layer.getId());
},
});
if (
isLayerGroup(this.props.layer) &&
(this.props.layer as LayerGroup).getChildren().length > 0
) {
actionItems.push({
name: i18n.translate('xpack.maps.layerTocActions.ungroupLayerTitle', {
defaultMessage: 'Ungroup layers',
}),
icon: <EuiIcon type="layers" size="m" />,
toolTipContent: null,
'data-test-subj': 'removeLayerButton',
onClick: () => {
this._closePopover();
this.props.ungroupLayer(this.props.layer.getId());
this.props.removeLayer(this.props.layer.getId());
},
});
}
actionItems.push({
name: i18n.translate('xpack.maps.layerTocActions.removeLayerTitle', {
defaultMessage: 'Remove layer',