Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Maps] surface geo_shape clustering gold feature #68666

Merged
merged 12 commits into from Jun 12, 2020
3 changes: 3 additions & 0 deletions x-pack/plugins/maps/common/constants.ts
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
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) {
nreese marked this conversation as resolved.
Show resolved Hide resolved
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.

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
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