Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nreese committed Dec 5, 2019
1 parent cc8b671 commit ccabd81
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
32 changes: 16 additions & 16 deletions x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
Expand All @@ -94,7 +90,7 @@ export class FieldMetaOptionsPopover extends Component {
>
<EuiSwitch
label={getIsEnableToggleLabel(this.props.styleProperty.getStyleName())}
checked={this._getFieldMetaOptions().isEnabled}
checked={this.props.styleProperty.getFieldMetaOptions().isEnabled}
onChange={this._onIsEnabledChange}
compressed
/>
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit ccabd81

Please sign in to comment.