From ccabd818f6c432b3308065a21ba29da2a0edd5f2 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Thu, 5 Dec 2019 14:51:44 -0700 Subject: [PATCH] review feedback --- .../maps/public/layers/fields/es_agg_field.js | 8 ++--- .../maps/public/layers/fields/es_doc_field.js | 32 +++++++++---------- .../update_source_editor.js | 4 +-- .../components/field_meta_options_popover.js | 14 +++----- .../legend/style_property_legend_row.js | 4 +-- .../maps/public/layers/util/can_skip_fetch.js | 4 +-- .../public/layers/util/is_metric_countable.js | 11 +++++++ 7 files changed, 38 insertions(+), 39 deletions(-) create mode 100644 x-pack/legacy/plugins/maps/public/layers/util/is_metric_countable.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 index d3e71de4aa5fb..af78e3a871802 100644 --- 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 @@ -4,15 +4,11 @@ * you may not use this file except in compliance with the Elastic License. */ - import { AbstractField } from './field'; -import { COUNT_AGG_TYPE, METRIC_TYPE } from '../../../common/constants'; +import { COUNT_AGG_TYPE } from '../../../common/constants'; +import { isMetricCountable } from '../util/is_metric_countable'; import { ESAggMetricTooltipProperty } from '../tooltips/es_aggmetric_tooltip_property'; -function isMetricCountable(aggType) { - return [METRIC_TYPE.COUNT, METRIC_TYPE.SUM, METRIC_TYPE.UNIQUE_COUNT].includes(aggType); -} - export class ESAggMetricField extends AbstractField { static type = 'ES_AGG'; 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 0209e34d6a9d1..ad15c6249e554 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 @@ -34,24 +34,24 @@ export class ESDocField extends AbstractField { async getFieldMetaRequest(/* config */) { const field = await this._getField(); - if (field.type === 'number' || field.type === 'date') { - const extendedStats = {}; - if (field.scripted) { - extendedStats.script = { - source: field.script, - lang: field.lang - }; - } else { - extendedStats.field = this._fieldName; - } - return { - [this._fieldName]: { - extended_stats: extendedStats - } - }; + if (field.type !== 'number' && field.type !== 'date') { + return null; } - return null; + const extendedStats = {}; + if (field.scripted) { + extendedStats.script = { + source: field.script, + lang: field.lang + }; + } else { + extendedStats.field = this._fieldName; + } + return { + [this._fieldName]: { + extended_stats: extendedStats + } + }; } } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/update_source_editor.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/update_source_editor.js index 1b446e1f2159a..cc1e53dc5cb3f 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/update_source_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/update_source_editor.js @@ -8,13 +8,13 @@ import React, { Fragment, Component } from 'react'; import { RENDER_AS } from './render_as'; import { MetricsEditor } from '../../../components/metrics_editor'; -import { METRIC_TYPE } from '../../../../common/constants'; import { indexPatternService } from '../../../kibana_services'; import { ResolutionEditor } from './resolution_editor'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; import { EuiSpacer, EuiTitle } from '@elastic/eui'; import { GlobalFilterCheckbox } from '../../../components/global_filter_checkbox'; +import { isMetricCountable } from '../../util/is_metric_countable'; export class UpdateSourceEditor extends Component { state = { @@ -72,7 +72,7 @@ export class UpdateSourceEditor extends Component { this.props.renderAs === RENDER_AS.HEATMAP ? metric => { //these are countable metrics, where blending heatmap color blobs make sense - return [METRIC_TYPE.COUNT, METRIC_TYPE.SUM, METRIC_TYPE.UNIQUE_COUNT].includes(metric.value); + return isMetricCountable(metric.value); } : null; const allowMultipleMetrics = this.props.renderAs !== RENDER_AS.HEATMAP; diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/field_meta_options_popover.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/field_meta_options_popover.js index 3b20dc0d28d3f..095740abe3dda 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/field_meta_options_popover.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/field_meta_options_popover.js @@ -55,20 +55,16 @@ export class FieldMetaOptionsPopover extends Component { }); } - _getFieldMetaOptions = () => { - return this.props.styleProperty.getFieldMetaOptions(); - } - _onIsEnabledChange = event => { this.props.onChange({ - ...this._getFieldMetaOptions(), + ...this.props.styleProperty.getFieldMetaOptions(), isEnabled: event.target.checked, }); }; _onSigmaChange = event => { this.props.onChange({ - ...this._getFieldMetaOptions(), + ...this.props.styleProperty.getFieldMetaOptions(), sigma: event.target.value, }); } @@ -94,7 +90,7 @@ export class FieldMetaOptionsPopover extends Component { > @@ -110,9 +106,9 @@ export class FieldMetaOptionsPopover extends Component { min={1} max={5} step={0.25} - value={this._getFieldMetaOptions().sigma} + value={this.props.styleProperty.getFieldMetaOptions().sigma} onChange={this._onSigmaChange} - disabled={!this._getFieldMetaOptions().isEnabled} + disabled={!this.props.styleProperty.getFieldMetaOptions().isEnabled} showTicks tickInterval={1} compressed diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/style_property_legend_row.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/style_property_legend_row.js index bd71698ffe5b5..7479bdb907286 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/style_property_legend_row.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/legend/style_property_legend_row.js @@ -77,9 +77,7 @@ export class StylePropertyLegendRow extends Component { return value; } - return this.props.style.isFieldMetaEnabled() - ? `${prefix} ${this._fieldValueFormatter(value)}` - : this._fieldValueFormatter(value); + return this.props.style.isFieldMetaEnabled() ? `${prefix} ${this._fieldValueFormatter(value)}` : this._fieldValueFormatter(value); } render() { diff --git a/x-pack/legacy/plugins/maps/public/layers/util/can_skip_fetch.js b/x-pack/legacy/plugins/maps/public/layers/util/can_skip_fetch.js index f9ae23fe891be..557a2bf869987 100644 --- a/x-pack/legacy/plugins/maps/public/layers/util/can_skip_fetch.js +++ b/x-pack/legacy/plugins/maps/public/layers/util/can_skip_fetch.js @@ -143,9 +143,7 @@ export function canSkipStyleMetaUpdate({ prevDataRequest, nextMeta }) { const updateDueToSourceQuery = !_.isEqual(prevMeta.sourceQuery, nextMeta.sourceQuery); const updateDueToIsTimeAware = nextMeta.isTimeAware !== prevMeta.isTimeAware; - const updateDueToTime = nextMeta.isTimeAware - ? !_.isEqual(prevMeta.timeFilters, nextMeta.timeFilters) - : false; + const updateDueToTime = nextMeta.isTimeAware ? !_.isEqual(prevMeta.timeFilters, nextMeta.timeFilters) : false; return !updateDueToFields && !updateDueToSourceQuery && !updateDueToIsTimeAware && !updateDueToTime; } diff --git a/x-pack/legacy/plugins/maps/public/layers/util/is_metric_countable.js b/x-pack/legacy/plugins/maps/public/layers/util/is_metric_countable.js new file mode 100644 index 0000000000000..54d8794b1e3cf --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/util/is_metric_countable.js @@ -0,0 +1,11 @@ +/* + * 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 { METRIC_TYPE } from '../../../common/constants'; + +export function isMetricCountable(aggType) { + return [METRIC_TYPE.COUNT, METRIC_TYPE.SUM, METRIC_TYPE.UNIQUE_COUNT].includes(aggType); +}