From f54473420f7e0831be5dd990f0559c1db5deb66b Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 18 Feb 2020 15:29:17 -0500 Subject: [PATCH 01/35] boilerplate --- .../components/color/color_map_select.js | 59 ++++++++++++-- .../components/color/dynamic_color_form.js | 76 ++++++++++++++----- .../properties/dynamic_color_property.test.js | 27 +++++++ 3 files changed, 135 insertions(+), 27 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js index e8d5754ef4206..8d487fe7f5e20 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js @@ -6,10 +6,11 @@ import React, { Component, Fragment } from 'react'; -import { EuiSuperSelect, EuiSpacer } from '@elastic/eui'; +import { EuiSuperSelect, EuiSpacer, EuiSelect, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; import { ColorStopsOrdinal } from './color_stops_ordinal'; import { COLOR_MAP_TYPE } from '../../../../../../common/constants'; import { ColorStopsCategorical } from './color_stops_categorical'; +import { i18n } from '@kbn/i18n'; const CUSTOM_COLOR_MAP = 'CUSTOM_COLOR_MAP'; @@ -27,6 +28,45 @@ export class ColorMapSelect extends Component { }; } + _renderColorMapToggle() { + if (!this.props.showColorMapTypeToggle) { + return null; + } + const options = [ + { + value: COLOR_MAP_TYPE.ORDINAL, + text: i18n.translate('xpack.maps.styles.dynamicColorSelect.quantitativeLabel', { + defaultMessage: 'Quantitative', + }), + }, + { + value: COLOR_MAP_TYPE.CATEGORICAL, + text: i18n.translate('xpack.maps.styles.dynamicColorSelect.qualitativeLavel', { + defaultMessage: 'Qualitative', + }), + }, + ]; + + const selectedValue = this.props.styleProperty.isOrdinal() + ? COLOR_MAP_TYPE.ORDINAL + : COLOR_MAP_TYPE.CATEGORICAL; + + return ( + + ); + } + _onColorMapSelect = selectedValue => { const useCustomColorMap = selectedValue === CUSTOM_COLOR_MAP; this.props.onChange({ @@ -100,12 +140,17 @@ export class ColorMapSelect extends Component { return ( - + + {this._renderColorMapToggle()} + + + + {this._renderColorStopsInput()} ); diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/dynamic_color_form.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/dynamic_color_form.js index af5e5b37f5467..04ba358fb7bf3 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/dynamic_color_form.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/dynamic_color_form.js @@ -13,6 +13,12 @@ import { CATEGORICAL_DATA_TYPES, COLOR_MAP_TYPE } from '../../../../../../common import { COLOR_GRADIENTS, COLOR_PALETTES } from '../../../color_utils'; import { i18n } from '@kbn/i18n'; +function getDefaultColorMapType(fieldType) { + return CATEGORICAL_DATA_TYPES.includes(fieldType) + ? COLOR_MAP_TYPE.CATEGORICAL + : COLOR_MAP_TYPE.ORDINAL; +} + export function DynamicColorForm({ fields, onDynamicStyleChange, @@ -40,21 +46,47 @@ export function DynamicColorForm({ }; const onFieldChange = async ({ field }) => { - const { name, origin, type } = field; + const { name, origin, type: fieldType } = field; + const defaultColorMapType = getDefaultColorMapType(fieldType); onDynamicStyleChange(styleProperty.getStyleName(), { ...styleOptions, field: { name, origin }, - type: CATEGORICAL_DATA_TYPES.includes(type) - ? COLOR_MAP_TYPE.CATEGORICAL - : COLOR_MAP_TYPE.ORDINAL, + type: defaultColorMapType, + }); + }; + + const onColorMapTypeChange = async e => { + const colorMapType = e.target.value; + onDynamicStyleChange(styleProperty.getStyleName(), { + ...styleOptions, + type: colorMapType, + }); + }; + + const getField = () => { + const fieldName = styleProperty.getFieldName(); + if (!fieldName) { + return null; + } + + return fields.find(field => { + return field.name === fieldName; }); }; const renderColorMapSelect = () => { - if (!styleOptions.field || !styleOptions.field.name) { + // if (!styleOptions.field || !styleOptions.field.name) { + // return null; + // } + + const field = getField(); + + if (!field) { return null; } + const showColorMapTypeToggle = !CATEGORICAL_DATA_TYPES.includes(field.type); + if (styleProperty.isOrdinal()) { return ( + ); + } else if (styleProperty.isCategorical()) { + return ( + ); } - - return ( - - ); }; return ( diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.test.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.test.js index 6b08fc2a105c3..7a03d8a7bed20 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.test.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.test.js @@ -222,3 +222,30 @@ test('Should pluck the categorical style-meta from fieldmeta', async () => { ], }); }); + +test('Should read out ordinal/categorical correctly', async () => { + const categoricalColorStyle = makeProperty({ + type: COLOR_MAP_TYPE.CATEGORICAL, + colorCategory: 'palette_0', + getCategoricalFieldMeta, + }); + + expect(categoricalColorStyle.isOrdinal()).toEqual(false); + expect(categoricalColorStyle.isCategorical()).toEqual(true); + + const ordinalColorStyle = makeProperty({ + type: undefined, + color: 'Blues', + }); + + expect(ordinalColorStyle.isOrdinal()).toEqual(true); + expect(ordinalColorStyle.isCategorical()).toEqual(false); + + const ordinalColorStyle2 = makeProperty({ + type: COLOR_MAP_TYPE.ORDINAL, + colorCategory: 'palette_0', + }); + + expect(ordinalColorStyle2.isOrdinal()).toEqual(true); + expect(ordinalColorStyle2.isCategorical()).toEqual(false); +}); From 4be903f038feb59d76cf4a909a0e1fe720a4f44b Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 18 Feb 2020 16:20:26 -0500 Subject: [PATCH 02/35] styling --- .../components/color/color_map_select.js | 52 ++++++++++++------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js index 8d487fe7f5e20..3a40ac0ffc3d4 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js @@ -6,7 +6,7 @@ import React, { Component, Fragment } from 'react'; -import { EuiSuperSelect, EuiSpacer, EuiSelect, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; +import { EuiSpacer, EuiSelect, EuiSuperSelect, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; import { ColorStopsOrdinal } from './color_stops_ordinal'; import { COLOR_MAP_TYPE } from '../../../../../../common/constants'; import { ColorStopsCategorical } from './color_stops_categorical'; @@ -29,9 +29,6 @@ export class ColorMapSelect extends Component { } _renderColorMapToggle() { - if (!this.props.showColorMapTypeToggle) { - return null; - } const options = [ { value: COLOR_MAP_TYPE.ORDINAL, @@ -91,10 +88,6 @@ export class ColorMapSelect extends Component { }; _renderColorStopsInput() { - if (!this.props.useCustomColorMap) { - return null; - } - if (this.props.colorMapType === COLOR_MAP_TYPE.ORDINAL) { return ( @@ -120,7 +113,7 @@ export class ColorMapSelect extends Component { ); } - render() { + _renderColorMapSelections() { const colorMapOptionsWithCustom = [ { value: CUSTOM_COLOR_MAP, @@ -138,20 +131,43 @@ export class ColorMapSelect extends Component { : ''; } + let toggle; + if (this.props.showColorMapTypeToggle) { + toggle = {this._renderColorMapToggle()}; + } else { + toggle = ; + } + return ( - - {this._renderColorMapToggle()} + {toggle} + + + + + ); + } + + render() { + return ( + + + + + {this._renderColorMapSelections()} + + - + + {this._renderColorStopsInput()} + - {this._renderColorStopsInput()} ); } From 894a5baa4540137c1e0b3119d88fb9dedc1354f6 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 18 Feb 2020 16:23:58 -0500 Subject: [PATCH 03/35] fix --- .../layers/styles/vector/components/color/color_map_select.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js index 3a40ac0ffc3d4..cd5a799f27128 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js @@ -88,6 +88,10 @@ export class ColorMapSelect extends Component { }; _renderColorStopsInput() { + if (!this.props.useCustomColorMap) { + return null; + } + if (this.props.colorMapType === COLOR_MAP_TYPE.ORDINAL) { return ( From 3f798be471f562ee0efc662165691dc8c900b9ec Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 20 Feb 2020 11:39:28 -0500 Subject: [PATCH 04/35] remove cruft --- .../styles/vector/components/color/dynamic_color_form.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/dynamic_color_form.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/dynamic_color_form.js index 04ba358fb7bf3..1d53fc05f9dec 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/dynamic_color_form.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/dynamic_color_form.js @@ -75,12 +75,7 @@ export function DynamicColorForm({ }; const renderColorMapSelect = () => { - // if (!styleOptions.field || !styleOptions.field.name) { - // return null; - // } - const field = getField(); - if (!field) { return null; } From cc0738dfc28552aa9292bab967a1df1e249db236 Mon Sep 17 00:00:00 2001 From: miukimiu Date: Thu, 20 Feb 2020 16:56:30 +0000 Subject: [PATCH 05/35] Improving color map select styles --- .../components/color/color_map_select.js | 50 ++++++++----------- 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js index cd5a799f27128..eb6bb35cc0c14 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js @@ -94,26 +94,20 @@ export class ColorMapSelect extends Component { if (this.props.colorMapType === COLOR_MAP_TYPE.ORDINAL) { return ( - - - - + ); } return ( - - - - + ); } @@ -137,40 +131,36 @@ export class ColorMapSelect extends Component { let toggle; if (this.props.showColorMapTypeToggle) { - toggle = {this._renderColorMapToggle()}; + toggle = {this._renderColorMapToggle()}; } else { toggle = ; } return ( - + {toggle} - + ); } render() { return ( - - - - {this._renderColorMapSelections()} - - - - - {this._renderColorStopsInput()} - - + {this._renderColorMapSelections()} + + + + + {this._renderColorStopsInput()} ); From 67fa1b826a48eefa27d1102aa0d956c81730aadb Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Sun, 23 Feb 2020 17:04:42 -0500 Subject: [PATCH 06/35] enable for icon-fields --- .../layers/styles/vector/components/vector_style_editor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js index 7daf85b68dd8e..5b9d93ea4c129 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js @@ -335,7 +335,7 @@ export class VectorStyleEditor extends Component { onStaticStyleChange={this._onStaticStyleChange} onDynamicStyleChange={this._onDynamicStyleChange} styleProperty={this.props.styleProperties[VECTOR_STYLES.ICON]} - fields={this.state.categoricalFields} + fields={this._getOrdinalAndCategoricalFields()} defaultStaticStyleOptions={ this.state.defaultStaticProperties[VECTOR_STYLES.ICON].options } From 09af833b914f13cf1636b13cc34b363d112d50b3 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Sun, 23 Feb 2020 17:14:22 -0500 Subject: [PATCH 07/35] remove unused --- .../vector/components/vector_style_editor.js | 22 +++++-------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js index 5b9d93ea4c129..1fc6823991b0e 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js @@ -31,7 +31,6 @@ export class VectorStyleEditor extends Component { state = { dateFields: [], numberFields: [], - categoricalFields: [], fields: [], defaultDynamicProperties: getDefaultDynamicProperties(), defaultStaticProperties: getDefaultStaticProperties(), @@ -78,13 +77,6 @@ export class VectorStyleEditor extends Component { this.setState({ numberFields: numberFieldsArray }); } - const categoricalFields = await this.props.layer.getCategoricalFields(); - const categoricalFieldMeta = categoricalFields.map(getFieldMeta); - const categoricalFieldsArray = await Promise.all(categoricalFieldMeta); - if (this._isMounted && !_.isEqual(categoricalFieldsArray, this.state.categoricalFields)) { - this.setState({ categoricalFields: categoricalFieldsArray }); - } - const fields = await this.props.layer.getFields(); const fieldPromises = fields.map(getFieldMeta); const fieldsArray = await Promise.all(fieldPromises); @@ -118,10 +110,6 @@ export class VectorStyleEditor extends Component { return [...this.state.dateFields, ...this.state.numberFields]; } - _getOrdinalAndCategoricalFields() { - return [...this.state.dateFields, ...this.state.numberFields, ...this.state.categoricalFields]; - } - _handleSelectedFeatureChange = selectedFeature => { this.setState({ selectedFeature }); }; @@ -172,7 +160,7 @@ export class VectorStyleEditor extends Component { onStaticStyleChange={this._onStaticStyleChange} onDynamicStyleChange={this._onDynamicStyleChange} styleProperty={this.props.styleProperties[VECTOR_STYLES.FILL_COLOR]} - fields={this._getOrdinalAndCategoricalFields()} + fields={this.state.fields} defaultStaticStyleOptions={ this.state.defaultStaticProperties[VECTOR_STYLES.FILL_COLOR].options } @@ -193,7 +181,7 @@ export class VectorStyleEditor extends Component { onStaticStyleChange={this._onStaticStyleChange} onDynamicStyleChange={this._onDynamicStyleChange} styleProperty={this.props.styleProperties[VECTOR_STYLES.LINE_COLOR]} - fields={this._getOrdinalAndCategoricalFields()} + fields={this.state.fields} defaultStaticStyleOptions={ this.state.defaultStaticProperties[VECTOR_STYLES.LINE_COLOR].options } @@ -249,7 +237,7 @@ export class VectorStyleEditor extends Component { onStaticStyleChange={this._onStaticStyleChange} onDynamicStyleChange={this._onDynamicStyleChange} styleProperty={this.props.styleProperties[VECTOR_STYLES.LABEL_COLOR]} - fields={this._getOrdinalAndCategoricalFields()} + fields={this.state.fields} defaultStaticStyleOptions={ this.state.defaultStaticProperties[VECTOR_STYLES.LABEL_COLOR].options } @@ -282,7 +270,7 @@ export class VectorStyleEditor extends Component { onStaticStyleChange={this._onStaticStyleChange} onDynamicStyleChange={this._onDynamicStyleChange} styleProperty={this.props.styleProperties[VECTOR_STYLES.LABEL_BORDER_COLOR]} - fields={this._getOrdinalAndCategoricalFields()} + fields={this.state.fields} defaultStaticStyleOptions={ this.state.defaultStaticProperties[VECTOR_STYLES.LABEL_BORDER_COLOR].options } @@ -335,7 +323,7 @@ export class VectorStyleEditor extends Component { onStaticStyleChange={this._onStaticStyleChange} onDynamicStyleChange={this._onDynamicStyleChange} styleProperty={this.props.styleProperties[VECTOR_STYLES.ICON]} - fields={this._getOrdinalAndCategoricalFields()} + fields={this.state.fields} defaultStaticStyleOptions={ this.state.defaultStaticProperties[VECTOR_STYLES.ICON].options } From 42d7cd3fca24ecb26cb81a6b36cf5a463fe88f7e Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Sun, 23 Feb 2020 17:30:30 -0500 Subject: [PATCH 08/35] only include styleable fields --- .../legacy/plugins/maps/common/constants.ts | 1 + .../plugins/maps/public/layers/layer.js | 4 -- .../es_search_source/es_search_source.js | 22 ---------- .../public/layers/sources/vector_source.js | 4 -- .../vector/components/vector_style_editor.js | 42 +++++++++++-------- .../maps/public/layers/vector_layer.js | 4 -- 6 files changed, 25 insertions(+), 52 deletions(-) diff --git a/x-pack/legacy/plugins/maps/common/constants.ts b/x-pack/legacy/plugins/maps/common/constants.ts index ab9a696fa3a17..c44720c57ce66 100644 --- a/x-pack/legacy/plugins/maps/common/constants.ts +++ b/x-pack/legacy/plugins/maps/common/constants.ts @@ -151,6 +151,7 @@ export const COLOR_MAP_TYPE = { export const COLOR_PALETTE_MAX_SIZE = 10; export const CATEGORICAL_DATA_TYPES = ['string', 'ip', 'boolean']; +export const ORDINAL_DATA_TYPES = ['number', 'date']; export const SYMBOLIZE_AS_TYPES = { CIRCLE: 'circle', diff --git a/x-pack/legacy/plugins/maps/public/layers/layer.js b/x-pack/legacy/plugins/maps/public/layers/layer.js index b76f1ebce15d2..47252b3da68a7 100644 --- a/x-pack/legacy/plugins/maps/public/layers/layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/layer.js @@ -340,10 +340,6 @@ export class AbstractLayer { return []; } - async getCategoricalFields() { - return []; - } - async getFields() { return []; } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js index 288dd117da137..f4c223e262f50 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js @@ -19,7 +19,6 @@ import { ES_GEO_FIELD_TYPE, DEFAULT_MAX_BUCKETS_LIMIT, SORT_ORDER, - CATEGORICAL_DATA_TYPES, } from '../../../../common/constants'; import { i18n } from '@kbn/i18n'; import { getDataSourceLabel } from '../../../../common/i18n_getters'; @@ -181,27 +180,6 @@ export class ESSearchSource extends AbstractESSource { } } - async getCategoricalFields() { - try { - const indexPattern = await this.getIndexPattern(); - - const aggFields = []; - CATEGORICAL_DATA_TYPES.forEach(dataType => { - indexPattern.fields.getByType(dataType).forEach(field => { - if (field.aggregatable) { - aggFields.push(field); - } - }); - }); - return aggFields.map(field => { - return this.createField({ fieldName: field.name }); - }); - } catch (error) { - //error surfaces in the LayerTOC UI - return []; - } - } - async getFields() { try { const indexPattern = await this.getIndexPattern(); diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.js index 3952aacf03b33..876d6df69034e 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.js @@ -123,10 +123,6 @@ export class AbstractVectorSource extends AbstractSource { return [...(await this.getDateFields()), ...(await this.getNumberFields())]; } - async getCategoricalFields() { - return []; - } - async getLeftJoinFields() { return []; } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js index 1fc6823991b0e..7cf80e1f792d6 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js @@ -26,12 +26,14 @@ import { VECTOR_SHAPE_TYPES } from '../../../sources/vector_feature_types'; import { i18n } from '@kbn/i18n'; import { EuiSpacer, EuiButtonGroup, EuiFormRow, EuiSwitch } from '@elastic/eui'; +import { CATEGORICAL_DATA_TYPES, ORDINAL_DATA_TYPES } from '../../../../../common/constants'; export class VectorStyleEditor extends Component { state = { dateFields: [], numberFields: [], fields: [], + styleableFields: [], defaultDynamicProperties: getDefaultDynamicProperties(), defaultStaticProperties: getDefaultStaticProperties(), supportedFeatures: undefined, @@ -63,26 +65,30 @@ export class VectorStyleEditor extends Component { }; }; - const dateFields = await this.props.layer.getDateFields(); - const dateFieldPromises = dateFields.map(getFieldMeta); - const dateFieldsArray = await Promise.all(dateFieldPromises); + //These are all fields (only used for text labeling) + const fields = await this.props.layer.getFields(); + const fieldPromises = fields.map(getFieldMeta); + const fieldsArrayAll = await Promise.all(fieldPromises); + if (this._isMounted && !_.isEqual(fieldsArrayAll, this.state.fields)) { + this.setState({ fields: fieldsArrayAll }); + } + + const styleableFields = fieldsArrayAll.filter(field => { + return CATEGORICAL_DATA_TYPES.includes(field.type) || ORDINAL_DATA_TYPES.includes(field.type); + }); + if (this._isMounted && !_.isEqual(styleableFields, this.state.styleableFields)) { + this.setState({ styleableFields: styleableFields }); + } + + const dateFieldsArray = styleableFields.filter(field => field.type === 'date'); if (this._isMounted && !_.isEqual(dateFieldsArray, this.state.dateFields)) { this.setState({ dateFields: dateFieldsArray }); } - const numberFields = await this.props.layer.getNumberFields(); - const numberFieldPromises = numberFields.map(getFieldMeta); - const numberFieldsArray = await Promise.all(numberFieldPromises); + const numberFieldsArray = styleableFields.filter(field => field.type === 'number'); if (this._isMounted && !_.isEqual(numberFieldsArray, this.state.numberFields)) { this.setState({ numberFields: numberFieldsArray }); } - - const fields = await this.props.layer.getFields(); - const fieldPromises = fields.map(getFieldMeta); - const fieldsArray = await Promise.all(fieldPromises); - if (this._isMounted && !_.isEqual(fieldsArray, this.state.fields)) { - this.setState({ fields: fieldsArray }); - } } async _loadSupportedFeatures() { @@ -160,7 +166,7 @@ export class VectorStyleEditor extends Component { onStaticStyleChange={this._onStaticStyleChange} onDynamicStyleChange={this._onDynamicStyleChange} styleProperty={this.props.styleProperties[VECTOR_STYLES.FILL_COLOR]} - fields={this.state.fields} + fields={this.state.styleableFields} defaultStaticStyleOptions={ this.state.defaultStaticProperties[VECTOR_STYLES.FILL_COLOR].options } @@ -181,7 +187,7 @@ export class VectorStyleEditor extends Component { onStaticStyleChange={this._onStaticStyleChange} onDynamicStyleChange={this._onDynamicStyleChange} styleProperty={this.props.styleProperties[VECTOR_STYLES.LINE_COLOR]} - fields={this.state.fields} + fields={this.state.styleableFields} defaultStaticStyleOptions={ this.state.defaultStaticProperties[VECTOR_STYLES.LINE_COLOR].options } @@ -237,7 +243,7 @@ export class VectorStyleEditor extends Component { onStaticStyleChange={this._onStaticStyleChange} onDynamicStyleChange={this._onDynamicStyleChange} styleProperty={this.props.styleProperties[VECTOR_STYLES.LABEL_COLOR]} - fields={this.state.fields} + fields={this.state.styleableFields} defaultStaticStyleOptions={ this.state.defaultStaticProperties[VECTOR_STYLES.LABEL_COLOR].options } @@ -270,7 +276,7 @@ export class VectorStyleEditor extends Component { onStaticStyleChange={this._onStaticStyleChange} onDynamicStyleChange={this._onDynamicStyleChange} styleProperty={this.props.styleProperties[VECTOR_STYLES.LABEL_BORDER_COLOR]} - fields={this.state.fields} + fields={this.state.styleableFields} defaultStaticStyleOptions={ this.state.defaultStaticProperties[VECTOR_STYLES.LABEL_BORDER_COLOR].options } @@ -323,7 +329,7 @@ export class VectorStyleEditor extends Component { onStaticStyleChange={this._onStaticStyleChange} onDynamicStyleChange={this._onDynamicStyleChange} styleProperty={this.props.styleProperties[VECTOR_STYLES.ICON]} - fields={this.state.fields} + fields={this.state.styleableFields} defaultStaticStyleOptions={ this.state.defaultStaticProperties[VECTOR_STYLES.ICON].options } diff --git a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js index 1698d52ea4406..cddf6377bf49a 100644 --- a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js @@ -205,10 +205,6 @@ export class VectorLayer extends AbstractLayer { return [...numberFieldOptions, ...this._getJoinFields()]; } - async getCategoricalFields() { - return await this._source.getCategoricalFields(); - } - async getFields() { const sourceFields = await this._source.getFields(); return [...sourceFields, ...this._getJoinFields()]; From 6cf2e349e3d638ce4d6407badc690890a3b204b0 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Sun, 23 Feb 2020 17:33:23 -0500 Subject: [PATCH 09/35] remove number fields --- x-pack/legacy/plugins/maps/public/layers/layer.js | 4 ---- .../maps/public/layers/sources/es_agg_source.js | 4 ---- .../sources/es_search_source/es_search_source.js | 11 ----------- .../maps/public/layers/sources/vector_source.js | 4 ---- .../legacy/plugins/maps/public/layers/vector_layer.js | 5 ----- 5 files changed, 28 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/layer.js b/x-pack/legacy/plugins/maps/public/layers/layer.js index 47252b3da68a7..83713a1d6cd58 100644 --- a/x-pack/legacy/plugins/maps/public/layers/layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/layer.js @@ -336,10 +336,6 @@ export class AbstractLayer { return []; } - async getNumberFields() { - return []; - } - async getFields() { return []; } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js index 967a3c41aec26..f53be93267fd2 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js @@ -102,10 +102,6 @@ export class AbstractESAggSource extends AbstractESSource { return this.getMetricFields().map(esAggMetric => esAggMetric.makeMetricAggConfig()); } - async getNumberFields() { - return this.getMetricFields(); - } - async filterAndFormatPropertiesToHtmlForMetricFields(properties) { const metricFields = this.getMetricFields(); const tooltipPropertiesPromises = []; diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js index f4c223e262f50..74abf3d10f1b0 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js @@ -158,17 +158,6 @@ export class ESSearchSource extends AbstractESSource { ); } - async getNumberFields() { - try { - const indexPattern = await this.getIndexPattern(); - return indexPattern.fields.getByType('number').map(field => { - return this.createField({ fieldName: field.name }); - }); - } catch (error) { - return []; - } - } - async getDateFields() { try { const indexPattern = await this.getIndexPattern(); diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.js index 876d6df69034e..3a42b84803dad 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.js @@ -115,10 +115,6 @@ export class AbstractVectorSource extends AbstractSource { return []; } - async getNumberFields() { - return []; - } - async getFields() { return [...(await this.getDateFields()), ...(await this.getNumberFields())]; } diff --git a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js index cddf6377bf49a..f6eaab297dfe4 100644 --- a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js @@ -200,11 +200,6 @@ export class VectorLayer extends AbstractLayer { return await this._source.getDateFields(); } - async getNumberFields() { - const numberFieldOptions = await this._source.getNumberFields(); - return [...numberFieldOptions, ...this._getJoinFields()]; - } - async getFields() { const sourceFields = await this._source.getFields(); return [...sourceFields, ...this._getJoinFields()]; From 42b1d88208a9d734fafd9143aae20d54cfc66026 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Sun, 23 Feb 2020 17:35:32 -0500 Subject: [PATCH 10/35] remove date fields --- x-pack/legacy/plugins/maps/public/layers/layer.js | 4 ---- .../sources/es_search_source/es_search_source.js | 11 ----------- .../maps/public/layers/sources/vector_source.js | 4 ---- .../legacy/plugins/maps/public/layers/vector_layer.js | 4 ---- 4 files changed, 23 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/layer.js b/x-pack/legacy/plugins/maps/public/layers/layer.js index 83713a1d6cd58..71e5d7b95e44f 100644 --- a/x-pack/legacy/plugins/maps/public/layers/layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/layer.js @@ -332,10 +332,6 @@ export class AbstractLayer { return []; } - async getDateFields() { - return []; - } - async getFields() { return []; } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js index 74abf3d10f1b0..66ed7e0ab4392 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js @@ -158,17 +158,6 @@ export class ESSearchSource extends AbstractESSource { ); } - async getDateFields() { - try { - const indexPattern = await this.getIndexPattern(); - return indexPattern.fields.getByType('date').map(field => { - return this.createField({ fieldName: field.name }); - }); - } catch (error) { - return []; - } - } - async getFields() { try { const indexPattern = await this.getIndexPattern(); diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.js index 3a42b84803dad..e397d19c7e66c 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.js @@ -111,10 +111,6 @@ export class AbstractVectorSource extends AbstractSource { return null; } - async getDateFields() { - return []; - } - async getFields() { return [...(await this.getDateFields()), ...(await this.getNumberFields())]; } diff --git a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js index f6eaab297dfe4..89284edad820e 100644 --- a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js @@ -196,10 +196,6 @@ export class VectorLayer extends AbstractLayer { return joinFields; } - async getDateFields() { - return await this._source.getDateFields(); - } - async getFields() { const sourceFields = await this._source.getFields(); return [...sourceFields, ...this._getJoinFields()]; From f927b75b8ebd2f2b67e562c42b84fd3e7bdd3f1a Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Sun, 23 Feb 2020 18:29:34 -0500 Subject: [PATCH 11/35] add tooltip --- .../components/color/color_map_select.js | 38 ++++++++++++++----- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js index eb6bb35cc0c14..ab16b1205c9d7 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js @@ -6,7 +6,14 @@ import React, { Component, Fragment } from 'react'; -import { EuiSpacer, EuiSelect, EuiSuperSelect, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; +import { + EuiSpacer, + EuiSelect, + EuiSuperSelect, + EuiFlexGroup, + EuiFlexItem, + EuiToolTip, +} from '@elastic/eui'; import { ColorStopsOrdinal } from './color_stops_ordinal'; import { COLOR_MAP_TYPE } from '../../../../../../common/constants'; import { ColorStopsCategorical } from './color_stops_categorical'; @@ -49,18 +56,29 @@ export class ColorMapSelect extends Component { : COLOR_MAP_TYPE.CATEGORICAL; return ( - + > + + ); } From 567c36b65a87630befd33ddd0744ea2c4197f15f Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Sun, 23 Feb 2020 18:30:04 -0500 Subject: [PATCH 12/35] change text --- .../layers/styles/vector/components/color/color_map_select.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js index ab16b1205c9d7..52cfbb10ff554 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js @@ -62,7 +62,7 @@ export class ColorMapSelect extends Component { 'xpack.maps.styles.dynamicColorSelect.qualitativeOrQuantitativeTooltip', { defaultMessage: - 'Choose `quantitative` to map the value as a number to a color on a range, or `qualitative` to map the value as a category to a color from a palette', + 'Choose `quantitative` to map the value as a number to a color on a range. Choose `qualitative` to map the value as a category to a color from a palette', } )} > From 988b567082cf63db42f961f170bb294ef1ba1bd0 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 26 Feb 2020 10:00:18 -0500 Subject: [PATCH 13/35] feedback --- .../public/layers/sources/vector_source.js | 2 +- .../components/color/color_map_select.js | 43 ++++++------------- 2 files changed, 14 insertions(+), 31 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.js index e397d19c7e66c..38acecdf654e3 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.js @@ -112,7 +112,7 @@ export class AbstractVectorSource extends AbstractSource { } async getFields() { - return [...(await this.getDateFields()), ...(await this.getNumberFields())]; + return []; } async getLeftJoinFields() { diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js index 52cfbb10ff554..24c525b8e596d 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js @@ -6,14 +6,7 @@ import React, { Component, Fragment } from 'react'; -import { - EuiSpacer, - EuiSelect, - EuiSuperSelect, - EuiFlexGroup, - EuiFlexItem, - EuiToolTip, -} from '@elastic/eui'; +import { EuiSpacer, EuiSelect, EuiSuperSelect, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; import { ColorStopsOrdinal } from './color_stops_ordinal'; import { COLOR_MAP_TYPE } from '../../../../../../common/constants'; import { ColorStopsCategorical } from './color_stops_categorical'; @@ -40,13 +33,13 @@ export class ColorMapSelect extends Component { { value: COLOR_MAP_TYPE.ORDINAL, text: i18n.translate('xpack.maps.styles.dynamicColorSelect.quantitativeLabel', { - defaultMessage: 'Quantitative', + defaultMessage: 'As number', }), }, { value: COLOR_MAP_TYPE.CATEGORICAL, - text: i18n.translate('xpack.maps.styles.dynamicColorSelect.qualitativeLavel', { - defaultMessage: 'Qualitative', + text: i18n.translate('xpack.maps.styles.dynamicColorSelect.qualitativeLabel', { + defaultMessage: 'As category', }), }, ]; @@ -56,29 +49,19 @@ export class ColorMapSelect extends Component { : COLOR_MAP_TYPE.CATEGORICAL; return ( - - - + compressed + /> ); } From 5d0937521b335262f290ffc95f440938628ce092 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 26 Feb 2020 10:05:39 -0500 Subject: [PATCH 14/35] remove restriction --- .../legacy/plugins/maps/public/layers/fields/es_doc_field.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js index 0b90dbe47c6e9..ea7641ed5e8dd 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js @@ -57,11 +57,6 @@ export class ESDocField extends AbstractField { async getCategoricalFieldMetaRequest() { const field = await this._getField(); - if (field.type !== 'string') { - //UX does not support categorical styling for number/date fields - return null; - } - const topTerms = { size: COLOR_PALETTE_MAX_SIZE - 1, //need additional color for the "other"-value }; From d6565ffd987a865f37003fc53f10d0c5c901aa04 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 26 Feb 2020 15:54:07 -0500 Subject: [PATCH 15/35] add unit test --- .../public/layers/sources/es_agg_source.js | 4 +++ .../layers/sources/es_term_source.test.js | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js index 1824a72f5d39c..c5e283cd131ea 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.js @@ -80,6 +80,10 @@ export class AbstractESAggSource extends AbstractESSource { return aggType !== AGG_TYPE.COUNT ? `${aggType} of ${fieldName}` : COUNT_PROP_LABEL; } + async getFields() { + return this.getMetricFields(); + } + getValueAggsDsl(indexPattern) { const valueAggsDsl = {}; this.getMetricFields() diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.test.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.test.js index 39cc301d458cb..60759e6d71c51 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.test.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.test.js @@ -5,6 +5,7 @@ */ import { ESTermSource, extractPropertiesMap } from './es_term_source'; +import _ from 'lodash'; jest.mock('ui/new_platform'); jest.mock('../vector_layer', () => {}); @@ -64,6 +65,30 @@ describe('getMetricFields', () => { expect(metrics[1].getName()).toEqual('__kbnjoin__count_groupby_myIndex.myTermField'); expect(await metrics[1].getLabel()).toEqual('Count of myIndex'); }); + + it('should match getFields since term_source is agg_source', async () => { + const source = new ESTermSource({ + indexPatternTitle: indexPatternTitle, + term: termFieldName, + metrics: metricExamples, + }); + const metrics = source.getMetricFields(); + const fields = await source.getFields(); + + const getFieldMeta = async field => { + return { + aggType: field.getAggType(), + name: field.getName(), + label: await field.getLabel(), + esDoc: field.getESDocFieldName(), + }; + }; + + const metricsFieldMeta = await Promise.all(metrics.map(getFieldMeta)); + const fieldsFieldMeta = await Promise.all(fields.map(getFieldMeta)); + + expect(_.isEqual(metricsFieldMeta, fieldsFieldMeta)).toEqual(true); + }); }); describe('extractPropertiesMap', () => { From 444cbbf8d8e780a83b076ac0df2cf7ed1a265211 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 26 Feb 2020 16:52:36 -0500 Subject: [PATCH 16/35] more typing --- .../plugins/maps/common/descriptor_types.d.ts | 13 ++++ .../maps/public/layers/fields/field.js | 55 -------------- .../maps/public/layers/fields/field.ts | 74 ++++++++++++++++++ .../public/layers/sources/es_agg_source.d.ts | 9 +++ .../es_geo_grid_source.d.ts | 12 +++ .../es_geo_grid_source.test.ts | 76 +++++++++++++++++++ .../maps/public/layers/sources/es_source.d.ts | 16 ++++ .../public/layers/sources/vector_source.d.ts | 33 ++++++++ 8 files changed, 233 insertions(+), 55 deletions(-) delete mode 100644 x-pack/legacy/plugins/maps/public/layers/fields/field.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/fields/field.ts create mode 100644 x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.d.ts create mode 100644 x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.d.ts create mode 100644 x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.test.ts create mode 100644 x-pack/legacy/plugins/maps/public/layers/sources/es_source.d.ts create mode 100644 x-pack/legacy/plugins/maps/public/layers/sources/vector_source.d.ts diff --git a/x-pack/legacy/plugins/maps/common/descriptor_types.d.ts b/x-pack/legacy/plugins/maps/common/descriptor_types.d.ts index c024721dfb870..a285f607312e8 100644 --- a/x-pack/legacy/plugins/maps/common/descriptor_types.d.ts +++ b/x-pack/legacy/plugins/maps/common/descriptor_types.d.ts @@ -4,6 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ +import uuid from 'uuid/v4'; + export interface ISourceDescriptor { id: string; type: string; @@ -13,6 +15,17 @@ export interface IXYZTMSSourceDescriptor extends ISourceDescriptor { urlTemplate: string; } +export interface IESAggSourceDescriptor extends ISourceDescriptor { + indexPatternId: string; + metrics: unknown[]; +} + +export interface IGeoGridSourceDescriptor extends IESAggSourceDescriptor { + geoField: string; + requestType: string; + resolution: string; +} + export interface ILayerDescriptor { sourceDescriptor: ISourceDescriptor; id: string; diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/field.js b/x-pack/legacy/plugins/maps/public/layers/fields/field.js deleted file mode 100644 index b5d157ad1697a..0000000000000 --- a/x-pack/legacy/plugins/maps/public/layers/fields/field.js +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { FIELD_ORIGIN } from '../../../common/constants'; - -export class AbstractField { - constructor({ fieldName, source, origin }) { - this._fieldName = fieldName; - this._source = source; - this._origin = origin || FIELD_ORIGIN.SOURCE; - } - - getName() { - return this._fieldName; - } - - getSource() { - return this._source; - } - - isValid() { - return !!this._fieldName; - } - - async getDataType() { - return 'string'; - } - - async getLabel() { - return this._fieldName; - } - - async createTooltipProperty() { - throw new Error('must implement Field#createTooltipProperty'); - } - - getOrigin() { - return this._origin; - } - - supportsFieldMeta() { - return false; - } - - async getOrdinalFieldMetaRequest(/* config */) { - return null; - } - - async getCategoricalFieldMetaRequest() { - return null; - } -} diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/field.ts b/x-pack/legacy/plugins/maps/public/layers/fields/field.ts new file mode 100644 index 0000000000000..4393181aeecd9 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/fields/field.ts @@ -0,0 +1,74 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { FIELD_ORIGIN } from '../../../common/constants'; +import { IVectorSource } from '../sources/vector_source'; + +export interface IField { + getName(): string; + getLabel(): Promise; + getDataType(): Promise; +} + +export class AbstractField implements IField { + private _fieldName: string; + private _source: IVectorSource; + private _origin: string; + + constructor({ + fieldName, + source, + origin, + }: { + fieldName: string; + source: IVectorSource; + origin: string; + }) { + this._fieldName = fieldName; + this._source = source; + this._origin = origin || FIELD_ORIGIN.SOURCE; + } + + getName(): string { + return this._fieldName; + } + + getSource(): IVectorSource { + return this._source; + } + + isValid(): boolean { + return !!this._fieldName; + } + + async getDataType(): Promise { + return 'string'; + } + + async getLabel(): Promise { + return this._fieldName; + } + + async createTooltipProperty(): Promise { + throw new Error('must implement Field#createTooltipProperty'); + } + + getOrigin(): string { + return this._origin; + } + + supportsFieldMeta(): boolean { + return false; + } + + async getOrdinalFieldMetaRequest(/* config */): Promise { + return null; + } + + async getCategoricalFieldMetaRequest(): Promise { + return null; + } +} diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.d.ts b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.d.ts new file mode 100644 index 0000000000000..ecbc6d54f1b7e --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.d.ts @@ -0,0 +1,9 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { AbstractESSource } from './es_source'; + +export class AbstractESAggSource extends AbstractESSource {} diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.d.ts b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.d.ts new file mode 100644 index 0000000000000..8ed9410710ebc --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.d.ts @@ -0,0 +1,12 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { AbstractESAggSource } from '../es_agg_source'; +import { IGeoGridSourceDescriptor } from '../../../../common/descriptor_types'; + +export class ESGeoGridSource extends AbstractESAggSource { + constructor(sourceDescriptor: IGeoGridSourceDescriptor, inspectorAdapters: object); +} diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.test.ts b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.test.ts new file mode 100644 index 0000000000000..14eb01a577017 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.test.ts @@ -0,0 +1,76 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ +jest.mock('../../../kibana_services', () => {}); +jest.mock('ui/new_platform'); + +import { ESGeoGridSource } from './es_geo_grid_source'; +import { ES_GEO_GRID } from '../../../../common/constants'; +import { IField } from '../../fields/field'; + +describe('ESGeoGridSource', () => { + it('metrics and fields should match', async () => { + const metricExamples = [ + { + type: 'sum', + field: 'myFieldGettingSummed', + label: 'my custom label', + }, + { + // metric config is invalid beause field is missing + type: 'max', + }, + { + // metric config is valid because "count" metric does not need to provide field + type: 'count', + label: '', // should ignore empty label fields + }, + ]; + + const geogridSource = new ESGeoGridSource( + { + id: 'foobar', + indexPatternId: 'fooIp', + geoField: 'bar', + metrics: metricExamples, + resolution: 'coarse', + type: ES_GEO_GRID, + requestType: 'heatmap', + }, + {} + ); + + const fields = await geogridSource.getFields(); + const metrics = await geogridSource.getMetricFields(); + + const getFieldMeta = async (field: IField) => { + return { + field: field.getName(), + label: await field.getLabel(), + type: await field.getDataType(), + }; + }; + + const fm = await Promise.all(fields.map(getFieldMeta)); + const mm = await Promise.all(metrics.map(getFieldMeta)); + + expect(_.isEqual(fm, mm)).toEqual(true); + + expect( + _.isEqual(fm, [ + { + type: 'number', + field: 'sum_of_myFieldGettingSummed', + label: 'my custom label', + }, + { + type: 'number', + label: 'count', + field: 'doc_count', + }, + ]) + ).toEqual(true); + }); +}); diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_source.d.ts b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.d.ts new file mode 100644 index 0000000000000..5f2e585cffdd1 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.d.ts @@ -0,0 +1,16 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { AbstractVectorSource, IVectorSource } from './vector_source'; +import { IField } from '../fields/field'; + +export interface IESSource extends IVectorSource { + getMetricFields(): IField[]; +} + +export class AbstractESSource extends AbstractVectorSource implements IESSource { + getMetricFields(): IField[]; +} diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.d.ts b/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.d.ts new file mode 100644 index 0000000000000..d9ea037f3dc7d --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.d.ts @@ -0,0 +1,33 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { AbstractSource, ISource } from './source'; +import { IField } from '../fields/field'; + +export interface IGeoJsonResult { + data: unknown; + meta: unknown; +} + +export interface IVectorSource extends ISource { + getGeoJsonWithMeta( + layerName: 'string', + searchFilters: unknown[], + registerCancelCallback: (callback: () => void) => void + ): Promise; + + getFields(): Promise; +} + +export class AbstractVectorSource extends AbstractSource implements IVectorSource { + getGeoJsonWithMeta( + layerName: 'string', + searchFilters: unknown[], + registerCancelCallback: (callback: () => void) => void + ): Promise; + + getFields(): Promise; +} From d02909403a5c4ce542cd32685f8760ea9bd301d1 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 27 Feb 2020 13:10:21 -0500 Subject: [PATCH 17/35] add style ts boilerplate --- .../plugins/maps/common/descriptor_types.d.ts | 24 ++++++++++ .../public/layers/styles/vector/style_meta.ts | 47 +++++++++++++++++++ .../layers/styles/vector/vector_style.js | 15 +++--- 3 files changed, 78 insertions(+), 8 deletions(-) create mode 100644 x-pack/legacy/plugins/maps/public/layers/styles/vector/style_meta.ts diff --git a/x-pack/legacy/plugins/maps/common/descriptor_types.d.ts b/x-pack/legacy/plugins/maps/common/descriptor_types.d.ts index a285f607312e8..fdf23a3b677a8 100644 --- a/x-pack/legacy/plugins/maps/common/descriptor_types.d.ts +++ b/x-pack/legacy/plugins/maps/common/descriptor_types.d.ts @@ -31,3 +31,27 @@ export interface ILayerDescriptor { id: string; label?: string; } + +interface IFieldMetaDescriptor { + [key: string]: string | number | unknown; +} + +interface IRangeFieldMetaDescriptor extends IFieldMetaDescriptor { + min: number; + max: number; + delta: number; +} + +interface ICategoryFieldMetaDescriptor extends IFieldMetaDescriptor { + categories: unknown[]; +} + +interface IGeometryTypesDescriptor { + isPointsOnly: boolean; + isLinesOnly: boolean; + isPolygonsOnly: boolean; +} +interface IStyleMetaDescriptor { + geometryTypes?: IGeometryTypesDescriptor; + [key: string]: IRangeFieldMetaDescriptor | ICategoryFieldMetaDescriptor | unknown; +} diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/style_meta.ts b/x-pack/legacy/plugins/maps/public/layers/styles/vector/style_meta.ts new file mode 100644 index 0000000000000..4b97c94cb15e3 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/style_meta.ts @@ -0,0 +1,47 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { + IFieldMetaDescriptor, + IStyleMetaDescriptor, + IGeometryTypesDescriptor, +} from '../../../../common/descriptor_types'; + +export class StyleMeta { + private _descriptor: IStyleMetaDescriptor; + constructor(styleMetaDescriptor: IStyleMetaDescriptor) { + this._descriptor = styleMetaDescriptor; + } + + getGeometryTypes(): IGeometryTypesDescriptor { + return this._descriptor.geometryTypes + ? this._descriptor.geometryTypes + : ({ + isPointsOnly: false, + isLinesOnly: false, + isPolygonsOnly: false, + }); + } + + getFieldMetaDescriptor(field: string): IFieldMetaDescriptor | unknown { + if (field === 'geometryTypes') { + throw new Error('Cannot use geometryTypes as field-key'); + } + return this._descriptor[field]; + } + + isPointsOnly(): boolean { + return this.getGeometryTypes().isPointsOnly; + } + + isLinesOnly(): boolean { + return this.getGeometryTypes().isLinesOnly; + } + + isPolygonsOnly(): boolean { + return this.getGeometryTypes().isPolygonsOnly; + } +} diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js index 053aa114d94ae..ed5f7a339bb40 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style.js @@ -23,6 +23,7 @@ import { LAYER_STYLE_TYPE, DEFAULT_ICON, } from '../../../../common/constants'; +import { StyleMeta } from './style_meta'; import { VectorIcon } from './components/legend/vector_icon'; import { VectorStyleLegend } from './components/legend/vector_style_legend'; import { VECTOR_SHAPE_TYPES } from '../../sources/vector_feature_types'; @@ -71,6 +72,8 @@ export class VectorStyle extends AbstractStyle { ...VectorStyle.createDescriptor(descriptor.properties, descriptor.isTimeAware), }; + this._styleMeta = new StyleMeta(this._descriptor.__styleMeta || {}); + this._symbolizeAsStyleProperty = new SymbolizeAsProperty( this._descriptor.properties[VECTOR_STYLES.SYMBOLIZE_AS].options, VECTOR_STYLES.SYMBOLIZE_AS @@ -335,15 +338,15 @@ export class VectorStyle extends AbstractStyle { } _getIsPointsOnly = () => { - return _.get(this._getStyleMeta(), 'geometryTypes.isPointsOnly', false); + return this._styleMeta.isPointsOnly(); }; _getIsLinesOnly = () => { - return _.get(this._getStyleMeta(), 'geometryTypes.isLinesOnly', false); + return this._styleMeta.isLinesOnly(); }; _getIsPolygonsOnly = () => { - return _.get(this._getStyleMeta(), 'geometryTypes.isPolygonsOnly', false); + return this._styleMeta.isPolygonsOnly(); }; _getDynamicPropertyByFieldName(fieldName) { @@ -354,7 +357,7 @@ export class VectorStyle extends AbstractStyle { } _getFieldMeta = fieldName => { - const fieldMetaFromLocalFeatures = _.get(this._descriptor, ['__styleMeta', fieldName]); + const fieldMetaFromLocalFeatures = this._styleMeta.getFieldMetaDescriptor(fieldName); const dynamicProp = this._getDynamicPropertyByFieldName(fieldName); if (!dynamicProp || !dynamicProp.isFieldMetaEnabled()) { @@ -418,10 +421,6 @@ export class VectorStyle extends AbstractStyle { return formatters[fieldName]; }; - _getStyleMeta = () => { - return _.get(this._descriptor, '__styleMeta', {}); - }; - _getSymbolId() { return this.arePointsSymbolizedAsCircles() ? undefined From 970aedad3fb9c51d98fedfc08033027d4c0f1b60 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 27 Feb 2020 13:10:45 -0500 Subject: [PATCH 18/35] lint --- .../plugins/maps/public/layers/styles/vector/style_meta.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/style_meta.ts b/x-pack/legacy/plugins/maps/public/layers/styles/vector/style_meta.ts index 4b97c94cb15e3..081b20fb7625b 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/style_meta.ts +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/style_meta.ts @@ -19,11 +19,11 @@ export class StyleMeta { getGeometryTypes(): IGeometryTypesDescriptor { return this._descriptor.geometryTypes ? this._descriptor.geometryTypes - : ({ + : { isPointsOnly: false, isLinesOnly: false, isPolygonsOnly: false, - }); + }; } getFieldMetaDescriptor(field: string): IFieldMetaDescriptor | unknown { From c6e2535a0a329ebeced94fc16565cc80c81f7d21 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 5 Mar 2020 14:14:32 -0500 Subject: [PATCH 19/35] split tests --- .../styles/vector/properties/dynamic_color_property.test.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.test.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.test.js index aea527a99735f..b4c3a6c69773e 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.test.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.test.js @@ -237,7 +237,7 @@ test('Should pluck the categorical style-meta from fieldmeta', async () => { }); }); -test('Should read out ordinal/categorical correctly', async () => { +test('Should read out categorical type correctly', async () => { const categoricalColorStyle = makeProperty({ type: COLOR_MAP_TYPE.CATEGORICAL, colorCategory: 'palette_0', @@ -245,7 +245,9 @@ test('Should read out ordinal/categorical correctly', async () => { expect(categoricalColorStyle.isOrdinal()).toEqual(false); expect(categoricalColorStyle.isCategorical()).toEqual(true); +}); +test('Should read out ordinal correctly when type===undefined', async () => { const ordinalColorStyle = makeProperty({ type: undefined, color: 'Blues', @@ -253,7 +255,9 @@ test('Should read out ordinal/categorical correctly', async () => { expect(ordinalColorStyle.isOrdinal()).toEqual(true); expect(ordinalColorStyle.isCategorical()).toEqual(false); +}); +test('Should read out ordinal type correctly', async () => { const ordinalColorStyle2 = makeProperty({ type: COLOR_MAP_TYPE.ORDINAL, colorCategory: 'palette_0', From ef9e74220de2c2d9332173d3d67e046f0d860c99 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 5 Mar 2020 22:24:03 -0500 Subject: [PATCH 20/35] tslint fixes --- .../maps/public/layers/fields/es_agg_field.js | 96 +++++++++++++++++++ .../es_geo_grid_source.test.ts | 12 +-- 2 files changed, 102 insertions(+), 6 deletions(-) create mode 100644 x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js new file mode 100644 index 0000000000000..7dfc806991ca2 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js @@ -0,0 +1,96 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { AbstractField } from './field'; +import { AGG_TYPE } from '../../../common/constants'; +import { isMetricCountable } from '../util/is_metric_countable'; +import { ESAggMetricTooltipProperty } from '../tooltips/es_aggmetric_tooltip_property'; +import { getField, addFieldToDSL } from '../util/es_agg_utils'; + +export class ESAggMetricField extends AbstractField { + static type = 'ES_AGG'; + + constructor({ label, source, aggType, esDocField, origin }) { + super({ source, origin }); + this._label = label; + this._aggType = aggType; + this._esDocField = esDocField; + } + + getName() { + return this._source.getAggKey(this.getAggType(), this.getRootName()); + } + + getRootName() { + return this._getESDocFieldName(); + } + + async getLabel() { + return this._label + ? this._label + : this._source.getAggLabel(this.getAggType(), this.getRootName()); + } + + getAggType() { + return this._aggType; + } + + isValid() { + return this.getAggType() === AGG_TYPE.COUNT ? true : !!this._esDocField; + } + + async getDataType() { + return this.getAggType() === AGG_TYPE.TERMS ? 'string' : 'number'; + } + + _getESDocFieldName() { + return this._esDocField ? this._esDocField.getName() : ''; + } + + getRequestDescription() { + return this.getAggType() !== AGG_TYPE.COUNT + ? `${this.getAggType()} ${this.getRootName()}` + : AGG_TYPE.COUNT; + } + + async createTooltipProperty(value) { + const indexPattern = await this._source.getIndexPattern(); + return new ESAggMetricTooltipProperty( + this.getName(), + await this.getLabel(), + value, + indexPattern, + this + ); + } + + getValueAggDsl(indexPattern) { + const field = getField(indexPattern, this.getRootName()); + const aggType = this.getAggType(); + const aggBody = aggType === AGG_TYPE.TERMS ? { size: 1, shard_size: 1 } : {}; + return { + [aggType]: addFieldToDSL(aggBody, field), + }; + } + + supportsFieldMeta() { + // count and sum aggregations are not within field bounds so they do not support field meta. + return !isMetricCountable(this.getAggType()); + } + + canValueBeFormatted() { + // Do not use field formatters for counting metrics + return ![AGG_TYPE.COUNT, AGG_TYPE.UNIQUE_COUNT].includes(this.getAggType()); + } + + async getOrdinalFieldMetaRequest(config) { + return this._esDocField.getOrdinalFieldMetaRequest(config); + } + + async getCategoricalFieldMetaRequest() { + return this._esDocField.getCategoricalFielOdMetaRequest(); + } +} diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.test.ts b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.test.ts index 14eb01a577017..06f308883dd0f 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.test.ts +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.test.ts @@ -7,24 +7,24 @@ jest.mock('../../../kibana_services', () => {}); jest.mock('ui/new_platform'); import { ESGeoGridSource } from './es_geo_grid_source'; -import { ES_GEO_GRID } from '../../../../common/constants'; +import { AGG_TYPE, ES_GEO_GRID, GRID_RESOLUTION, RENDER_AS } from '../../../../common/constants'; import { IField } from '../../fields/field'; describe('ESGeoGridSource', () => { it('metrics and fields should match', async () => { const metricExamples = [ { - type: 'sum', + type: AGG_TYPE.SUM, field: 'myFieldGettingSummed', label: 'my custom label', }, { // metric config is invalid beause field is missing - type: 'max', + type: AGG_TYPE.MAX, }, { // metric config is valid because "count" metric does not need to provide field - type: 'count', + type: AGG_TYPE.COUNT, label: '', // should ignore empty label fields }, ]; @@ -35,9 +35,9 @@ describe('ESGeoGridSource', () => { indexPatternId: 'fooIp', geoField: 'bar', metrics: metricExamples, - resolution: 'coarse', + resolution: GRID_RESOLUTION.COARSE, type: ES_GEO_GRID, - requestType: 'heatmap', + requestType: RENDER_AS.HEATMAP, }, {} ); From b6764d8f0f4be4226e0f714f8dec8184dcaae735 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 5 Mar 2020 22:27:43 -0500 Subject: [PATCH 21/35] lint fix --- .../layers/sources/es_geo_grid_source/es_geo_grid_source.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.d.ts b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.d.ts index 652409b61fd72..5b01af324d6b7 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.d.ts +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.d.ts @@ -6,7 +6,9 @@ import { AbstractESAggSource } from '../es_agg_source'; import { ESGeoGridSourceDescriptor } from '../../../../common/descriptor_types'; +import { IESAggField } from '../../fields/es_agg_field'; export class ESGeoGridSource extends AbstractESAggSource { constructor(sourceDescriptor: ESGeoGridSourceDescriptor, inspectorAdapters: unknown); + getMetricFields(): IESAggField[]; } From cb0e37a489eb72b61cdeb0eeef945b90c4bfe139 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 5 Mar 2020 22:35:42 -0500 Subject: [PATCH 22/35] fix name --- .../plugins/maps/public/layers/sources/es_term_source.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.test.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.test.js index f200f4e4edfcb..549176dd7aa48 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.test.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.test.js @@ -80,7 +80,7 @@ describe('getMetricFields', () => { aggType: field.getAggType(), name: field.getName(), label: await field.getLabel(), - esDoc: field.getESDocFieldName(), + esDoc: field.getRootName(), }; }; From fee679367fc503c26d6ef2a26f73e00abbf525d2 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 5 Mar 2020 22:45:36 -0500 Subject: [PATCH 23/35] fix faulty merge --- .../maps/public/layers/fields/es_agg_field.js | 96 ------------------- 1 file changed, 96 deletions(-) delete mode 100644 x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js deleted file mode 100644 index 7dfc806991ca2..0000000000000 --- a/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { AbstractField } from './field'; -import { AGG_TYPE } from '../../../common/constants'; -import { isMetricCountable } from '../util/is_metric_countable'; -import { ESAggMetricTooltipProperty } from '../tooltips/es_aggmetric_tooltip_property'; -import { getField, addFieldToDSL } from '../util/es_agg_utils'; - -export class ESAggMetricField extends AbstractField { - static type = 'ES_AGG'; - - constructor({ label, source, aggType, esDocField, origin }) { - super({ source, origin }); - this._label = label; - this._aggType = aggType; - this._esDocField = esDocField; - } - - getName() { - return this._source.getAggKey(this.getAggType(), this.getRootName()); - } - - getRootName() { - return this._getESDocFieldName(); - } - - async getLabel() { - return this._label - ? this._label - : this._source.getAggLabel(this.getAggType(), this.getRootName()); - } - - getAggType() { - return this._aggType; - } - - isValid() { - return this.getAggType() === AGG_TYPE.COUNT ? true : !!this._esDocField; - } - - async getDataType() { - return this.getAggType() === AGG_TYPE.TERMS ? 'string' : 'number'; - } - - _getESDocFieldName() { - return this._esDocField ? this._esDocField.getName() : ''; - } - - getRequestDescription() { - return this.getAggType() !== AGG_TYPE.COUNT - ? `${this.getAggType()} ${this.getRootName()}` - : AGG_TYPE.COUNT; - } - - async createTooltipProperty(value) { - const indexPattern = await this._source.getIndexPattern(); - return new ESAggMetricTooltipProperty( - this.getName(), - await this.getLabel(), - value, - indexPattern, - this - ); - } - - getValueAggDsl(indexPattern) { - const field = getField(indexPattern, this.getRootName()); - const aggType = this.getAggType(); - const aggBody = aggType === AGG_TYPE.TERMS ? { size: 1, shard_size: 1 } : {}; - return { - [aggType]: addFieldToDSL(aggBody, field), - }; - } - - supportsFieldMeta() { - // count and sum aggregations are not within field bounds so they do not support field meta. - return !isMetricCountable(this.getAggType()); - } - - canValueBeFormatted() { - // Do not use field formatters for counting metrics - return ![AGG_TYPE.COUNT, AGG_TYPE.UNIQUE_COUNT].includes(this.getAggType()); - } - - async getOrdinalFieldMetaRequest(config) { - return this._esDocField.getOrdinalFieldMetaRequest(config); - } - - async getCategoricalFieldMetaRequest() { - return this._esDocField.getCategoricalFielOdMetaRequest(); - } -} From 89d461df9c3d9f394f26e9d34cbe5d5e99296164 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Fri, 6 Mar 2020 16:35:46 -0500 Subject: [PATCH 24/35] init feedback --- .../public/layers/sources/es_agg_source.d.ts | 3 + .../es_geo_grid_source.d.ts | 2 - .../es_geo_grid_source.test.ts | 91 ++++++++++--------- .../components/color/color_map_select.js | 9 +- 4 files changed, 53 insertions(+), 52 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.d.ts b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.d.ts index a91bb4a8bb1a7..b662cd42ee34d 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.d.ts +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.d.ts @@ -7,13 +7,16 @@ import { IESSource } from './es_source'; import { AbstractESSource } from './es_source'; import { AGG_TYPE } from '../../../common/constants'; +import { IESAggField } from '../fields/es_agg_field'; export interface IESAggSource extends IESSource { getAggKey(aggType: AGG_TYPE, fieldName: string): string; getAggLabel(aggType: AGG_TYPE, fieldName: string): string; + getMetricFields(): IESAggField[]; } export class AbstractESAggSource extends AbstractESSource implements IESAggSource { getAggKey(aggType: AGG_TYPE, fieldName: string): string; getAggLabel(aggType: AGG_TYPE, fieldName: string): string; + getMetricFields(): IESAggField[]; } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.d.ts b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.d.ts index 5b01af324d6b7..652409b61fd72 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.d.ts +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.d.ts @@ -6,9 +6,7 @@ import { AbstractESAggSource } from '../es_agg_source'; import { ESGeoGridSourceDescriptor } from '../../../../common/descriptor_types'; -import { IESAggField } from '../../fields/es_agg_field'; export class ESGeoGridSource extends AbstractESAggSource { constructor(sourceDescriptor: ESGeoGridSourceDescriptor, inspectorAdapters: unknown); - getMetricFields(): IESAggField[]; } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.test.ts b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.test.ts index 06f308883dd0f..95dba2269311a 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.test.ts +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.test.ts @@ -11,55 +11,49 @@ import { AGG_TYPE, ES_GEO_GRID, GRID_RESOLUTION, RENDER_AS } from '../../../../c import { IField } from '../../fields/field'; describe('ESGeoGridSource', () => { - it('metrics and fields should match', async () => { - const metricExamples = [ - { - type: AGG_TYPE.SUM, - field: 'myFieldGettingSummed', - label: 'my custom label', - }, - { - // metric config is invalid beause field is missing - type: AGG_TYPE.MAX, - }, - { - // metric config is valid because "count" metric does not need to provide field - type: AGG_TYPE.COUNT, - label: '', // should ignore empty label fields - }, - ]; + const metricExamples = [ + { + type: AGG_TYPE.SUM, + field: 'myFieldGettingSummed', + label: 'my custom label', + }, + { + // metric config is invalid beause field is missing + type: AGG_TYPE.MAX, + }, + { + // metric config is valid because "count" metric does not need to provide field + type: AGG_TYPE.COUNT, + label: '', // should ignore empty label fields + }, + ]; - const geogridSource = new ESGeoGridSource( - { - id: 'foobar', - indexPatternId: 'fooIp', - geoField: 'bar', - metrics: metricExamples, - resolution: GRID_RESOLUTION.COARSE, - type: ES_GEO_GRID, - requestType: RENDER_AS.HEATMAP, - }, - {} - ); + const geogridSource = new ESGeoGridSource( + { + id: 'foobar', + indexPatternId: 'fooIp', + geoField: 'bar', + metrics: metricExamples, + resolution: GRID_RESOLUTION.COARSE, + type: ES_GEO_GRID, + requestType: RENDER_AS.HEATMAP, + }, + {} + ); - const fields = await geogridSource.getFields(); - const metrics = await geogridSource.getMetricFields(); - - const getFieldMeta = async (field: IField) => { - return { - field: field.getName(), - label: await field.getLabel(), - type: await field.getDataType(), - }; + const getFieldMeta = async (field: IField) => { + return { + field: field.getName(), + label: await field.getLabel(), + type: await field.getDataType(), }; + }; - const fm = await Promise.all(fields.map(getFieldMeta)); - const mm = await Promise.all(metrics.map(getFieldMeta)); - - expect(_.isEqual(fm, mm)).toEqual(true); - + it('getMetricFields should remove incomplete metric aggregations. Smaller tests t', async () => { + const fields = await geogridSource.getFields(); + const fieldsMeta = await Promise.all(fields.map(getFieldMeta)); expect( - _.isEqual(fm, [ + _.isEqual(fieldsMeta, [ { type: 'number', field: 'sum_of_myFieldGettingSummed', @@ -73,4 +67,13 @@ describe('ESGeoGridSource', () => { ]) ).toEqual(true); }); + + it('getFields should return getMetricFields', async () => { + const fields = await geogridSource.getFields(); + const metrics = await geogridSource.getMetricFields(); + const fieldsMeta = await Promise.all(fields.map(getFieldMeta)); + const metricFieldsMeta = await Promise.all(metrics.map(getFieldMeta)); + + expect(_.isEqual(fieldsMeta, metricFieldsMeta)).toEqual(true); + }); }); diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js index 24c525b8e596d..ca50691ce105e 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js @@ -130,12 +130,9 @@ export class ColorMapSelect extends Component { : ''; } - let toggle; - if (this.props.showColorMapTypeToggle) { - toggle = {this._renderColorMapToggle()}; - } else { - toggle = ; - } + const toggle = this.props.showColorMapTypeToggle ? ( + {this._renderColorMapToggle()} + ) : null; return ( From fae5e84e5bb1bedc6850037209683063b9cea886 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Fri, 6 Mar 2020 16:45:32 -0500 Subject: [PATCH 25/35] more edits --- .../components/color/dynamic_color_form.js | 10 ++--- .../vector/components/vector_style_editor.js | 38 ++++++++----------- .../properties/dynamic_color_property.test.js | 4 +- 3 files changed, 21 insertions(+), 31 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/dynamic_color_form.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/dynamic_color_form.js index 673f84c04bd4c..c6b68b7e94409 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/dynamic_color_form.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/dynamic_color_form.js @@ -13,12 +13,6 @@ import { CATEGORICAL_DATA_TYPES, COLOR_MAP_TYPE } from '../../../../../../common import { COLOR_GRADIENTS, COLOR_PALETTES } from '../../../color_utils'; import { i18n } from '@kbn/i18n'; -function getDefaultColorMapType(fieldType) { - return CATEGORICAL_DATA_TYPES.includes(fieldType) - ? COLOR_MAP_TYPE.CATEGORICAL - : COLOR_MAP_TYPE.ORDINAL; -} - export function DynamicColorForm({ fields, onDynamicStyleChange, @@ -47,7 +41,9 @@ export function DynamicColorForm({ const onFieldChange = async ({ field }) => { const { name, origin, type: fieldType } = field; - const defaultColorMapType = getDefaultColorMapType(fieldType); + const defaultColorMapType = CATEGORICAL_DATA_TYPES.includes(fieldType) + ? COLOR_MAP_TYPE.CATEGORICAL + : COLOR_MAP_TYPE.ORDINAL; onDynamicStyleChange(styleProperty.getStyleName(), { ...styleOptions, field: { name, origin }, diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js index 7cf80e1f792d6..92146ba3006fc 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js @@ -33,7 +33,7 @@ export class VectorStyleEditor extends Component { dateFields: [], numberFields: [], fields: [], - styleableFields: [], + ordinalAndCategoricalFields: [], defaultDynamicProperties: getDefaultDynamicProperties(), defaultStaticProperties: getDefaultStaticProperties(), supportedFeatures: undefined, @@ -70,25 +70,19 @@ export class VectorStyleEditor extends Component { const fieldPromises = fields.map(getFieldMeta); const fieldsArrayAll = await Promise.all(fieldPromises); if (this._isMounted && !_.isEqual(fieldsArrayAll, this.state.fields)) { - this.setState({ fields: fieldsArrayAll }); + return; } - const styleableFields = fieldsArrayAll.filter(field => { - return CATEGORICAL_DATA_TYPES.includes(field.type) || ORDINAL_DATA_TYPES.includes(field.type); + this.setState({ + fields: fieldsArrayAll, + ordinalAndCategoricalFields: fieldsArrayAll.filter(field => { + return ( + CATEGORICAL_DATA_TYPES.includes(field.type) || ORDINAL_DATA_TYPES.includes(field.type) + ); + }), + dateFields: fieldsArrayAll.filter(field => field.type === 'date'), + numberFields: fieldsArrayAll.filter(field => field.type === 'number'), }); - if (this._isMounted && !_.isEqual(styleableFields, this.state.styleableFields)) { - this.setState({ styleableFields: styleableFields }); - } - - const dateFieldsArray = styleableFields.filter(field => field.type === 'date'); - if (this._isMounted && !_.isEqual(dateFieldsArray, this.state.dateFields)) { - this.setState({ dateFields: dateFieldsArray }); - } - - const numberFieldsArray = styleableFields.filter(field => field.type === 'number'); - if (this._isMounted && !_.isEqual(numberFieldsArray, this.state.numberFields)) { - this.setState({ numberFields: numberFieldsArray }); - } } async _loadSupportedFeatures() { @@ -166,7 +160,7 @@ export class VectorStyleEditor extends Component { onStaticStyleChange={this._onStaticStyleChange} onDynamicStyleChange={this._onDynamicStyleChange} styleProperty={this.props.styleProperties[VECTOR_STYLES.FILL_COLOR]} - fields={this.state.styleableFields} + fields={this.state.ordinalAndCategoricalFields} defaultStaticStyleOptions={ this.state.defaultStaticProperties[VECTOR_STYLES.FILL_COLOR].options } @@ -187,7 +181,7 @@ export class VectorStyleEditor extends Component { onStaticStyleChange={this._onStaticStyleChange} onDynamicStyleChange={this._onDynamicStyleChange} styleProperty={this.props.styleProperties[VECTOR_STYLES.LINE_COLOR]} - fields={this.state.styleableFields} + fields={this.state.ordinalAndCategoricalFields} defaultStaticStyleOptions={ this.state.defaultStaticProperties[VECTOR_STYLES.LINE_COLOR].options } @@ -243,7 +237,7 @@ export class VectorStyleEditor extends Component { onStaticStyleChange={this._onStaticStyleChange} onDynamicStyleChange={this._onDynamicStyleChange} styleProperty={this.props.styleProperties[VECTOR_STYLES.LABEL_COLOR]} - fields={this.state.styleableFields} + fields={this.state.ordinalAndCategoricalFields} defaultStaticStyleOptions={ this.state.defaultStaticProperties[VECTOR_STYLES.LABEL_COLOR].options } @@ -276,7 +270,7 @@ export class VectorStyleEditor extends Component { onStaticStyleChange={this._onStaticStyleChange} onDynamicStyleChange={this._onDynamicStyleChange} styleProperty={this.props.styleProperties[VECTOR_STYLES.LABEL_BORDER_COLOR]} - fields={this.state.styleableFields} + fields={this.state.ordinalAndCategoricalFields} defaultStaticStyleOptions={ this.state.defaultStaticProperties[VECTOR_STYLES.LABEL_BORDER_COLOR].options } @@ -329,7 +323,7 @@ export class VectorStyleEditor extends Component { onStaticStyleChange={this._onStaticStyleChange} onDynamicStyleChange={this._onDynamicStyleChange} styleProperty={this.props.styleProperties[VECTOR_STYLES.ICON]} - fields={this.state.styleableFields} + fields={this.state.ordinalAndCategoricalFields} defaultStaticStyleOptions={ this.state.defaultStaticProperties[VECTOR_STYLES.ICON].options } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.test.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.test.js index b4c3a6c69773e..5b286e4ba120e 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.test.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/properties/dynamic_color_property.test.js @@ -237,7 +237,7 @@ test('Should pluck the categorical style-meta from fieldmeta', async () => { }); }); -test('Should read out categorical type correctly', async () => { +test('isCategorical should return true when type is categorical', async () => { const categoricalColorStyle = makeProperty({ type: COLOR_MAP_TYPE.CATEGORICAL, colorCategory: 'palette_0', @@ -247,7 +247,7 @@ test('Should read out categorical type correctly', async () => { expect(categoricalColorStyle.isCategorical()).toEqual(true); }); -test('Should read out ordinal correctly when type===undefined', async () => { +test('isOrdinal should return true when type is ordinal', async () => { const ordinalColorStyle = makeProperty({ type: undefined, color: 'Blues', From 2958ba7e8640838d49c5798c0aa7a63e3ebafc61 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Sat, 7 Mar 2020 18:53:51 -0500 Subject: [PATCH 26/35] test --- .../layers/styles/vector/components/vector_style_editor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js index 92146ba3006fc..7ad36bd2ae33d 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js @@ -69,7 +69,7 @@ export class VectorStyleEditor extends Component { const fields = await this.props.layer.getFields(); const fieldPromises = fields.map(getFieldMeta); const fieldsArrayAll = await Promise.all(fieldPromises); - if (this._isMounted && !_.isEqual(fieldsArrayAll, this.state.fields)) { + if (!this._isMounted || _.isEqual(fieldsArrayAll, this.state.fields)) { return; } From cc08409eb96f733c024fe99cd2e6c641b6f9c204 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Sat, 7 Mar 2020 18:54:20 -0500 Subject: [PATCH 27/35] language --- .../sources/es_geo_grid_source/es_geo_grid_source.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.test.ts b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.test.ts index 95dba2269311a..fe1484f0428d9 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.test.ts +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.test.ts @@ -49,7 +49,7 @@ describe('ESGeoGridSource', () => { }; }; - it('getMetricFields should remove incomplete metric aggregations. Smaller tests t', async () => { + it('getMetricFields should remove incomplete metric aggregations.', async () => { const fields = await geogridSource.getFields(); const fieldsMeta = await Promise.all(fields.map(getFieldMeta)); expect( From 3c4cd9b1d897bb3f68e7bf50b99193b3aa51bbf9 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Sat, 7 Mar 2020 19:30:19 -0500 Subject: [PATCH 28/35] add dummy test --- .../plugins/maps/common/descriptor_types.d.ts | 8 +- .../maps/public/layers/fields/es_agg_field.ts | 1 + .../public/layers/sources/es_agg_source.d.ts | 3 + .../layers/sources/es_agg_source.test.ts | 86 +++++++++++++++++++ .../es_geo_grid_source.d.ts | 3 + .../es_geo_grid_source/es_geo_grid_source.js | 2 +- .../es_geo_grid_source.test.ts | 37 +------- .../layers/sources/es_term_source.test.js | 38 +------- 8 files changed, 104 insertions(+), 74 deletions(-) create mode 100644 x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.test.ts diff --git a/x-pack/legacy/plugins/maps/common/descriptor_types.d.ts b/x-pack/legacy/plugins/maps/common/descriptor_types.d.ts index f03f828200bbd..ce0743ba2baed 100644 --- a/x-pack/legacy/plugins/maps/common/descriptor_types.d.ts +++ b/x-pack/legacy/plugins/maps/common/descriptor_types.d.ts @@ -35,11 +35,11 @@ export type AggDescriptor = { type: AGG_TYPE; }; -export type AbstractESAggDescriptor = AbstractESSourceDescriptor & { +export type AbstractESAggSourceDescriptor = AbstractESSourceDescriptor & { metrics: AggDescriptor[]; }; -export type ESGeoGridSourceDescriptor = AbstractESAggDescriptor & { +export type ESGeoGridSourceDescriptor = AbstractESAggSourceDescriptor & { requestType?: RENDER_AS; resolution?: GRID_RESOLUTION; }; @@ -54,12 +54,12 @@ export type ESSearchSourceDescriptor = AbstractESSourceDescriptor & { topHitsSize?: number; }; -export type ESPewPewSourceDescriptor = AbstractESAggDescriptor & { +export type ESPewPewSourceDescriptor = AbstractESAggSourceDescriptor & { sourceGeoField: string; destGeoField: string; }; -export type ESTermSourceDescriptor = AbstractESAggDescriptor & { +export type ESTermSourceDescriptor = AbstractESAggSourceDescriptor & { indexPatternTitle: string; term: string; // term field name }; diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.ts b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.ts index 9f08200442fea..00c6b4d26d2f2 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.ts +++ b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.ts @@ -21,6 +21,7 @@ import { TopTermPercentageField } from './top_term_percentage_field'; export interface IESAggField extends IField { getValueAggDsl(indexPattern: IndexPattern): unknown | null; getBucketCount(): number; + getAggType(): AGG_TYPE; } export class ESAggField implements IESAggField { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.d.ts b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.d.ts index b662cd42ee34d..99ee1ec652b54 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.d.ts +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.d.ts @@ -8,6 +8,7 @@ import { IESSource } from './es_source'; import { AbstractESSource } from './es_source'; import { AGG_TYPE } from '../../../common/constants'; import { IESAggField } from '../fields/es_agg_field'; +import { AbstractESAggSourceDescriptor } from '../../../common/descriptor_types'; export interface IESAggSource extends IESSource { getAggKey(aggType: AGG_TYPE, fieldName: string): string; @@ -16,6 +17,8 @@ export interface IESAggSource extends IESSource { } export class AbstractESAggSource extends AbstractESSource implements IESAggSource { + constructor(sourceDescriptor: AbstractESAggSourceDescriptor, inspectorAdapters: object); + getAggKey(aggType: AGG_TYPE, fieldName: string): string; getAggLabel(aggType: AGG_TYPE, fieldName: string): string; getMetricFields(): IESAggField[]; diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.test.ts b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.test.ts new file mode 100644 index 0000000000000..6dbc19f179a7a --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.test.ts @@ -0,0 +1,86 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { AbstractESAggSource } from './es_agg_source'; +import { IField } from '../fields/field'; +import { IESAggField } from '../fields/es_agg_field'; +import _ from 'lodash'; +import { AGG_TYPE } from '../../../common/constants'; +import { AggDescriptor } from '../../../common/descriptor_types'; + +jest.mock('ui/new_platform'); + +const sumFieldName = 'myFieldGettingSummed'; +const metricExamples = [ + { + type: AGG_TYPE.SUM, + field: sumFieldName, + label: 'my custom label', + }, + { + // metric config is invalid beause field is missing + type: AGG_TYPE.MAX, + }, + { + // metric config is valid because "count" metric does not need to provide field + type: AGG_TYPE.COUNT, + label: '', // should ignore empty label fields + }, +]; + +class TestESAggSource extends AbstractESAggSource { + constructor(metrics: AggDescriptor[]) { + super({ type: 'test', id: 'foobar', indexPatternId: 'foobarid', metrics }, []); + } +} + +describe('getMetricFields', () => { + it('should add default "count" metric when no metrics are provided', async () => { + const source = new TestESAggSource([]); + const metrics = source.getMetricFields(); + expect(metrics.length).toBe(1); + + expect(metrics[0].getAggType()).toEqual('count'); + expect(metrics[0].getName()).toEqual('doc_count'); + expect(await metrics[0].getLabel()).toEqual('count'); + }); + + it('should remove incomplete metric configurations', async () => { + const source = new TestESAggSource(metricExamples); + const metrics = source.getMetricFields(); + expect(metrics.length).toBe(2); + + expect(metrics[0].getAggType()).toEqual('sum'); + expect(metrics[0].getRootName()).toEqual(sumFieldName); + expect(metrics[0].getName()).toEqual('sum_of_myFieldGettingSummed'); + expect(await metrics[0].getLabel()).toEqual('my custom label'); + + expect(metrics[1].getAggType()).toEqual('count'); + expect(metrics[1].getName()).toEqual('doc_count'); + expect(await metrics[1].getLabel()).toEqual('count'); + }); + + it('getMetrics should be identical to getFields', async () => { + const source = new TestESAggSource(metricExamples); + const metrics = source.getMetricFields(); + const fields = await source.getFields(); + + const getFieldMeta = async (field: IField) => { + const esAggField = field as IESAggField; + return { + aggType: esAggField.getAggType(), + name: esAggField.getName(), + label: await esAggField.getLabel(), + esDoc: esAggField.getRootName(), + }; + }; + + const metricsFieldMeta = await Promise.all(metrics.map(getFieldMeta)); + const fieldsFieldMeta = await Promise.all(fields.map(getFieldMeta)); + + expect(_.isEqual(metricsFieldMeta, fieldsFieldMeta)).toEqual(true); + }); +}); diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.d.ts b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.d.ts index 652409b61fd72..48e90b6c41d51 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.d.ts +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.d.ts @@ -6,7 +6,10 @@ import { AbstractESAggSource } from '../es_agg_source'; import { ESGeoGridSourceDescriptor } from '../../../../common/descriptor_types'; +import { GRID_RESOLUTION } from '../../../../common/constants'; export class ESGeoGridSource extends AbstractESAggSource { constructor(sourceDescriptor: ESGeoGridSourceDescriptor, inspectorAdapters: unknown); + getGridResolution(): GRID_RESOLUTION; + getGeoGridPrecision(zoom: number): number; } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js index 4987d052b8ab7..3b3e8004ded05 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js @@ -35,7 +35,7 @@ import { DynamicStyleProperty } from '../../styles/vector/properties/dynamic_sty import { StaticStyleProperty } from '../../styles/vector/properties/static_style_property'; import { DataRequestAbortError } from '../../util/data_request'; -const MAX_GEOTILE_LEVEL = 29; +export const MAX_GEOTILE_LEVEL = 29; export class ESGeoGridSource extends AbstractESAggSource { static type = ES_GEO_GRID; diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.test.ts b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.test.ts index fe1484f0428d9..2fcd64f292914 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.test.ts +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.test.ts @@ -8,7 +8,6 @@ jest.mock('ui/new_platform'); import { ESGeoGridSource } from './es_geo_grid_source'; import { AGG_TYPE, ES_GEO_GRID, GRID_RESOLUTION, RENDER_AS } from '../../../../common/constants'; -import { IField } from '../../fields/field'; describe('ESGeoGridSource', () => { const metricExamples = [ @@ -41,39 +40,11 @@ describe('ESGeoGridSource', () => { {} ); - const getFieldMeta = async (field: IField) => { - return { - field: field.getName(), - label: await field.getLabel(), - type: await field.getDataType(), - }; - }; - - it('getMetricFields should remove incomplete metric aggregations.', async () => { - const fields = await geogridSource.getFields(); - const fieldsMeta = await Promise.all(fields.map(getFieldMeta)); - expect( - _.isEqual(fieldsMeta, [ - { - type: 'number', - field: 'sum_of_myFieldGettingSummed', - label: 'my custom label', - }, - { - type: 'number', - label: 'count', - field: 'doc_count', - }, - ]) - ).toEqual(true); + it('should echo gridResoltuion', () => { + expect(geogridSource.getGridResolution()).toBe(GRID_RESOLUTION.COARSE); }); - it('getFields should return getMetricFields', async () => { - const fields = await geogridSource.getFields(); - const metrics = await geogridSource.getMetricFields(); - const fieldsMeta = await Promise.all(fields.map(getFieldMeta)); - const metricFieldsMeta = await Promise.all(metrics.map(getFieldMeta)); - - expect(_.isEqual(fieldsMeta, metricFieldsMeta)).toEqual(true); + it('should clamp geo-grid derived zoom to max geotile level supported by ES', () => { + expect(geogridSource.getGeoGridPrecision(29)).toBe(29); }); }); diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.test.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.test.js index 549176dd7aa48..890b1e3aaac1f 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.test.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.test.js @@ -5,7 +5,6 @@ */ import { ESTermSource, extractPropertiesMap } from './es_term_source'; -import _ from 'lodash'; jest.mock('ui/new_platform'); jest.mock('../vector_layer', () => {}); @@ -32,63 +31,30 @@ const metricExamples = [ ]; describe('getMetricFields', () => { - it('should add default "count" metric when no metrics are provided', async () => { + it('should override name and label of count metric', async () => { const source = new ESTermSource({ indexPatternTitle: indexPatternTitle, term: termFieldName, }); const metrics = source.getMetricFields(); - expect(metrics.length).toBe(1); - - expect(metrics[0].getAggType()).toEqual('count'); expect(metrics[0].getName()).toEqual('__kbnjoin__count_groupby_myIndex.myTermField'); expect(await metrics[0].getLabel()).toEqual('Count of myIndex'); }); - it('should remove incomplete metric configurations', async () => { + it('should override name and label of sum metric', async () => { const source = new ESTermSource({ indexPatternTitle: indexPatternTitle, term: termFieldName, metrics: metricExamples, }); const metrics = source.getMetricFields(); - expect(metrics.length).toBe(2); - - expect(metrics[0].getAggType()).toEqual('sum'); - expect(metrics[0].getRootName()).toEqual(sumFieldName); expect(metrics[0].getName()).toEqual( '__kbnjoin__sum_of_myFieldGettingSummed_groupby_myIndex.myTermField' ); expect(await metrics[0].getLabel()).toEqual('my custom label'); - - expect(metrics[1].getAggType()).toEqual('count'); expect(metrics[1].getName()).toEqual('__kbnjoin__count_groupby_myIndex.myTermField'); expect(await metrics[1].getLabel()).toEqual('Count of myIndex'); }); - - it('should match getFields since term_source is agg_source', async () => { - const source = new ESTermSource({ - indexPatternTitle: indexPatternTitle, - term: termFieldName, - metrics: metricExamples, - }); - const metrics = source.getMetricFields(); - const fields = await source.getFields(); - - const getFieldMeta = async field => { - return { - aggType: field.getAggType(), - name: field.getName(), - label: await field.getLabel(), - esDoc: field.getRootName(), - }; - }; - - const metricsFieldMeta = await Promise.all(metrics.map(getFieldMeta)); - const fieldsFieldMeta = await Promise.all(fields.map(getFieldMeta)); - - expect(_.isEqual(metricsFieldMeta, fieldsFieldMeta)).toEqual(true); - }); }); describe('extractPropertiesMap', () => { From 6a3b99adcf12f7cb43c31b11ac6e1c87fca7ef7f Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 9 Mar 2020 10:53:11 -0400 Subject: [PATCH 29/35] remove agg type --- x-pack/legacy/plugins/maps/common/constants.ts | 1 + .../plugins/maps/public/layers/fields/es_agg_field.ts | 1 - .../maps/public/layers/fields/top_term_percentage_field.ts | 6 +++++- .../maps/public/layers/sources/es_agg_source.test.ts | 5 +---- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/x-pack/legacy/plugins/maps/common/constants.ts b/x-pack/legacy/plugins/maps/common/constants.ts index a4afae0b9e077..6c23541d64d58 100644 --- a/x-pack/legacy/plugins/maps/common/constants.ts +++ b/x-pack/legacy/plugins/maps/common/constants.ts @@ -125,6 +125,7 @@ export enum AGG_TYPE { SUM = 'sum', TERMS = 'terms', UNIQUE_COUNT = 'cardinality', + PERCENTAGE_KBN = 'percentage_kbn', } export enum RENDER_AS { diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.ts b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.ts index 00c6b4d26d2f2..9f08200442fea 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.ts +++ b/x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.ts @@ -21,7 +21,6 @@ import { TopTermPercentageField } from './top_term_percentage_field'; export interface IESAggField extends IField { getValueAggDsl(indexPattern: IndexPattern): unknown | null; getBucketCount(): number; - getAggType(): AGG_TYPE; } export class ESAggField implements IESAggField { diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/top_term_percentage_field.ts b/x-pack/legacy/plugins/maps/public/layers/fields/top_term_percentage_field.ts index cadf325652370..34e73f1c3fd38 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/top_term_percentage_field.ts +++ b/x-pack/legacy/plugins/maps/public/layers/fields/top_term_percentage_field.ts @@ -8,7 +8,7 @@ import { IESAggField } from './es_agg_field'; import { IVectorSource } from '../sources/vector_source'; // @ts-ignore import { TooltipProperty } from '../tooltips/tooltip_property'; -import { TOP_TERM_PERCENTAGE_SUFFIX } from '../../../common/constants'; +import { AGG_TYPE, TOP_TERM_PERCENTAGE_SUFFIX } from '../../../common/constants'; import { FIELD_ORIGIN } from '../../../common/constants'; export class TopTermPercentageField implements IESAggField { @@ -22,6 +22,10 @@ export class TopTermPercentageField implements IESAggField { return this._topTermAggField.getSource(); } + getAggType(): AGG_TYPE { + return AGG_TYPE.PERCENTAGE_KBN; + } + getOrigin(): FIELD_ORIGIN { return this._topTermAggField.getOrigin(); } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.test.ts b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.test.ts index 6dbc19f179a7a..32d1dff699cc8 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.test.ts +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.test.ts @@ -53,12 +53,10 @@ describe('getMetricFields', () => { const metrics = source.getMetricFields(); expect(metrics.length).toBe(2); - expect(metrics[0].getAggType()).toEqual('sum'); expect(metrics[0].getRootName()).toEqual(sumFieldName); expect(metrics[0].getName()).toEqual('sum_of_myFieldGettingSummed'); expect(await metrics[0].getLabel()).toEqual('my custom label'); - expect(metrics[1].getAggType()).toEqual('count'); expect(metrics[1].getName()).toEqual('doc_count'); expect(await metrics[1].getLabel()).toEqual('count'); }); @@ -69,9 +67,8 @@ describe('getMetricFields', () => { const fields = await source.getFields(); const getFieldMeta = async (field: IField) => { - const esAggField = field as IESAggField; + const esAggField = field as IESAggField; // this ensures we can downcast correctly. return { - aggType: esAggField.getAggType(), name: esAggField.getName(), label: await esAggField.getLabel(), esDoc: esAggField.getRootName(), From 7813255bbaee9132058ea6a730d3a7d447411946 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 9 Mar 2020 10:56:06 -0400 Subject: [PATCH 30/35] remove getAggType --- .../plugins/maps/public/layers/sources/es_agg_source.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.test.ts b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.test.ts index 32d1dff699cc8..848091586eb9c 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.test.ts +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_agg_source.test.ts @@ -43,7 +43,6 @@ describe('getMetricFields', () => { const metrics = source.getMetricFields(); expect(metrics.length).toBe(1); - expect(metrics[0].getAggType()).toEqual('count'); expect(metrics[0].getName()).toEqual('doc_count'); expect(await metrics[0].getLabel()).toEqual('count'); }); From 1c7391d88a7e48dce564be865481a7fa5957bb09 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 9 Mar 2020 10:58:28 -0400 Subject: [PATCH 31/35] add more boilerplate --- .../es_geo_grid_source/es_geo_grid_source.test.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.test.ts b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.test.ts index 2fcd64f292914..8fbebff49120f 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.test.ts +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.test.ts @@ -44,7 +44,13 @@ describe('ESGeoGridSource', () => { expect(geogridSource.getGridResolution()).toBe(GRID_RESOLUTION.COARSE); }); - it('should clamp geo-grid derived zoom to max geotile level supported by ES', () => { - expect(geogridSource.getGeoGridPrecision(29)).toBe(29); + describe('getGeoGridPrecision', () => { + it('should clamp geo-grid derived zoom to max geotile level supported by ES', () => { + expect(geogridSource.getGeoGridPrecision(29)).toBe(29); + }); + + it('should use heuristic to derive precision', () => { + expect(geogridSource.getGeoGridPrecision(10)).toBe(12); + }); }); }); From 02c725e253a139d554bd8c150cbcc0fd61a1014a Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 9 Mar 2020 11:02:49 -0400 Subject: [PATCH 32/35] remove cruft --- .../es_geo_grid_source.test.ts | 27 +++++-------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.test.ts b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.test.ts index 8fbebff49120f..727435c3cbfef 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.test.ts +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.test.ts @@ -7,32 +7,15 @@ jest.mock('../../../kibana_services', () => {}); jest.mock('ui/new_platform'); import { ESGeoGridSource } from './es_geo_grid_source'; -import { AGG_TYPE, ES_GEO_GRID, GRID_RESOLUTION, RENDER_AS } from '../../../../common/constants'; +import { ES_GEO_GRID, GRID_RESOLUTION, RENDER_AS } from '../../../../common/constants'; describe('ESGeoGridSource', () => { - const metricExamples = [ - { - type: AGG_TYPE.SUM, - field: 'myFieldGettingSummed', - label: 'my custom label', - }, - { - // metric config is invalid beause field is missing - type: AGG_TYPE.MAX, - }, - { - // metric config is valid because "count" metric does not need to provide field - type: AGG_TYPE.COUNT, - label: '', // should ignore empty label fields - }, - ]; - const geogridSource = new ESGeoGridSource( { id: 'foobar', indexPatternId: 'fooIp', geoField: 'bar', - metrics: metricExamples, + metrics: [], resolution: GRID_RESOLUTION.COARSE, type: ES_GEO_GRID, requestType: RENDER_AS.HEATMAP, @@ -40,8 +23,10 @@ describe('ESGeoGridSource', () => { {} ); - it('should echo gridResoltuion', () => { - expect(geogridSource.getGridResolution()).toBe(GRID_RESOLUTION.COARSE); + describe('getGridResolution', () => { + it('should echo gridResoltuion', () => { + expect(geogridSource.getGridResolution()).toBe(GRID_RESOLUTION.COARSE); + }); }); describe('getGeoGridPrecision', () => { From 47565638ca2bc9b68cb3eeb8da360f042db39af8 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 9 Mar 2020 11:20:57 -0400 Subject: [PATCH 33/35] remove aggtype --- .../maps/public/layers/fields/top_term_percentage_field.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/top_term_percentage_field.ts b/x-pack/legacy/plugins/maps/public/layers/fields/top_term_percentage_field.ts index 34e73f1c3fd38..cadf325652370 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/top_term_percentage_field.ts +++ b/x-pack/legacy/plugins/maps/public/layers/fields/top_term_percentage_field.ts @@ -8,7 +8,7 @@ import { IESAggField } from './es_agg_field'; import { IVectorSource } from '../sources/vector_source'; // @ts-ignore import { TooltipProperty } from '../tooltips/tooltip_property'; -import { AGG_TYPE, TOP_TERM_PERCENTAGE_SUFFIX } from '../../../common/constants'; +import { TOP_TERM_PERCENTAGE_SUFFIX } from '../../../common/constants'; import { FIELD_ORIGIN } from '../../../common/constants'; export class TopTermPercentageField implements IESAggField { @@ -22,10 +22,6 @@ export class TopTermPercentageField implements IESAggField { return this._topTermAggField.getSource(); } - getAggType(): AGG_TYPE { - return AGG_TYPE.PERCENTAGE_KBN; - } - getOrigin(): FIELD_ORIGIN { return this._topTermAggField.getOrigin(); } From e7153db33b7605cef49a2dab7aeadb4aa5a14e84 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 9 Mar 2020 11:37:30 -0400 Subject: [PATCH 34/35] formatting --- .../components/color/color_map_select.js | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js index ca50691ce105e..0d4cf322d2a40 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/color/color_map_select.js @@ -93,22 +93,28 @@ export class ColorMapSelect extends Component { return null; } + let colorStopEditor; if (this.props.colorMapType === COLOR_MAP_TYPE.ORDINAL) { - return ( + colorStopEditor = ( ); - } + } else + colorStopEditor = ( + + ); return ( - + + {colorStopEditor} + ); } @@ -154,12 +160,8 @@ export class ColorMapSelect extends Component { return ( {this._renderColorMapSelections()} - - - - {this._renderColorStopsInput()} - + {this._renderColorStopsInput()} ); } From a66bb34cdeb740b98e5df42aa2e62ed38cab127b Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 9 Mar 2020 11:39:11 -0400 Subject: [PATCH 35/35] remove from constants --- x-pack/legacy/plugins/maps/common/constants.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/legacy/plugins/maps/common/constants.ts b/x-pack/legacy/plugins/maps/common/constants.ts index 6c23541d64d58..a4afae0b9e077 100644 --- a/x-pack/legacy/plugins/maps/common/constants.ts +++ b/x-pack/legacy/plugins/maps/common/constants.ts @@ -125,7 +125,6 @@ export enum AGG_TYPE { SUM = 'sum', TERMS = 'terms', UNIQUE_COUNT = 'cardinality', - PERCENTAGE_KBN = 'percentage_kbn', } export enum RENDER_AS {