[Maps] display metric tooltips for grid source the same as for joins (#31621) (#31755)

This commit is contained in:
Thomas Neirynck 2019-02-21 18:09:46 -05:00 committed by GitHub
parent fd286bce11
commit 78d58324de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 87 additions and 78 deletions

View file

@ -7,6 +7,7 @@
import { ESJoinSource } from '../sources/es_join_source';
import { VectorStyle } from '../styles/vector_style';
import { filterPropertiesForTooltip } from '../util';
export class LeftInnerJoin {
@ -46,12 +47,12 @@ export class LeftInnerJoin {
}
joinPropertiesToFeatureCollection(featureCollection, propertiesMap) {
const joinFields = this.getJoinFields();
const joinFields = this._rightSource.getMetricFields();
featureCollection.features.forEach(feature => {
// Clean up old join property values
joinFields.forEach(({ name }) => {
delete feature.properties[name];
const stylePropertyName = VectorStyle.getComputedFieldName(name);
joinFields.forEach(({ propertyKey }) => {
delete feature.properties[propertyKey];
const stylePropertyName = VectorStyle.getComputedFieldName(propertyKey);
delete feature.properties[stylePropertyName];
});
@ -78,19 +79,9 @@ export class LeftInnerJoin {
}
filterAndFormatPropertiesForTooltip(properties) {
const joinFields = this.getJoinFields();
const tooltipProps = {};
joinFields.forEach((joinField) => {
for (const key in properties) {
if (properties.hasOwnProperty(key)) {
if (joinField.name === key) {
tooltipProps[joinField.label] = properties[key];
}
}
}
});
const metricFields = this._rightSource.getMetricFields();
return filterPropertiesForTooltip(metricFields, properties);
return tooltipProps;
}
getIndexPatternIds() {

View file

@ -4,7 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
import _ from 'lodash';
import React from 'react';
import uuid from 'uuid/v4';
@ -22,8 +21,9 @@ import { CreateSourceEditor } from './create_source_editor';
import { UpdateSourceEditor } from './update_source_editor';
import { GRID_RESOLUTION } from '../../grid_resolution';
import { getGeohashPrecisionForZoom } from './zoom_to_precision';
import { filterPropertiesForTooltip } from '../../util';
const COUNT_PROP_LABEL = 'Count';
const COUNT_PROP_LABEL = 'count';
const COUNT_PROP_NAME = 'doc_count';
const aggSchemas = new Schemas([
@ -191,31 +191,13 @@ export class ESGeoGridSource extends AbstractESSource {
return true;
}
_getValidMetrics() {
const metrics = _.get(this._descriptor, 'metrics', []).filter(({ type, field }) => {
if (type === 'count') {
return true;
}
if (field) {
return true;
}
return false;
});
if (metrics.length === 0) {
metrics.push({ type: 'count' });
}
return metrics;
_formatMetricKey(metric) {
return metric.type !== 'count' ? `${metric.type}_of_${metric.field}` : COUNT_PROP_NAME;
}
getMetricFields() {
return this._getValidMetrics().map(metric => {
return {
...metric,
propertyKey: metric.type !== 'count' ? `${metric.type}_of_${metric.field}` : COUNT_PROP_NAME,
propertyLabel: metric.type !== 'count' ? `${metric.type} of ${metric.field}` : COUNT_PROP_LABEL,
};
});
_formatMetricLabel(metric) {
return metric.type !== 'count' ? `${metric.type} of ${metric.field}` : COUNT_PROP_LABEL;
}
_makeAggConfigs(precision) {
@ -313,13 +295,8 @@ export class ESGeoGridSource extends AbstractESSource {
}
async filterAndFormatProperties(properties) {
properties = await super.filterAndFormatProperties(properties);
const allProps = {};
for (const key in properties) {
if (key !== 'geohash_meta') {
allProps[key] = properties[key];
}
}
return allProps;
const metricFields = this.getMetricFields();
return filterPropertiesForTooltip(metricFields, properties);
}
}

View file

@ -82,6 +82,16 @@ export class ESJoinSource extends AbstractESSource {
return [this._descriptor.indexPatternId];
}
_formatMetricKey(metric) {
const metricKey = metric.type !== 'count' ? `${metric.type}_of_${metric.field}` : metric.type;
return `__kbnjoin__${metricKey}_groupby_${this._descriptor.indexPatternTitle}.${this._descriptor.term}`;
}
_formatMetricLabel(metric) {
const metricLabel = metric.type !== 'count' ? `${metric.type} ${metric.field}` : 'count';
return `${metricLabel} of ${this._descriptor.indexPatternTitle}:${this._descriptor.term}`;
}
async getPropertiesMap(searchFilters, leftSourceName, leftFieldName) {
if (!this.hasCompleteConfig()) {
@ -154,35 +164,6 @@ export class ESJoinSource extends AbstractESSource {
return `Elasticsearch terms aggregation request for ${joinStatement.join(' ')}`;
}
_getValidMetrics() {
const metrics = _.get(this._descriptor, 'metrics', []).filter(({ type, field }) => {
if (type === 'count') {
return true;
}
if (field) {
return true;
}
return false;
});
if (metrics.length === 0) {
metrics.push({ type: 'count' });
}
return metrics;
}
getMetricFields() {
return this._getValidMetrics().map(metric => {
const metricKey = metric.type !== 'count' ? `${metric.type}_of_${metric.field}` : metric.type;
const metricLabel = metric.type !== 'count' ? `${metric.type} ${metric.field}` : 'count';
return {
...metric,
propertyKey: `__kbnjoin__${metricKey}_groupby_${this._descriptor.indexPatternTitle}.${this._descriptor.term}`,
propertyLabel: `${metricLabel} of ${this._descriptor.indexPatternTitle}:${this._descriptor.term}`,
};
});
}
_makeAggConfigs() {
const metricAggConfigs = this.getMetricFields().map(metric => {
const metricAggConfig = {

View file

@ -66,6 +66,10 @@ export class ESSearchSource extends AbstractESSource {
}
}
getMetricFields() {
return [];
}
getFieldNames() {
return [
this._descriptor.geoField,

View file

@ -44,6 +44,43 @@ export class AbstractESSource extends AbstractVectorSource {
inspectorAdapters.requests.resetRequest(this._descriptor.id);
}
_getValidMetrics() {
const metrics = _.get(this._descriptor, 'metrics', []).filter(({ type, field }) => {
if (type === 'count') {
return true;
}
if (field) {
return true;
}
return false;
});
if (metrics.length === 0) {
metrics.push({ type: 'count' });
}
return metrics;
}
_formatMetricKey() {
throw new Error('should implement');
}
_formatMetricLabel() {
throw new Error('should implement');
}
getMetricFields() {
return this._getValidMetrics().map(metric => {
const metricKey = this._formatMetricKey(metric);
const metricLabel = this._formatMetricLabel(metric);
return {
...metric,
propertyKey: metricKey,
propertyLabel: metricLabel
};
});
}
async _runEsQuery(layerName, searchSource, requestDescription) {
try {
return await fetchSearchSourceAndRecordWithInspector({

View file

@ -90,7 +90,7 @@ export class AbstractVectorSource extends AbstractSource {
//todo :this is quick hack... should revise (should model proeprties explicitly in vector_layer
const props = {};
for (const key in properties) {
if (key.startsWith('__kbn')) {//these are system proeprties and should be ignored
if (key.startsWith('__kbn')) {//these are system properties and should be ignored
continue;
}
props[key] = properties[key];

View file

@ -0,0 +1,19 @@
/*
* 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 filterPropertiesForTooltip(metricFields, properties) {
const tooltipProps = {};
metricFields.forEach((field) => {
for (const key in properties) {
if (properties.hasOwnProperty(key)) {
if (field.propertyKey === key) {
tooltipProps[field.propertyLabel] = properties[key];
}
}
}
});
return tooltipProps;
}