Skip to content

Commit

Permalink
[Maps] fix results trimmed tooltip message doubles feature count for …
Browse files Browse the repository at this point in the history
…line and polygon features (elastic#92932)

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
nreese and kibanamachine committed Mar 1, 2021
1 parent cc74c89 commit 455414f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export type VectorStyleRequestMeta = MapFilters & {

export type ESSearchSourceResponseMeta = {
areResultsTrimmed?: boolean;
resultsCount?: number;

// top hits meta
areEntitiesTrimmed?: boolean;
Expand Down
12 changes: 10 additions & 2 deletions x-pack/plugins/maps/public/actions/data_request_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ import uuid from 'uuid/v4';
import { multiPoint } from '@turf/helpers';
import { FeatureCollection } from 'geojson';
import { MapStoreState } from '../reducers/store';
import { LAYER_STYLE_TYPE, LAYER_TYPE, SOURCE_DATA_REQUEST_ID } from '../../common/constants';
import {
KBN_IS_CENTROID_FEATURE,
LAYER_STYLE_TYPE,
LAYER_TYPE,
SOURCE_DATA_REQUEST_ID,
} from '../../common/constants';
import {
getDataFilters,
getDataRequestDescriptor,
Expand Down Expand Up @@ -246,7 +251,10 @@ function endDataLoad(
const layer = getLayerById(layerId, getState());
const resultMeta: ResultMeta = {};
if (layer && layer.getType() === LAYER_TYPE.VECTOR) {
resultMeta.featuresCount = features.length;
const featuresWithoutCentroids = features.filter((feature) => {
return feature.properties ? !feature.properties[KBN_IS_CENTROID_FEATURE] : true;
});
resultMeta.featuresCount = featuresWithoutCentroids.length;
}

eventHandlers.onDataLoadEnd({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import rison from 'rison-node';

import { i18n } from '@kbn/i18n';
import { IFieldType, IndexPattern } from 'src/plugins/data/public';
import { FeatureCollection, GeoJsonProperties } from 'geojson';
import { GeoJsonProperties } from 'geojson';
import { AbstractESSource } from '../es_source';
import { getHttp, getSearchService } from '../../../kibana_services';
import { addFieldToDSL, getField, hitsToGeoJson } from '../../../../common/elasticsearch_util';
Expand Down Expand Up @@ -399,6 +399,7 @@ export class ESSearchSource extends AbstractESSource implements ITiledSingleLaye
return {
hits: resp.hits.hits.reverse(), // Reverse hits so top documents by sort are drawn on top
meta: {
resultsCount: resp.hits.hits.length,
areResultsTrimmed: resp.hits.total > resp.hits.hits.length,
},
};
Expand Down Expand Up @@ -589,11 +590,8 @@ export class ESSearchSource extends AbstractESSource implements ITiledSingleLaye
}

getSourceTooltipContent(sourceDataRequest?: DataRequest): SourceTooltipConfig {
const featureCollection: FeatureCollection | null = sourceDataRequest
? (sourceDataRequest.getData() as FeatureCollection)
: null;
const meta = sourceDataRequest ? sourceDataRequest.getMeta() : null;
if (!featureCollection || !meta) {
if (!meta) {
// no tooltip content needed when there is no feature collection or meta
return {
tooltipContent: null,
Expand Down Expand Up @@ -631,7 +629,7 @@ export class ESSearchSource extends AbstractESSource implements ITiledSingleLaye
return {
tooltipContent: i18n.translate('xpack.maps.esSearch.resultsTrimmedMsg', {
defaultMessage: `Results limited to first {count} documents.`,
values: { count: featureCollection.features.length },
values: { count: meta.resultsCount },
}),
areResultsTrimmed: true,
};
Expand All @@ -640,7 +638,7 @@ export class ESSearchSource extends AbstractESSource implements ITiledSingleLaye
return {
tooltipContent: i18n.translate('xpack.maps.esSearch.featureCountMsg', {
defaultMessage: `Found {count} documents.`,
values: { count: featureCollection.features.length },
values: { count: meta.resultsCount },
}),
areResultsTrimmed: false,
};
Expand Down

0 comments on commit 455414f

Please sign in to comment.