Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Maps] top term percentage field property #59386

Merged
merged 17 commits into from
Mar 6, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions x-pack/legacy/plugins/maps/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ 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';
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,72 @@
/*
* 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 });
expect(fields.length).toBe(1);
});

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