From 08c40955a41abb263a65f59c34fb2ce2e1905b0f Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Mon, 1 Mar 2021 14:11:18 -0700 Subject: [PATCH] [Maps] fix results trimmed tooltip message doubles feature count for line and polygon features (#92932) Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../data_request_descriptor_types.ts | 1 + .../maps/public/actions/data_request_actions.ts | 12 ++++++++++-- .../sources/es_search_source/es_search_source.tsx | 12 +++++------- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/x-pack/plugins/maps/common/descriptor_types/data_request_descriptor_types.ts b/x-pack/plugins/maps/common/descriptor_types/data_request_descriptor_types.ts index 5394d00ba16eb..dd01b7b596c30 100644 --- a/x-pack/plugins/maps/common/descriptor_types/data_request_descriptor_types.ts +++ b/x-pack/plugins/maps/common/descriptor_types/data_request_descriptor_types.ts @@ -75,6 +75,7 @@ export type VectorStyleRequestMeta = MapFilters & { export type ESSearchSourceResponseMeta = { areResultsTrimmed?: boolean; + resultsCount?: number; // top hits meta areEntitiesTrimmed?: boolean; diff --git a/x-pack/plugins/maps/public/actions/data_request_actions.ts b/x-pack/plugins/maps/public/actions/data_request_actions.ts index f5a09fdc8fffc..6b57da132e895 100644 --- a/x-pack/plugins/maps/public/actions/data_request_actions.ts +++ b/x-pack/plugins/maps/public/actions/data_request_actions.ts @@ -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, @@ -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({ diff --git a/x-pack/plugins/maps/public/classes/sources/es_search_source/es_search_source.tsx b/x-pack/plugins/maps/public/classes/sources/es_search_source/es_search_source.tsx index d5087664b399c..785b00c06dd54 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_search_source/es_search_source.tsx +++ b/x-pack/plugins/maps/public/classes/sources/es_search_source/es_search_source.tsx @@ -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'; @@ -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, }, }; @@ -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, @@ -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, }; @@ -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, };