From c52fc8291aef3acc6cfcdf9f791447d0ea0ff4e9 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Thu, 17 Jun 2021 08:45:15 -0600 Subject: [PATCH 1/4] [Maps] clean up feature editing name space to avoid conflicts with layer settings editing --- x-pack/plugins/maps/common/constants.ts | 2 +- .../layers/vector_layer/vector_layer.tsx | 24 ++++++++++++------- .../es_search_source/es_search_source.tsx | 2 +- .../toc_entry_actions_popover.tsx | 4 ++-- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/x-pack/plugins/maps/common/constants.ts b/x-pack/plugins/maps/common/constants.ts index c49dd4fb619b50..37a8e8063c4ed1 100644 --- a/x-pack/plugins/maps/common/constants.ts +++ b/x-pack/plugins/maps/common/constants.ts @@ -107,7 +107,7 @@ export const SOURCE_DATA_REQUEST_ID = 'source'; export const SOURCE_META_DATA_REQUEST_ID = `${SOURCE_DATA_REQUEST_ID}_${META_DATA_REQUEST_ID_SUFFIX}`; export const SOURCE_FORMATTERS_DATA_REQUEST_ID = `${SOURCE_DATA_REQUEST_ID}_${FORMATTERS_DATA_REQUEST_ID_SUFFIX}`; export const SOURCE_BOUNDS_DATA_REQUEST_ID = `${SOURCE_DATA_REQUEST_ID}_bounds`; -export const IS_EDITABLE_REQUEST_ID = 'isEditable'; +export const SUPPORTS_FEATURE_EDITING_REQUEST_ID = 'SUPPORTS_FEATURE_EDITING_REQUEST_ID'; export const MIN_ZOOM = 0; export const MAX_ZOOM = 24; diff --git a/x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.tsx b/x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.tsx index bcd46568ef58ea..8b4d25f4612ccd 100644 --- a/x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.tsx +++ b/x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.tsx @@ -28,7 +28,7 @@ import { FIELD_ORIGIN, KBN_TOO_MANY_FEATURES_IMAGE_ID, FieldFormatter, - IS_EDITABLE_REQUEST_ID, + SUPPORTS_FEATURE_EDITING_REQUEST_ID, } from '../../../../common/constants'; import { JoinTooltipProperty } from '../../tooltips/join_tooltip_property'; import { DataRequestAbortError } from '../../util/data_request'; @@ -177,10 +177,10 @@ export class VectorLayer extends AbstractLayer implements IVectorLayer { } supportsFeatureEditing(): boolean { - const dataRequest = this.getDataRequest(IS_EDITABLE_REQUEST_ID); - const data = dataRequest?.getData() as { isEditable: boolean } | undefined; + const dataRequest = this.getDataRequest(SUPPORTS_FEATURE_EDITING_REQUEST_ID); + const data = dataRequest?.getData() as { supportsFeatureEditing: boolean } | undefined; - return data ? data.isEditable : false; + return data ? data.supportsFeatureEditing : false; } hasJoins() { @@ -678,7 +678,7 @@ export class VectorLayer extends AbstractLayer implements IVectorLayer { syncContext, source, }); - await this._syncIsEditable({ syncContext }); + await this._syncSupportsFeatureEditing({ syncContext, source }); if ( !sourceResult.featureCollection || !sourceResult.featureCollection.features.length || @@ -696,12 +696,18 @@ export class VectorLayer extends AbstractLayer implements IVectorLayer { } } - async _syncIsEditable({ syncContext }: { syncContext: DataRequestContext }) { + async _syncSupportsFeatureEditing({ + syncContext, + source, + }: { + syncContext: DataRequestContext; + source: IVectorSource; + }) { if (syncContext.dataFilters.isReadOnly) { return; } const { startLoading, stopLoading, onLoadError } = syncContext; - const dataRequestId = IS_EDITABLE_REQUEST_ID; + const dataRequestId = SUPPORTS_FEATURE_EDITING_REQUEST_ID; const requestToken = Symbol(`layer-${this.getId()}-${dataRequestId}`); const prevDataRequest = this.getDataRequest(dataRequestId); if (prevDataRequest) { @@ -709,8 +715,8 @@ export class VectorLayer extends AbstractLayer implements IVectorLayer { } try { startLoading(dataRequestId, requestToken); - const isEditable = await this.getSource().loadIsEditable(); - stopLoading(dataRequestId, requestToken, { isEditable }); + const supportsFeatureEditing = await source.supportsFeatureEditing(); + stopLoading(dataRequestId, requestToken, { supportsFeatureEditing }); } catch (error) { onLoadError(dataRequestId, requestToken, error.message); throw error; diff --git a/x-pack/plugins/maps/public/classes/sources/es_search_source/es_search_source.tsx b/x-pack/plugins/maps/public/classes/sources/es_search_source/es_search_source.tsx index a3f8ce8e51edea..a51e291574b703 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_search_source/es_search_source.tsx +++ b/x-pack/plugins/maps/public/classes/sources/es_search_source/es_search_source.tsx @@ -389,7 +389,7 @@ export class ESSearchSource extends AbstractESSource implements ITiledSingleLaye return !!(scalingType === SCALING_TYPES.TOP_HITS && topHitsSplitField); } - async loadIsEditable(): Promise { + async supportsFeatureEditing(): Promise { if (!getMapAppConfig().enableDrawingFeature) { return false; } diff --git a/x-pack/plugins/maps/public/connected_components/right_side_controls/layer_control/layer_toc/toc_entry/toc_entry_actions_popover/toc_entry_actions_popover.tsx b/x-pack/plugins/maps/public/connected_components/right_side_controls/layer_control/layer_toc/toc_entry/toc_entry_actions_popover/toc_entry_actions_popover.tsx index 526c157ceaabcf..c25c8ed921d317 100644 --- a/x-pack/plugins/maps/public/connected_components/right_side_controls/layer_control/layer_toc/toc_entry/toc_entry_actions_popover/toc_entry_actions_popover.tsx +++ b/x-pack/plugins/maps/public/connected_components/right_side_controls/layer_control/layer_toc/toc_entry/toc_entry_actions_popover/toc_entry_actions_popover.tsx @@ -57,10 +57,10 @@ export class TOCEntryActionsPopover extends Component { } componentDidUpdate() { - this._checkLayerEditable(); + this._loadFeatureEditing(); } - async _checkLayerEditable() { + async _loadFeatureEditing() { if (!(this.props.layer instanceof VectorLayer)) { return; } From b990f5a3b22abcec718293209083ea2c8b2e70ad Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Thu, 17 Jun 2021 08:49:15 -0600 Subject: [PATCH 2/4] update vector_source --- .../public/classes/sources/vector_source/vector_source.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/maps/public/classes/sources/vector_source/vector_source.tsx b/x-pack/plugins/maps/public/classes/sources/vector_source/vector_source.tsx index 84aad44c4fdbbf..1194d571e344bb 100644 --- a/x-pack/plugins/maps/public/classes/sources/vector_source/vector_source.tsx +++ b/x-pack/plugins/maps/public/classes/sources/vector_source/vector_source.tsx @@ -66,7 +66,7 @@ export interface IVectorSource extends ISource { getSupportedShapeTypes(): Promise; isBoundsAware(): boolean; getSourceTooltipContent(sourceDataRequest?: DataRequest): SourceTooltipConfig; - loadIsEditable(): Promise; + supportsFeatureEditing(): Promise; addFeature(geometry: Geometry | Position[]): Promise; } @@ -160,7 +160,7 @@ export class AbstractVectorSource extends AbstractSource implements IVectorSourc throw new Error('Should implement VectorSource#addFeature'); } - async loadIsEditable(): Promise { + async supportsFeatureEditing(): Promise { return false; } } From 147f1c8dc3d98399d50d8d72d727c0b517f26a7e Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Thu, 17 Jun 2021 08:52:29 -0600 Subject: [PATCH 3/4] mvt_single_layer_vector_source udpates --- .../mvt_single_layer_vector_source.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/maps/public/classes/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source.tsx b/x-pack/plugins/maps/public/classes/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source.tsx index 2311774691acbd..d58e71db2a9abd 100644 --- a/x-pack/plugins/maps/public/classes/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source.tsx +++ b/x-pack/plugins/maps/public/classes/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source.tsx @@ -228,7 +228,7 @@ export class MVTSingleLayerVectorSource return tooltips; } - async loadIsEditable(): Promise { + async supportsFeatureEditing(): Promise { return false; } } From 48c8dd4fd1332a9da45a5083f1ed5adaf648f727 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Thu, 17 Jun 2021 16:18:41 -0600 Subject: [PATCH 4/4] review feedback --- .../toc_entry_actions_popover.tsx | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/x-pack/plugins/maps/public/connected_components/right_side_controls/layer_control/layer_toc/toc_entry/toc_entry_actions_popover/toc_entry_actions_popover.tsx b/x-pack/plugins/maps/public/connected_components/right_side_controls/layer_control/layer_toc/toc_entry/toc_entry_actions_popover/toc_entry_actions_popover.tsx index c25c8ed921d317..ab7a54be37404c 100644 --- a/x-pack/plugins/maps/public/connected_components/right_side_controls/layer_control/layer_toc/toc_entry/toc_entry_actions_popover/toc_entry_actions_popover.tsx +++ b/x-pack/plugins/maps/public/connected_components/right_side_controls/layer_control/layer_toc/toc_entry/toc_entry_actions_popover/toc_entry_actions_popover.tsx @@ -41,11 +41,15 @@ export interface Props { interface State { isPopoverOpen: boolean; supportsFeatureEditing: boolean; - canEditFeatures: boolean; + isFeatureEditingEnabled: boolean; } export class TOCEntryActionsPopover extends Component { - state: State = { isPopoverOpen: false, supportsFeatureEditing: false, canEditFeatures: false }; + state: State = { + isPopoverOpen: false, + supportsFeatureEditing: false, + isFeatureEditingEnabled: false, + }; private _isMounted = false; componentDidMount() { @@ -65,18 +69,18 @@ export class TOCEntryActionsPopover extends Component { return; } const supportsFeatureEditing = this.props.layer.supportsFeatureEditing(); - const canEditFeatures = await this._getCanEditFeatures(); + const isFeatureEditingEnabled = await this._getIsFeatureEditingEnabled(); if ( !this._isMounted || (supportsFeatureEditing === this.state.supportsFeatureEditing && - canEditFeatures === this.state.canEditFeatures) + isFeatureEditingEnabled === this.state.isFeatureEditingEnabled) ) { return; } - this.setState({ supportsFeatureEditing, canEditFeatures }); + this.setState({ supportsFeatureEditing, isFeatureEditingEnabled }); } - async _getCanEditFeatures(): Promise { + async _getIsFeatureEditingEnabled(): Promise { const vectorLayer = this.props.layer as VectorLayer; const layerSource = await this.props.layer.getSource(); if (!(layerSource instanceof ESSearchSource)) { @@ -160,13 +164,13 @@ export class TOCEntryActionsPopover extends Component { name: EDIT_FEATURES_LABEL, icon: , 'data-test-subj': 'editLayerButton', - toolTipContent: this.state.canEditFeatures + toolTipContent: this.state.isFeatureEditingEnabled ? null : i18n.translate('xpack.maps.layerTocActions.editLayerTooltip', { defaultMessage: 'Edit features only supported for document layers without clustering, joins, or time filtering', }), - disabled: !this.state.canEditFeatures, + disabled: !this.state.isFeatureEditingEnabled, onClick: async () => { this._closePopover(); const supportedShapeTypes = await (this.props.layer.getSource() as ESSearchSource).getSupportedShapeTypes();