[Maps] only show fields that can be used in terms agg in join right field select (#35098) (#35358)

* [Maps] only show fields that can be used in terms agg in join right field select

* move filter to JoinExpression to avoid filtering metric fields

* use same filter on ES fields for left and right join fields
This commit is contained in:
Nathan Reese 2019-04-19 11:27:47 -06:00 committed by GitHub
parent 02c3478b77
commit 53fa62c346
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 29 additions and 22 deletions

View file

@ -92,11 +92,7 @@ export class Join extends Component {
}
this.setState({
rightFields: indexPattern.fields.filter(field => {
// Do not show multi fields as right join options
// since they do not have values in _source and exist for indexing only
return field.subType !== 'multi';
})
rightFields: indexPattern.fields
});
}
@ -109,16 +105,16 @@ export class Join extends Component {
}
async _loadLeftFields() {
let stringFields;
let leftFields;
try {
stringFields = await this.props.layer.getStringFields();
leftFields = await this.props.layer.getLeftJoinFields();
} catch (error) {
stringFields = [];
leftFields = [];
}
if (!this._isMounted) {
return;
}
this.setState({ leftFields: stringFields });
this.setState({ leftFields });
}
_onLeftFieldChange = (leftField) => {

View file

@ -18,6 +18,7 @@ import { i18n } from '@kbn/i18n';
import { IndexPatternSelect } from 'ui/index_patterns/components/index_pattern_select';
import { SingleFieldSelect } from '../../../../shared/components/single_field_select';
import { FormattedMessage } from '@kbn/i18n/react';
import { getTermsFields } from '../../../../shared/utils/get_terms_fields';
import {
indexPatternService,
@ -154,7 +155,7 @@ export class JoinExpression extends Component {
value={this.props.rightValue}
onChange={this.props.onRightFieldChange}
filterField={filterStringOrNumberFields}
fields={this.props.rightFields}
fields={getTermsFields(this.props.rightFields)}
isClearable={false}
/>
</EuiFormRow>

View file

@ -105,7 +105,7 @@ export class EMSFileSource extends AbstractVectorSource {
}
async getStringFields() {
async getLeftJoinFields() {
const emsVectorFileMeta = await this._getEmsVectorFileMeta();
return emsVectorFileMeta.fields.map(f => {
return { name: f.name, label: f.description };

View file

@ -16,6 +16,7 @@ import { ES_SEARCH } from '../../../../../common/constants';
import { i18n } from '@kbn/i18n';
import { getDataSourceLabel } from '../../../../../common/i18n_getters';
import { ESTooltipProperty } from '../../tooltips/es_tooltip_property';
import { getTermsFields } from '../../../utils/get_terms_fields';
import { DEFAULT_ES_DOC_LIMIT, DEFAULT_FILTER_BY_MAP_BOUNDS } from './constants';
@ -188,13 +189,11 @@ export class ESSearchSource extends AbstractESSource {
return _.get(this._descriptor, 'filterByMapBounds', false);
}
async getStringFields() {
async getLeftJoinFields() {
const indexPattern = await this._getIndexPattern();
const stringFields = indexPattern.fields.filter(field => {
return field.type === 'string' && field.subType !== 'multi';
});
return stringFields.map(stringField => {
return { name: stringField.name, label: stringField.name };
});
return getTermsFields(indexPattern.fields)
.map(field => {
return { name: field.name, label: field.name };
});
}
}

View file

@ -85,7 +85,7 @@ export class KibanaRegionmapSource extends AbstractVectorSource {
};
}
async getStringFields() {
async getLeftJoinFields() {
const vectorFileMeta = await this._getVectorFileMeta();
return vectorFileMeta.fields.map(f => {
return { name: f.name, label: f.description };

View file

@ -83,7 +83,7 @@ export class AbstractVectorSource extends AbstractSource {
return [];
}
async getStringFields() {
async getLeftJoinFields() {
return [];
}

View file

@ -116,8 +116,8 @@ export class VectorLayer extends AbstractLayer {
return this._getBoundsBasedOnData();
}
async getStringFields() {
return await this._source.getStringFields();
async getLeftJoinFields() {
return await this._source.getLeftJoinFields();
}
async getSourceName() {

View file

@ -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.
*/
export function getTermsFields(fields) {
return fields.filter(field => {
return field.aggregatable && ['number', 'boolean', 'date', 'ip', 'string'].includes(field.type);
});
}