[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>
This commit is contained in:
parent
a55d8b60ea
commit
08c40955a4
|
@ -75,6 +75,7 @@ export type VectorStyleRequestMeta = MapFilters & {
|
|||
|
||||
export type ESSearchSourceResponseMeta = {
|
||||
areResultsTrimmed?: boolean;
|
||||
resultsCount?: number;
|
||||
|
||||
// top hits meta
|
||||
areEntitiesTrimmed?: boolean;
|
||||
|
|
|
@ -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({
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue