Skip to content

Commit

Permalink
[Maps] surface geo_shape clustering gold feature (#68666)
Browse files Browse the repository at this point in the history
* [Maps] surface geo_shape clustering gold feature

* show gold in scaling form

* tslint

* more tslint changes

* fix jest test

* fix functional test by handling fields prop being undefined

* tslint fixes - that thing is slow to run

* review feedback

* update doc_values missing copy

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
nreese and elasticmachine authored Jun 12, 2020
1 parent ae8f6e3 commit 7d9378a
Show file tree
Hide file tree
Showing 12 changed files with 376 additions and 242 deletions.
3 changes: 3 additions & 0 deletions x-pack/plugins/maps/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ export enum ES_GEO_FIELD_TYPE {
GEO_SHAPE = 'geo_shape',
}

// Using strings instead of ES_GEO_FIELD_TYPE enum to avoid typeing errors where IFieldType.type is compared to value
export const ES_GEO_FIELD_TYPES = ['geo_point', 'geo_shape'];

export enum ES_SPATIAL_RELATIONS {
INTERSECTS = 'INTERSECTS',
DISJOINT = 'DISJOINT',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,25 @@ import _ from 'lodash';
import React, { Fragment, Component } from 'react';
import PropTypes from 'prop-types';

import { ES_GEO_FIELD_TYPES } from '../../../../common/constants';
import { SingleFieldSelect } from '../../../components/single_field_select';
import { getIndexPatternService, getIndexPatternSelectComponent } from '../../../kibana_services';
import { NoIndexPatternCallout } from '../../../components/no_index_pattern_callout';
import { i18n } from '@kbn/i18n';

import { EuiFormRow, EuiSpacer } from '@elastic/eui';
import { getAggregatableGeoFieldTypes, getFieldsWithGeoTileAgg } from '../../../index_pattern_util';
import {
getFieldsWithGeoTileAgg,
getGeoFields,
getGeoTileAggNotSupportedReason,
supportsGeoTileAgg,
} from '../../../index_pattern_util';
import { RenderAsSelect } from './render_as_select';

function doesNotSupportGeoTileAgg(field) {
return !supportsGeoTileAgg(field);
}

export class CreateSourceEditor extends Component {
static propTypes = {
onSourceConfigChange: PropTypes.func.isRequired,
Expand Down Expand Up @@ -87,9 +97,9 @@ export class CreateSourceEditor extends Component {
});

//make default selection
const geoFields = getFieldsWithGeoTileAgg(indexPattern.fields);
if (geoFields[0]) {
this._onGeoFieldSelect(geoFields[0].name);
const geoFieldsWithGeoTileAgg = getFieldsWithGeoTileAgg(indexPattern.fields);
if (geoFieldsWithGeoTileAgg[0]) {
this._onGeoFieldSelect(geoFieldsWithGeoTileAgg[0].name);
}
}, 300);

Expand Down Expand Up @@ -141,10 +151,10 @@ export class CreateSourceEditor extends Component {
value={this.state.geoField}
onChange={this._onGeoFieldSelect}
fields={
this.state.indexPattern
? getFieldsWithGeoTileAgg(this.state.indexPattern.fields)
: undefined
this.state.indexPattern ? getGeoFields(this.state.indexPattern.fields) : undefined
}
isFieldDisabled={doesNotSupportGeoTileAgg}
getFieldDisabledReason={getGeoTileAggNotSupportedReason}
/>
</EuiFormRow>
);
Expand Down Expand Up @@ -176,7 +186,7 @@ export class CreateSourceEditor extends Component {
placeholder={i18n.translate('xpack.maps.source.esGeoGrid.indexPatternPlaceholder', {
defaultMessage: 'Select index pattern',
})}
fieldTypes={getAggregatableGeoFieldTypes()}
fieldTypes={ES_GEO_FIELD_TYPES}
onNoIndexPatterns={this._onNoIndexPatterns}
/>
</EuiFormRow>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,15 @@ import { SingleFieldSelect } from '../../../components/single_field_select';
import { getIndexPatternService, getIndexPatternSelectComponent } from '../../../kibana_services';
import { NoIndexPatternCallout } from '../../../components/no_index_pattern_callout';
import { i18n } from '@kbn/i18n';
import { ES_GEO_FIELD_TYPE, SCALING_TYPES } from '../../../../common/constants';
import { ES_GEO_FIELD_TYPES, SCALING_TYPES } from '../../../../common/constants';
import { DEFAULT_FILTER_BY_MAP_BOUNDS } from './constants';
import { indexPatterns } from '../../../../../../../src/plugins/data/public';
import { ScalingForm } from './scaling_form';
import { getTermsFields, supportsGeoTileAgg } from '../../../index_pattern_util';

function getGeoFields(fields) {
return fields.filter((field) => {
return (
!indexPatterns.isNestedField(field) &&
[ES_GEO_FIELD_TYPE.GEO_POINT, ES_GEO_FIELD_TYPE.GEO_SHAPE].includes(field.type)
);
});
}
import {
getGeoFields,
getTermsFields,
getGeoTileAggNotSupportedReason,
supportsGeoTileAgg,
} from '../../../index_pattern_util';

function doesGeoFieldSupportGeoTileAgg(indexPattern, geoFieldName) {
return indexPattern ? supportsGeoTileAgg(indexPattern.fields.getByName(geoFieldName)) : false;
Expand Down Expand Up @@ -217,6 +212,13 @@ export class CreateSourceEditor extends Component {
this.state.indexPattern,
this.state.geoFieldName
)}
clusteringDisabledReason={
this.state.indexPattern
? getGeoTileAggNotSupportedReason(
this.state.indexPattern.fields.getByName(this.state.geoFieldName)
)
: null
}
termFields={getTermsFields(this.state.indexPattern.fields)}
topHitsSplitField={this.state.topHitsSplitField}
topHitsSize={this.state.topHitsSize}
Expand Down Expand Up @@ -260,7 +262,7 @@ export class CreateSourceEditor extends Component {
defaultMessage: 'Select index pattern',
}
)}
fieldTypes={[ES_GEO_FIELD_TYPE.GEO_POINT, ES_GEO_FIELD_TYPE.GEO_SHAPE]}
fieldTypes={ES_GEO_FIELD_TYPES}
onNoIndexPatterns={this._onNoIndexPatterns}
/>
</EuiFormRow>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,14 @@ test('should render', async () => {
expect(component).toMatchSnapshot();
});

test('should not render clusters option when clustering is not supported', async () => {
const component = shallow(<ScalingForm {...defaultProps} supportsClustering={false} />);
test('should disable clusters option when clustering is not supported', async () => {
const component = shallow(
<ScalingForm
{...defaultProps}
supportsClustering={false}
clusteringDisabledReason="Simulated clustering disabled"
/>
);

expect(component).toMatchSnapshot();
});
Expand Down
Loading

0 comments on commit 7d9378a

Please sign in to comment.