From 784862c56536267708e94eb7f4f9fa8ecde44bd3 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Mon, 24 Aug 2020 16:37:32 -0600 Subject: [PATCH 1/4] [Maps] fix IVectorLayer.getStyle typing --- .../classes/layers/vector_layer/vector_layer.d.ts | 3 ++- .../vector/properties/dynamic_style_property.tsx | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.d.ts b/x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.d.ts index ad4479d3a324b..65fa1290ed842 100644 --- a/x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.d.ts +++ b/x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.d.ts @@ -16,6 +16,7 @@ import { import { ILayer } from '../layer'; import { IJoin } from '../../joins/join'; import { IVectorStyle } from '../../styles/vector/vector_style'; +import { HeatmapStyle } from '../../styles/heatmap/heatmap_style'; import { IField } from '../../fields/field'; import { DataRequestContext } from '../../../actions'; import { ITooltipProperty } from '../../tooltips/tooltip_property'; @@ -32,7 +33,7 @@ export interface IVectorLayer extends ILayer { getJoins(): IJoin[]; getValidJoins(): IJoin[]; getSource(): IVectorSource; - getStyle(): IVectorStyle; + getStyle(): IVectorStyle | HeatmapStyle; getFeatureById(id: string | number): Feature | null; getPropertiesForTooltip(properties: GeoJsonProperties): Promise; hasJoins(): boolean; diff --git a/x-pack/plugins/maps/public/classes/styles/vector/properties/dynamic_style_property.tsx b/x-pack/plugins/maps/public/classes/styles/vector/properties/dynamic_style_property.tsx index 47659e055936e..a3d8b26385ba4 100644 --- a/x-pack/plugins/maps/public/classes/styles/vector/properties/dynamic_style_property.tsx +++ b/x-pack/plugins/maps/public/classes/styles/vector/properties/dynamic_style_property.tsx @@ -11,6 +11,7 @@ import { AbstractStyleProperty, IStyleProperty } from './style_property'; import { DEFAULT_SIGMA } from '../vector_style_defaults'; import { FIELD_ORIGIN, + LAYER_STYLE_TYPE, MB_LOOKUP_FUNCTION, SOURCE_META_DATA_REQUEST_ID, STYLE_TYPE, @@ -27,6 +28,7 @@ import { import { IField } from '../../../fields/field'; import { IVectorLayer } from '../../../layers/vector_layer/vector_layer'; import { IJoin } from '../../../joins/join'; +import { IVectorStyle } from '../vector_style'; export interface IDynamicStyleProperty extends IStyleProperty { getFieldMetaOptions(): FieldMetaOptions; @@ -89,7 +91,10 @@ export class DynamicStyleProperty extends AbstractStyleProperty getRangeFieldMeta() { const style = this._layer.getStyle(); - const styleMeta = style.getStyleMeta(); + if (style.getType() !== LAYER_STYLE_TYPE.VECTOR) { + return null; + } + const styleMeta = (style as IVectorStyle).getStyleMeta(); const fieldName = this.getFieldName(); const rangeFieldMetaFromLocalFeatures = styleMeta.getRangeFieldMetaDescriptor(fieldName); @@ -114,7 +119,10 @@ export class DynamicStyleProperty extends AbstractStyleProperty getCategoryFieldMeta() { const style = this._layer.getStyle(); - const styleMeta = style.getStyleMeta(); + if (style.getType() !== LAYER_STYLE_TYPE.VECTOR) { + return null; + } + const styleMeta = (style as IVectorStyle).getStyleMeta(); const fieldName = this.getFieldName(); const categoryFieldMetaFromLocalFeatures = styleMeta.getCategoryFieldMetaDescriptor(fieldName); From 133d26356e663af9b5af6094b937632a86955092 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Mon, 24 Aug 2020 16:39:31 -0600 Subject: [PATCH 2/4] update typing in VectorLayer type definition --- .../maps/public/classes/layers/vector_layer/vector_layer.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.d.ts b/x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.d.ts index 65fa1290ed842..745039d23f9ef 100644 --- a/x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.d.ts +++ b/x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.d.ts @@ -80,7 +80,7 @@ export class VectorLayer extends AbstractLayer implements IVectorLayer { _setMbPointsProperties(mbMap: unknown, mvtSourceLayer?: string): void; _setMbLinePolygonProperties(mbMap: unknown, mvtSourceLayer?: string): void; getSource(): IVectorSource; - getStyle(): IVectorStyle; + getStyle(): IVectorStyle | HeatmapStyle; getFeatureById(id: string | number): Feature | null; getPropertiesForTooltip(properties: GeoJsonProperties): Promise; hasJoins(): boolean; From f8dbc9d973e8852f86f9fee6173fbcca59c22549 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Mon, 24 Aug 2020 17:24:59 -0600 Subject: [PATCH 3/4] fix unit tests --- .../classes/styles/vector/properties/__tests__/test_util.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/maps/public/classes/styles/vector/properties/__tests__/test_util.ts b/x-pack/plugins/maps/public/classes/styles/vector/properties/__tests__/test_util.ts index 3f6edc81e30ef..a2dfdc94d8058 100644 --- a/x-pack/plugins/maps/public/classes/styles/vector/properties/__tests__/test_util.ts +++ b/x-pack/plugins/maps/public/classes/styles/vector/properties/__tests__/test_util.ts @@ -5,7 +5,7 @@ */ // eslint-disable-next-line max-classes-per-file -import { FIELD_ORIGIN } from '../../../../../../common/constants'; +import { FIELD_ORIGIN, LAYER_STYLE_TYPE } from '../../../../../../common/constants'; import { StyleMeta } from '../../style_meta'; import { CategoryFieldMeta, @@ -44,7 +44,7 @@ export class MockStyle implements IStyle { } getType() { - return 'mockStyle'; + return LAYER_STYLE_TYPE.VECTOR; } getStyleMeta(): StyleMeta { From de6db094ebfaa181af714edc7f0d07a16b5e3321 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Tue, 25 Aug 2020 13:01:17 -0600 Subject: [PATCH 4/4] review feedback --- .../classes/layers/vector_layer/vector_layer.d.ts | 3 --- .../vector/properties/dynamic_style_property.tsx | 15 ++++----------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.d.ts b/x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.d.ts index 745039d23f9ef..fa614ae87b290 100644 --- a/x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.d.ts +++ b/x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.d.ts @@ -16,7 +16,6 @@ import { import { ILayer } from '../layer'; import { IJoin } from '../../joins/join'; import { IVectorStyle } from '../../styles/vector/vector_style'; -import { HeatmapStyle } from '../../styles/heatmap/heatmap_style'; import { IField } from '../../fields/field'; import { DataRequestContext } from '../../../actions'; import { ITooltipProperty } from '../../tooltips/tooltip_property'; @@ -33,7 +32,6 @@ export interface IVectorLayer extends ILayer { getJoins(): IJoin[]; getValidJoins(): IJoin[]; getSource(): IVectorSource; - getStyle(): IVectorStyle | HeatmapStyle; getFeatureById(id: string | number): Feature | null; getPropertiesForTooltip(properties: GeoJsonProperties): Promise; hasJoins(): boolean; @@ -80,7 +78,6 @@ export class VectorLayer extends AbstractLayer implements IVectorLayer { _setMbPointsProperties(mbMap: unknown, mvtSourceLayer?: string): void; _setMbLinePolygonProperties(mbMap: unknown, mvtSourceLayer?: string): void; getSource(): IVectorSource; - getStyle(): IVectorStyle | HeatmapStyle; getFeatureById(id: string | number): Feature | null; getPropertiesForTooltip(properties: GeoJsonProperties): Promise; hasJoins(): boolean; diff --git a/x-pack/plugins/maps/public/classes/styles/vector/properties/dynamic_style_property.tsx b/x-pack/plugins/maps/public/classes/styles/vector/properties/dynamic_style_property.tsx index a3d8b26385ba4..826acd41e27a9 100644 --- a/x-pack/plugins/maps/public/classes/styles/vector/properties/dynamic_style_property.tsx +++ b/x-pack/plugins/maps/public/classes/styles/vector/properties/dynamic_style_property.tsx @@ -11,7 +11,6 @@ import { AbstractStyleProperty, IStyleProperty } from './style_property'; import { DEFAULT_SIGMA } from '../vector_style_defaults'; import { FIELD_ORIGIN, - LAYER_STYLE_TYPE, MB_LOOKUP_FUNCTION, SOURCE_META_DATA_REQUEST_ID, STYLE_TYPE, @@ -90,11 +89,8 @@ export class DynamicStyleProperty extends AbstractStyleProperty } getRangeFieldMeta() { - const style = this._layer.getStyle(); - if (style.getType() !== LAYER_STYLE_TYPE.VECTOR) { - return null; - } - const styleMeta = (style as IVectorStyle).getStyleMeta(); + const style = this._layer.getStyle() as IVectorStyle; + const styleMeta = style.getStyleMeta(); const fieldName = this.getFieldName(); const rangeFieldMetaFromLocalFeatures = styleMeta.getRangeFieldMetaDescriptor(fieldName); @@ -118,11 +114,8 @@ export class DynamicStyleProperty extends AbstractStyleProperty } getCategoryFieldMeta() { - const style = this._layer.getStyle(); - if (style.getType() !== LAYER_STYLE_TYPE.VECTOR) { - return null; - } - const styleMeta = (style as IVectorStyle).getStyleMeta(); + const style = this._layer.getStyle() as IVectorStyle; + const styleMeta = style.getStyleMeta(); const fieldName = this.getFieldName(); const categoryFieldMetaFromLocalFeatures = styleMeta.getCategoryFieldMetaDescriptor(fieldName);