Skip to content

Commit

Permalink
[Maps] top term percentage field property (elastic#59386)
Browse files Browse the repository at this point in the history
* [Maps] top term percentage property

* populate percentage in feature properties

* TS work

* clean up TS

* fix all type errors

* unit test for esAggFieldsFactory

* clean up

* i18n cleanup

* do not show decimal place for perentage

* fix jest expects

* fix eslint errors

* tslint errors

* handle empty top bucket aggregation

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
nreese and elasticmachine authored Mar 6, 2020
1 parent 5ff13ad commit 578137f
Show file tree
Hide file tree
Showing 23 changed files with 439 additions and 212 deletions.
10 changes: 6 additions & 4 deletions x-pack/legacy/plugins/maps/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ export const ES_SEARCH = 'ES_SEARCH';
export const ES_PEW_PEW = 'ES_PEW_PEW';
export const EMS_XYZ = 'EMS_XYZ'; // identifies a custom TMS source. Name is a little unfortunate.

export const FIELD_ORIGIN = {
SOURCE: 'source',
JOIN: 'join',
};
export enum FIELD_ORIGIN {
SOURCE = 'source',
JOIN = 'join',
}

export const SOURCE_DATA_ID_ORIGIN = 'source';
export const META_ID_ORIGIN_SUFFIX = 'meta';
Expand Down Expand Up @@ -139,6 +139,8 @@ export enum GRID_RESOLUTION {
MOST_FINE = 'MOST_FINE',
}

export const TOP_TERM_PERCENTAGE_SUFFIX = '__percentage';

export const COUNT_PROP_LABEL = i18n.translate('xpack.maps.aggs.defaultCountLabel', {
defaultMessage: 'count',
});
Expand Down
4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/maps/common/descriptor_types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export type AbstractESAggDescriptor = AbstractESSourceDescriptor & {
};

export type ESGeoGridSourceDescriptor = AbstractESAggDescriptor & {
requestType: RENDER_AS;
resolution: GRID_RESOLUTION;
requestType?: RENDER_AS;
resolution?: GRID_RESOLUTION;
};

export type ESSearchSourceDescriptor = AbstractESSourceDescriptor & {
Expand Down
96 changes: 0 additions & 96 deletions x-pack/legacy/plugins/maps/public/layers/fields/es_agg_field.js

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* 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.
*/

import { ESAggField, esAggFieldsFactory } from './es_agg_field';
import { AGG_TYPE, FIELD_ORIGIN } from '../../../common/constants';
import { IESAggSource } from '../sources/es_agg_source';
import { IIndexPattern } from 'src/plugins/data/public';

const mockIndexPattern = {
title: 'wildIndex',
fields: [
{
name: 'foo*',
},
],
} as IIndexPattern;

const mockEsAggSource = {
getAggKey: (aggType: AGG_TYPE, fieldName: string) => {
return 'agg_key';
},
getAggLabel: (aggType: AGG_TYPE, fieldName: string) => {
return 'agg_label';
},
getIndexPattern: async () => {
return mockIndexPattern;
},
} as IESAggSource;

const defaultParams = {
label: 'my agg field',
source: mockEsAggSource,
aggType: AGG_TYPE.COUNT,
origin: FIELD_ORIGIN.SOURCE,
};

describe('supportsFieldMeta', () => {
test('Non-counting aggregations should support field meta', () => {
const avgMetric = new ESAggField({ ...defaultParams, aggType: AGG_TYPE.AVG });
expect(avgMetric.supportsFieldMeta()).toBe(true);
const maxMetric = new ESAggField({ ...defaultParams, aggType: AGG_TYPE.MAX });
expect(maxMetric.supportsFieldMeta()).toBe(true);
const minMetric = new ESAggField({ ...defaultParams, aggType: AGG_TYPE.MIN });
expect(minMetric.supportsFieldMeta()).toBe(true);
const termsMetric = new ESAggField({ ...defaultParams, aggType: AGG_TYPE.TERMS });
expect(termsMetric.supportsFieldMeta()).toBe(true);
});

test('Counting aggregations should not support field meta', () => {
const countMetric = new ESAggField({ ...defaultParams, aggType: AGG_TYPE.COUNT });
expect(countMetric.supportsFieldMeta()).toBe(false);
const sumMetric = new ESAggField({ ...defaultParams, aggType: AGG_TYPE.SUM });
expect(sumMetric.supportsFieldMeta()).toBe(false);
const uniqueCountMetric = new ESAggField({ ...defaultParams, aggType: AGG_TYPE.UNIQUE_COUNT });
expect(uniqueCountMetric.supportsFieldMeta()).toBe(false);
});
});

describe('esAggFieldsFactory', () => {
test('Should only create top terms field when term field is not provided', () => {
const fields = esAggFieldsFactory(
{ type: AGG_TYPE.TERMS },
mockEsAggSource,
FIELD_ORIGIN.SOURCE
);
expect(fields.length).toBe(1);
});

test('Should create top terms and top terms percentage fields', () => {
const fields = esAggFieldsFactory(
{ type: AGG_TYPE.TERMS, field: 'myField' },
mockEsAggSource,
FIELD_ORIGIN.SOURCE
);
expect(fields.length).toBe(2);
});
});
Loading

0 comments on commit 578137f

Please sign in to comment.