mirror of
https://github.com/elastic/kibana.git
synced 2025-04-25 02:09:32 -04:00
[data.search.aggs] Remove fieldFormats from AggConfig & AggConfigs (#69762)
This commit is contained in:
parent
462bf1520f
commit
851e7ff9b8
66 changed files with 203 additions and 578 deletions
|
@ -17,7 +17,8 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { IFieldFormatsRegistry } from '.';
|
import { identity } from 'lodash';
|
||||||
|
import { FieldFormat, IFieldFormatsRegistry } from '.';
|
||||||
|
|
||||||
export const fieldFormatsMock: IFieldFormatsRegistry = {
|
export const fieldFormatsMock: IFieldFormatsRegistry = {
|
||||||
getByFieldType: jest.fn(),
|
getByFieldType: jest.fn(),
|
||||||
|
@ -35,6 +36,9 @@ export const fieldFormatsMock: IFieldFormatsRegistry = {
|
||||||
init: jest.fn(),
|
init: jest.fn(),
|
||||||
register: jest.fn(),
|
register: jest.fn(),
|
||||||
parseDefaultTypeMap: jest.fn(),
|
parseDefaultTypeMap: jest.fn(),
|
||||||
deserialize: jest.fn(),
|
deserialize: jest.fn().mockImplementation(() => {
|
||||||
|
const DefaultFieldFormat = FieldFormat.from(identity);
|
||||||
|
return new DefaultFieldFormat();
|
||||||
|
}),
|
||||||
getTypeWithoutMetaParams: jest.fn(),
|
getTypeWithoutMetaParams: jest.fn(),
|
||||||
};
|
};
|
||||||
|
|
|
@ -184,10 +184,7 @@ export class DataPublicPlugin implements Plugin<DataPublicPluginSetup, DataPubli
|
||||||
const query = this.queryService.start(savedObjects);
|
const query = this.queryService.start(savedObjects);
|
||||||
setQueryService(query);
|
setQueryService(query);
|
||||||
|
|
||||||
const search = this.searchService.start(core, {
|
const search = this.searchService.start(core, { indexPatterns });
|
||||||
indexPatterns,
|
|
||||||
fieldFormats,
|
|
||||||
});
|
|
||||||
setSearchService(search);
|
setSearchService(search);
|
||||||
|
|
||||||
uiActions.addTriggerAction(
|
uiActions.addTriggerAction(
|
||||||
|
|
|
@ -25,31 +25,23 @@ import { AggType } from './agg_type';
|
||||||
import { AggTypesRegistryStart } from './agg_types_registry';
|
import { AggTypesRegistryStart } from './agg_types_registry';
|
||||||
import { mockDataServices, mockAggTypesRegistry } from './test_helpers';
|
import { mockDataServices, mockAggTypesRegistry } from './test_helpers';
|
||||||
import { MetricAggType } from './metrics/metric_agg_type';
|
import { MetricAggType } from './metrics/metric_agg_type';
|
||||||
import {
|
import { IndexPattern, IIndexPatternFieldList } from '../../index_patterns';
|
||||||
Field as IndexPatternField,
|
|
||||||
IndexPattern,
|
|
||||||
IIndexPatternFieldList,
|
|
||||||
} from '../../index_patterns';
|
|
||||||
import { stubIndexPatternWithFields } from '../../../public/stubs';
|
import { stubIndexPatternWithFields } from '../../../public/stubs';
|
||||||
import { FieldFormatsStart } from '../../field_formats';
|
|
||||||
import { fieldFormatsServiceMock } from '../../field_formats/mocks';
|
|
||||||
|
|
||||||
describe('AggConfig', () => {
|
describe('AggConfig', () => {
|
||||||
let indexPattern: IndexPattern;
|
let indexPattern: IndexPattern;
|
||||||
let typesRegistry: AggTypesRegistryStart;
|
let typesRegistry: AggTypesRegistryStart;
|
||||||
let fieldFormats: FieldFormatsStart;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.restoreAllMocks();
|
jest.restoreAllMocks();
|
||||||
mockDataServices();
|
mockDataServices();
|
||||||
fieldFormats = fieldFormatsServiceMock.createStartContract();
|
|
||||||
indexPattern = stubIndexPatternWithFields as IndexPattern;
|
indexPattern = stubIndexPatternWithFields as IndexPattern;
|
||||||
typesRegistry = mockAggTypesRegistry();
|
typesRegistry = mockAggTypesRegistry();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#toDsl', () => {
|
describe('#toDsl', () => {
|
||||||
it('calls #write()', () => {
|
it('calls #write()', () => {
|
||||||
const ac = new AggConfigs(indexPattern, [], { typesRegistry, fieldFormats });
|
const ac = new AggConfigs(indexPattern, [], { typesRegistry });
|
||||||
const configStates = {
|
const configStates = {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
type: 'date_histogram',
|
type: 'date_histogram',
|
||||||
|
@ -64,7 +56,7 @@ describe('AggConfig', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses the type name as the agg name', () => {
|
it('uses the type name as the agg name', () => {
|
||||||
const ac = new AggConfigs(indexPattern, [], { typesRegistry, fieldFormats });
|
const ac = new AggConfigs(indexPattern, [], { typesRegistry });
|
||||||
const configStates = {
|
const configStates = {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
type: 'date_histogram',
|
type: 'date_histogram',
|
||||||
|
@ -79,7 +71,7 @@ describe('AggConfig', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses the params from #write() output as the agg params', () => {
|
it('uses the params from #write() output as the agg params', () => {
|
||||||
const ac = new AggConfigs(indexPattern, [], { typesRegistry, fieldFormats });
|
const ac = new AggConfigs(indexPattern, [], { typesRegistry });
|
||||||
const configStates = {
|
const configStates = {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
type: 'date_histogram',
|
type: 'date_histogram',
|
||||||
|
@ -109,7 +101,7 @@ describe('AggConfig', () => {
|
||||||
params: {},
|
params: {},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry, fieldFormats });
|
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry });
|
||||||
|
|
||||||
const histoConfig = ac.byName('date_histogram')[0];
|
const histoConfig = ac.byName('date_histogram')[0];
|
||||||
const avgConfig = ac.byName('avg')[0];
|
const avgConfig = ac.byName('avg')[0];
|
||||||
|
@ -219,8 +211,8 @@ describe('AggConfig', () => {
|
||||||
|
|
||||||
testsIdentical.forEach((configState, index) => {
|
testsIdentical.forEach((configState, index) => {
|
||||||
it(`identical aggregations (${index})`, () => {
|
it(`identical aggregations (${index})`, () => {
|
||||||
const ac1 = new AggConfigs(indexPattern, configState, { typesRegistry, fieldFormats });
|
const ac1 = new AggConfigs(indexPattern, configState, { typesRegistry });
|
||||||
const ac2 = new AggConfigs(indexPattern, configState, { typesRegistry, fieldFormats });
|
const ac2 = new AggConfigs(indexPattern, configState, { typesRegistry });
|
||||||
expect(ac1.jsonDataEquals(ac2.aggs)).toBe(true);
|
expect(ac1.jsonDataEquals(ac2.aggs)).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -260,8 +252,8 @@ describe('AggConfig', () => {
|
||||||
|
|
||||||
testsIdenticalDifferentOrder.forEach((test, index) => {
|
testsIdenticalDifferentOrder.forEach((test, index) => {
|
||||||
it(`identical aggregations (${index}) - init json is in different order`, () => {
|
it(`identical aggregations (${index}) - init json is in different order`, () => {
|
||||||
const ac1 = new AggConfigs(indexPattern, test.config1, { typesRegistry, fieldFormats });
|
const ac1 = new AggConfigs(indexPattern, test.config1, { typesRegistry });
|
||||||
const ac2 = new AggConfigs(indexPattern, test.config2, { typesRegistry, fieldFormats });
|
const ac2 = new AggConfigs(indexPattern, test.config2, { typesRegistry });
|
||||||
expect(ac1.jsonDataEquals(ac2.aggs)).toBe(true);
|
expect(ac1.jsonDataEquals(ac2.aggs)).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -325,8 +317,8 @@ describe('AggConfig', () => {
|
||||||
|
|
||||||
testsDifferent.forEach((test, index) => {
|
testsDifferent.forEach((test, index) => {
|
||||||
it(`different aggregations (${index})`, () => {
|
it(`different aggregations (${index})`, () => {
|
||||||
const ac1 = new AggConfigs(indexPattern, test.config1, { typesRegistry, fieldFormats });
|
const ac1 = new AggConfigs(indexPattern, test.config1, { typesRegistry });
|
||||||
const ac2 = new AggConfigs(indexPattern, test.config2, { typesRegistry, fieldFormats });
|
const ac2 = new AggConfigs(indexPattern, test.config2, { typesRegistry });
|
||||||
expect(ac1.jsonDataEquals(ac2.aggs)).toBe(false);
|
expect(ac1.jsonDataEquals(ac2.aggs)).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -334,7 +326,7 @@ describe('AggConfig', () => {
|
||||||
|
|
||||||
describe('#serialize', () => {
|
describe('#serialize', () => {
|
||||||
it('includes the aggs id, params, type and schema', () => {
|
it('includes the aggs id, params, type and schema', () => {
|
||||||
const ac = new AggConfigs(indexPattern, [], { typesRegistry, fieldFormats });
|
const ac = new AggConfigs(indexPattern, [], { typesRegistry });
|
||||||
const configStates = {
|
const configStates = {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
type: 'date_histogram',
|
type: 'date_histogram',
|
||||||
|
@ -365,8 +357,8 @@ describe('AggConfig', () => {
|
||||||
params: {},
|
params: {},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
const ac1 = new AggConfigs(indexPattern, configStates, { typesRegistry, fieldFormats });
|
const ac1 = new AggConfigs(indexPattern, configStates, { typesRegistry });
|
||||||
const ac2 = new AggConfigs(indexPattern, configStates, { typesRegistry, fieldFormats });
|
const ac2 = new AggConfigs(indexPattern, configStates, { typesRegistry });
|
||||||
|
|
||||||
// this relies on the assumption that js-engines consistently loop over properties in insertion order.
|
// this relies on the assumption that js-engines consistently loop over properties in insertion order.
|
||||||
// most likely the case, but strictly speaking not guaranteed by the JS and JSON specifications.
|
// most likely the case, but strictly speaking not guaranteed by the JS and JSON specifications.
|
||||||
|
@ -394,7 +386,7 @@ describe('AggConfig', () => {
|
||||||
params: { field: 'machine.os.keyword' },
|
params: { field: 'machine.os.keyword' },
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry, fieldFormats });
|
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry });
|
||||||
|
|
||||||
expect(ac.aggs.map((agg) => agg.toSerializedFieldFormat())).toMatchInlineSnapshot(`
|
expect(ac.aggs.map((agg) => agg.toSerializedFieldFormat())).toMatchInlineSnapshot(`
|
||||||
Array [
|
Array [
|
||||||
|
@ -456,7 +448,7 @@ describe('AggConfig', () => {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry, fieldFormats });
|
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry });
|
||||||
|
|
||||||
expect(ac.aggs.map((agg) => agg.toSerializedFieldFormat())).toMatchInlineSnapshot(`
|
expect(ac.aggs.map((agg) => agg.toSerializedFieldFormat())).toMatchInlineSnapshot(`
|
||||||
Array [
|
Array [
|
||||||
|
@ -478,20 +470,8 @@ describe('AggConfig', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#toExpressionAst', () => {
|
describe('#toExpressionAst', () => {
|
||||||
beforeEach(() => {
|
|
||||||
fieldFormats.getDefaultInstance = (() => ({
|
|
||||||
getConverterFor: (t?: string) => t || identity,
|
|
||||||
})) as any;
|
|
||||||
indexPattern.fields.getByName = (name) =>
|
|
||||||
({
|
|
||||||
format: {
|
|
||||||
getConverterFor: (t?: string) => t || identity,
|
|
||||||
},
|
|
||||||
} as IndexPatternField);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('works with primitive param types', () => {
|
it('works with primitive param types', () => {
|
||||||
const ac = new AggConfigs(indexPattern, [], { typesRegistry, fieldFormats });
|
const ac = new AggConfigs(indexPattern, [], { typesRegistry });
|
||||||
const configStates = {
|
const configStates = {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
type: 'terms',
|
type: 'terms',
|
||||||
|
@ -540,7 +520,7 @@ describe('AggConfig', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('creates a subexpression for params of type "agg"', () => {
|
it('creates a subexpression for params of type "agg"', () => {
|
||||||
const ac = new AggConfigs(indexPattern, [], { typesRegistry, fieldFormats });
|
const ac = new AggConfigs(indexPattern, [], { typesRegistry });
|
||||||
const configStates = {
|
const configStates = {
|
||||||
type: 'terms',
|
type: 'terms',
|
||||||
params: {
|
params: {
|
||||||
|
@ -616,7 +596,7 @@ describe('AggConfig', () => {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const ac = new AggConfigs(indexPattern, [], { typesRegistry, fieldFormats });
|
const ac = new AggConfigs(indexPattern, [], { typesRegistry });
|
||||||
const configStates = {
|
const configStates = {
|
||||||
type: 'range',
|
type: 'range',
|
||||||
params: {
|
params: {
|
||||||
|
@ -647,7 +627,7 @@ describe('AggConfig', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('stringifies any other params which are an object', () => {
|
it('stringifies any other params which are an object', () => {
|
||||||
const ac = new AggConfigs(indexPattern, [], { typesRegistry, fieldFormats });
|
const ac = new AggConfigs(indexPattern, [], { typesRegistry });
|
||||||
const configStates = {
|
const configStates = {
|
||||||
type: 'terms',
|
type: 'terms',
|
||||||
params: {
|
params: {
|
||||||
|
@ -662,7 +642,7 @@ describe('AggConfig', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`returns undefined if an expressionName doesn't exist on the agg type`, () => {
|
it(`returns undefined if an expressionName doesn't exist on the agg type`, () => {
|
||||||
const ac = new AggConfigs(indexPattern, [], { typesRegistry, fieldFormats });
|
const ac = new AggConfigs(indexPattern, [], { typesRegistry });
|
||||||
const configStates = {
|
const configStates = {
|
||||||
type: 'unknown type',
|
type: 'unknown type',
|
||||||
params: {},
|
params: {},
|
||||||
|
@ -676,7 +656,7 @@ describe('AggConfig', () => {
|
||||||
let aggConfig: AggConfig;
|
let aggConfig: AggConfig;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const ac = new AggConfigs(indexPattern, [], { typesRegistry, fieldFormats });
|
const ac = new AggConfigs(indexPattern, [], { typesRegistry });
|
||||||
aggConfig = ac.createAggConfig({ type: 'count' } as CreateAggConfigParams);
|
aggConfig = ac.createAggConfig({ type: 'count' } as CreateAggConfigParams);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -702,85 +682,4 @@ describe('AggConfig', () => {
|
||||||
expect(label).toBe('');
|
expect(label).toBe('');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#fieldFormatter - custom getFormat handler', () => {
|
|
||||||
it('returns formatter from getFormat handler', () => {
|
|
||||||
const ac = new AggConfigs(indexPattern, [], { typesRegistry, fieldFormats });
|
|
||||||
const configStates = {
|
|
||||||
enabled: true,
|
|
||||||
type: 'count',
|
|
||||||
schema: 'metric',
|
|
||||||
params: { field: '@timestamp' },
|
|
||||||
};
|
|
||||||
const aggConfig = ac.createAggConfig(configStates);
|
|
||||||
|
|
||||||
const fieldFormatter = aggConfig.fieldFormatter();
|
|
||||||
expect(fieldFormatter).toBeDefined();
|
|
||||||
expect(fieldFormatter('text')).toBe('text');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// TODO: Converting these field formatter tests from browser tests to unit
|
|
||||||
// tests makes them much less helpful due to the extensive use of mocking.
|
|
||||||
// We should revisit these and rewrite them into something more useful.
|
|
||||||
describe('#fieldFormatter - no custom getFormat handler', () => {
|
|
||||||
let aggConfig: AggConfig;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
fieldFormats.getDefaultInstance = (() => ({
|
|
||||||
getConverterFor: (t?: string) => t || identity,
|
|
||||||
})) as any;
|
|
||||||
indexPattern.fields.getByName = (name) =>
|
|
||||||
({
|
|
||||||
format: {
|
|
||||||
getConverterFor: (t?: string) => t || identity,
|
|
||||||
},
|
|
||||||
} as IndexPatternField);
|
|
||||||
|
|
||||||
const configStates = {
|
|
||||||
enabled: true,
|
|
||||||
type: 'histogram',
|
|
||||||
schema: 'bucket',
|
|
||||||
params: {
|
|
||||||
field: 'bytes',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const ac = new AggConfigs(indexPattern, [configStates], { typesRegistry, fieldFormats });
|
|
||||||
aggConfig = ac.createAggConfig(configStates);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns the field's formatter", () => {
|
|
||||||
aggConfig.params.field = {
|
|
||||||
format: {
|
|
||||||
getConverterFor: (t?: string) => t || identity,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
expect(aggConfig.fieldFormatter().toString()).toBe(
|
|
||||||
aggConfig.getField().format.getConverterFor().toString()
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('returns the string format if the field does not have a format', () => {
|
|
||||||
const agg = aggConfig;
|
|
||||||
agg.params.field = { type: 'number', format: null };
|
|
||||||
const fieldFormatter = agg.fieldFormatter();
|
|
||||||
expect(fieldFormatter).toBeDefined();
|
|
||||||
expect(fieldFormatter('text')).toBe('text');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('returns the string format if there is no field', () => {
|
|
||||||
const agg = aggConfig;
|
|
||||||
delete agg.params.field;
|
|
||||||
const fieldFormatter = agg.fieldFormatter();
|
|
||||||
expect(fieldFormatter).toBeDefined();
|
|
||||||
expect(fieldFormatter('text')).toBe('text');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('returns the html converter if "html" is passed in', () => {
|
|
||||||
const field = indexPattern.fields.getByName('bytes');
|
|
||||||
expect(aggConfig.fieldFormatter('html').toString()).toBe(
|
|
||||||
field!.format.getConverterFor('html').toString()
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -30,8 +30,6 @@ import { writeParams } from './agg_params';
|
||||||
import { IAggConfigs } from './agg_configs';
|
import { IAggConfigs } from './agg_configs';
|
||||||
import { FetchOptions } from '../fetch';
|
import { FetchOptions } from '../fetch';
|
||||||
import { ISearchSource } from '../search_source';
|
import { ISearchSource } from '../search_source';
|
||||||
import { FieldFormatsContentType, KBN_FIELD_TYPES } from '../../../common';
|
|
||||||
import { FieldFormatsStart } from '../../field_formats';
|
|
||||||
|
|
||||||
type State = string | number | boolean | null | undefined | SerializableState;
|
type State = string | number | boolean | null | undefined | SerializableState;
|
||||||
|
|
||||||
|
@ -52,10 +50,6 @@ export type AggConfigSerialized = Ensure<
|
||||||
SerializableState
|
SerializableState
|
||||||
>;
|
>;
|
||||||
|
|
||||||
export interface AggConfigDependencies {
|
|
||||||
fieldFormats: FieldFormatsStart;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type AggConfigOptions = Assign<AggConfigSerialized, { type: IAggType }>;
|
export type AggConfigOptions = Assign<AggConfigSerialized, { type: IAggType }>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -116,13 +110,8 @@ export class AggConfig {
|
||||||
private __type: IAggType;
|
private __type: IAggType;
|
||||||
private __typeDecorations: any;
|
private __typeDecorations: any;
|
||||||
private subAggs: AggConfig[] = [];
|
private subAggs: AggConfig[] = [];
|
||||||
private readonly fieldFormats: FieldFormatsStart;
|
|
||||||
|
|
||||||
constructor(
|
constructor(aggConfigs: IAggConfigs, opts: AggConfigOptions) {
|
||||||
aggConfigs: IAggConfigs,
|
|
||||||
opts: AggConfigOptions,
|
|
||||||
{ fieldFormats }: AggConfigDependencies
|
|
||||||
) {
|
|
||||||
this.aggConfigs = aggConfigs;
|
this.aggConfigs = aggConfigs;
|
||||||
this.id = String(opts.id || AggConfig.nextId(aggConfigs.aggs as any));
|
this.id = String(opts.id || AggConfig.nextId(aggConfigs.aggs as any));
|
||||||
this.enabled = typeof opts.enabled === 'boolean' ? opts.enabled : true;
|
this.enabled = typeof opts.enabled === 'boolean' ? opts.enabled : true;
|
||||||
|
@ -143,8 +132,6 @@ export class AggConfig {
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
this.__type = this.__type;
|
this.__type = this.__type;
|
||||||
|
|
||||||
this.fieldFormats = fieldFormats;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -433,24 +420,6 @@ export class AggConfig {
|
||||||
return this.aggConfigs.timeRange;
|
return this.aggConfigs.timeRange;
|
||||||
}
|
}
|
||||||
|
|
||||||
fieldFormatter(contentType?: FieldFormatsContentType, defaultFormat?: any) {
|
|
||||||
const format = this.type && this.type.getFormat(this);
|
|
||||||
|
|
||||||
if (format) {
|
|
||||||
return format.getConverterFor(contentType);
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.fieldOwnFormatter(contentType, defaultFormat);
|
|
||||||
}
|
|
||||||
|
|
||||||
fieldOwnFormatter(contentType?: FieldFormatsContentType, defaultFormat?: any) {
|
|
||||||
const field = this.getField();
|
|
||||||
let format = field && field.format;
|
|
||||||
if (!format) format = defaultFormat;
|
|
||||||
if (!format) format = this.fieldFormats.getDefaultInstance(KBN_FIELD_TYPES.STRING);
|
|
||||||
return format.getConverterFor(contentType);
|
|
||||||
}
|
|
||||||
|
|
||||||
fieldName() {
|
fieldName() {
|
||||||
const field = this.getField();
|
const field = this.getField();
|
||||||
return field ? field.name : '';
|
return field ? field.name : '';
|
||||||
|
|
|
@ -24,12 +24,10 @@ import { AggTypesRegistryStart } from './agg_types_registry';
|
||||||
import { mockDataServices, mockAggTypesRegistry } from './test_helpers';
|
import { mockDataServices, mockAggTypesRegistry } from './test_helpers';
|
||||||
import { Field as IndexPatternField, IndexPattern } from '../../index_patterns';
|
import { Field as IndexPatternField, IndexPattern } from '../../index_patterns';
|
||||||
import { stubIndexPattern, stubIndexPatternWithFields } from '../../../public/stubs';
|
import { stubIndexPattern, stubIndexPatternWithFields } from '../../../public/stubs';
|
||||||
import { fieldFormatsServiceMock } from '../../field_formats/mocks';
|
|
||||||
|
|
||||||
describe('AggConfigs', () => {
|
describe('AggConfigs', () => {
|
||||||
let indexPattern: IndexPattern;
|
let indexPattern: IndexPattern;
|
||||||
let typesRegistry: AggTypesRegistryStart;
|
let typesRegistry: AggTypesRegistryStart;
|
||||||
const fieldFormats = fieldFormatsServiceMock.createStartContract();
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
mockDataServices();
|
mockDataServices();
|
||||||
|
@ -47,7 +45,7 @@ describe('AggConfigs', () => {
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry, fieldFormats });
|
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry });
|
||||||
expect(ac.aggs).toHaveLength(1);
|
expect(ac.aggs).toHaveLength(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -72,7 +70,7 @@ describe('AggConfigs', () => {
|
||||||
];
|
];
|
||||||
|
|
||||||
const spy = jest.spyOn(AggConfig, 'ensureIds');
|
const spy = jest.spyOn(AggConfig, 'ensureIds');
|
||||||
new AggConfigs(indexPattern, configStates, { typesRegistry, fieldFormats });
|
new AggConfigs(indexPattern, configStates, { typesRegistry });
|
||||||
expect(spy).toHaveBeenCalledTimes(1);
|
expect(spy).toHaveBeenCalledTimes(1);
|
||||||
expect(spy.mock.calls[0]).toEqual([configStates]);
|
expect(spy.mock.calls[0]).toEqual([configStates]);
|
||||||
spy.mockRestore();
|
spy.mockRestore();
|
||||||
|
@ -94,20 +92,16 @@ describe('AggConfigs', () => {
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry, fieldFormats });
|
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry });
|
||||||
expect(ac.aggs).toHaveLength(2);
|
expect(ac.aggs).toHaveLength(2);
|
||||||
|
|
||||||
ac.createAggConfig(
|
ac.createAggConfig(
|
||||||
new AggConfig(
|
new AggConfig(ac, {
|
||||||
ac,
|
|
||||||
{
|
|
||||||
enabled: true,
|
enabled: true,
|
||||||
type: typesRegistry.get('terms'),
|
type: typesRegistry.get('terms'),
|
||||||
params: {},
|
params: {},
|
||||||
schema: 'split',
|
schema: 'split',
|
||||||
},
|
})
|
||||||
{ fieldFormats }
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
expect(ac.aggs).toHaveLength(3);
|
expect(ac.aggs).toHaveLength(3);
|
||||||
});
|
});
|
||||||
|
@ -121,7 +115,7 @@ describe('AggConfigs', () => {
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry, fieldFormats });
|
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry });
|
||||||
expect(ac.aggs).toHaveLength(1);
|
expect(ac.aggs).toHaveLength(1);
|
||||||
|
|
||||||
ac.createAggConfig({
|
ac.createAggConfig({
|
||||||
|
@ -142,7 +136,7 @@ describe('AggConfigs', () => {
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry, fieldFormats });
|
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry });
|
||||||
expect(ac.aggs).toHaveLength(1);
|
expect(ac.aggs).toHaveLength(1);
|
||||||
|
|
||||||
ac.createAggConfig(
|
ac.createAggConfig(
|
||||||
|
@ -170,7 +164,7 @@ describe('AggConfigs', () => {
|
||||||
{ type: 'percentiles', enabled: true, params: {}, schema: 'metric' },
|
{ type: 'percentiles', enabled: true, params: {}, schema: 'metric' },
|
||||||
];
|
];
|
||||||
|
|
||||||
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry, fieldFormats });
|
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry });
|
||||||
const sorted = ac.getRequestAggs();
|
const sorted = ac.getRequestAggs();
|
||||||
const aggs = indexBy(ac.aggs, (agg) => agg.type.name);
|
const aggs = indexBy(ac.aggs, (agg) => agg.type.name);
|
||||||
|
|
||||||
|
@ -193,7 +187,7 @@ describe('AggConfigs', () => {
|
||||||
{ type: 'count', enabled: true, params: {}, schema: 'metric' },
|
{ type: 'count', enabled: true, params: {}, schema: 'metric' },
|
||||||
];
|
];
|
||||||
|
|
||||||
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry, fieldFormats });
|
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry });
|
||||||
const sorted = ac.getResponseAggs();
|
const sorted = ac.getResponseAggs();
|
||||||
const aggs = indexBy(ac.aggs, (agg) => agg.type.name);
|
const aggs = indexBy(ac.aggs, (agg) => agg.type.name);
|
||||||
|
|
||||||
|
@ -210,7 +204,7 @@ describe('AggConfigs', () => {
|
||||||
{ type: 'percentiles', enabled: true, params: { percents: [1, 2, 3] }, schema: 'metric' },
|
{ type: 'percentiles', enabled: true, params: { percents: [1, 2, 3] }, schema: 'metric' },
|
||||||
];
|
];
|
||||||
|
|
||||||
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry, fieldFormats });
|
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry });
|
||||||
const sorted = ac.getResponseAggs();
|
const sorted = ac.getResponseAggs();
|
||||||
const aggs = indexBy(ac.aggs, (agg) => agg.type.name);
|
const aggs = indexBy(ac.aggs, (agg) => agg.type.name);
|
||||||
|
|
||||||
|
@ -231,7 +225,7 @@ describe('AggConfigs', () => {
|
||||||
|
|
||||||
it('uses the sorted aggs', () => {
|
it('uses the sorted aggs', () => {
|
||||||
const configStates = [{ enabled: true, type: 'avg', params: { field: 'bytes' } }];
|
const configStates = [{ enabled: true, type: 'avg', params: { field: 'bytes' } }];
|
||||||
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry, fieldFormats });
|
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry });
|
||||||
const spy = jest.spyOn(AggConfigs.prototype, 'getRequestAggs');
|
const spy = jest.spyOn(AggConfigs.prototype, 'getRequestAggs');
|
||||||
ac.toDsl();
|
ac.toDsl();
|
||||||
expect(spy).toHaveBeenCalledTimes(1);
|
expect(spy).toHaveBeenCalledTimes(1);
|
||||||
|
@ -245,10 +239,7 @@ describe('AggConfigs', () => {
|
||||||
{ enabled: true, type: 'count', params: {} },
|
{ enabled: true, type: 'count', params: {} },
|
||||||
];
|
];
|
||||||
|
|
||||||
const ac = new AggConfigs(indexPattern, configStates, {
|
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry });
|
||||||
typesRegistry,
|
|
||||||
fieldFormats,
|
|
||||||
});
|
|
||||||
|
|
||||||
const aggInfos = ac.aggs.map((aggConfig) => {
|
const aggInfos = ac.aggs.map((aggConfig) => {
|
||||||
const football = {};
|
const football = {};
|
||||||
|
@ -291,7 +282,7 @@ describe('AggConfigs', () => {
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry, fieldFormats });
|
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry });
|
||||||
const dsl = ac.toDsl();
|
const dsl = ac.toDsl();
|
||||||
const histo = ac.byName('date_histogram')[0];
|
const histo = ac.byName('date_histogram')[0];
|
||||||
const count = ac.byName('count')[0];
|
const count = ac.byName('count')[0];
|
||||||
|
@ -316,10 +307,7 @@ describe('AggConfigs', () => {
|
||||||
{ enabled: true, type: 'max', schema: 'metric', params: { field: 'bytes' } },
|
{ enabled: true, type: 'max', schema: 'metric', params: { field: 'bytes' } },
|
||||||
];
|
];
|
||||||
|
|
||||||
const ac = new AggConfigs(indexPattern, configStates, {
|
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry });
|
||||||
typesRegistry,
|
|
||||||
fieldFormats,
|
|
||||||
});
|
|
||||||
const dsl = ac.toDsl();
|
const dsl = ac.toDsl();
|
||||||
const histo = ac.byName('date_histogram')[0];
|
const histo = ac.byName('date_histogram')[0];
|
||||||
const metrics = ac.bySchemaName('metrics');
|
const metrics = ac.bySchemaName('metrics');
|
||||||
|
@ -344,7 +332,7 @@ describe('AggConfigs', () => {
|
||||||
{ enabled: true, type: 'max', schema: 'metric', params: { field: 'bytes' } },
|
{ enabled: true, type: 'max', schema: 'metric', params: { field: 'bytes' } },
|
||||||
];
|
];
|
||||||
|
|
||||||
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry, fieldFormats });
|
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry });
|
||||||
const topLevelDsl = ac.toDsl(true);
|
const topLevelDsl = ac.toDsl(true);
|
||||||
const buckets = ac.bySchemaName('buckets');
|
const buckets = ac.bySchemaName('buckets');
|
||||||
const metrics = ac.bySchemaName('metrics');
|
const metrics = ac.bySchemaName('metrics');
|
||||||
|
@ -414,7 +402,7 @@ describe('AggConfigs', () => {
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry, fieldFormats });
|
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry });
|
||||||
const topLevelDsl = ac.toDsl(true)['2'];
|
const topLevelDsl = ac.toDsl(true)['2'];
|
||||||
|
|
||||||
expect(Object.keys(topLevelDsl.aggs)).toContain('1');
|
expect(Object.keys(topLevelDsl.aggs)).toContain('1');
|
||||||
|
|
|
@ -28,7 +28,6 @@ import { IndexPattern } from '../../index_patterns';
|
||||||
import { ISearchSource } from '../search_source';
|
import { ISearchSource } from '../search_source';
|
||||||
import { FetchOptions } from '../fetch';
|
import { FetchOptions } from '../fetch';
|
||||||
import { TimeRange } from '../../../common';
|
import { TimeRange } from '../../../common';
|
||||||
import { FieldFormatsStart } from '../../field_formats';
|
|
||||||
|
|
||||||
function removeParentAggs(obj: any) {
|
function removeParentAggs(obj: any) {
|
||||||
for (const prop in obj) {
|
for (const prop in obj) {
|
||||||
|
@ -48,7 +47,6 @@ function parseParentAggs(dslLvlCursor: any, dsl: any) {
|
||||||
|
|
||||||
export interface AggConfigsOptions {
|
export interface AggConfigsOptions {
|
||||||
typesRegistry: AggTypesRegistryStart;
|
typesRegistry: AggTypesRegistryStart;
|
||||||
fieldFormats: FieldFormatsStart;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CreateAggConfigParams = Assign<AggConfigSerialized, { type: string | IAggType }>;
|
export type CreateAggConfigParams = Assign<AggConfigSerialized, { type: string | IAggType }>;
|
||||||
|
@ -70,7 +68,6 @@ export type IAggConfigs = AggConfigs;
|
||||||
export class AggConfigs {
|
export class AggConfigs {
|
||||||
public indexPattern: IndexPattern;
|
public indexPattern: IndexPattern;
|
||||||
public timeRange?: TimeRange;
|
public timeRange?: TimeRange;
|
||||||
private readonly fieldFormats: FieldFormatsStart;
|
|
||||||
private readonly typesRegistry: AggTypesRegistryStart;
|
private readonly typesRegistry: AggTypesRegistryStart;
|
||||||
|
|
||||||
aggs: IAggConfig[];
|
aggs: IAggConfig[];
|
||||||
|
@ -86,7 +83,6 @@ export class AggConfigs {
|
||||||
|
|
||||||
this.aggs = [];
|
this.aggs = [];
|
||||||
this.indexPattern = indexPattern;
|
this.indexPattern = indexPattern;
|
||||||
this.fieldFormats = opts.fieldFormats;
|
|
||||||
|
|
||||||
configStates.forEach((params: any) => this.createAggConfig(params));
|
configStates.forEach((params: any) => this.createAggConfig(params));
|
||||||
}
|
}
|
||||||
|
@ -117,7 +113,6 @@ export class AggConfigs {
|
||||||
|
|
||||||
const aggConfigs = new AggConfigs(this.indexPattern, this.aggs.filter(filterAggs), {
|
const aggConfigs = new AggConfigs(this.indexPattern, this.aggs.filter(filterAggs), {
|
||||||
typesRegistry: this.typesRegistry,
|
typesRegistry: this.typesRegistry,
|
||||||
fieldFormats: this.fieldFormats,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return aggConfigs;
|
return aggConfigs;
|
||||||
|
@ -134,14 +129,10 @@ export class AggConfigs {
|
||||||
aggConfig = params;
|
aggConfig = params;
|
||||||
params.parent = this;
|
params.parent = this;
|
||||||
} else {
|
} else {
|
||||||
aggConfig = new AggConfig(
|
aggConfig = new AggConfig(this, {
|
||||||
this,
|
|
||||||
{
|
|
||||||
...params,
|
...params,
|
||||||
type: typeof type === 'string' ? this.typesRegistry.get(type) : type,
|
type: typeof type === 'string' ? this.typesRegistry.get(type) : type,
|
||||||
},
|
});
|
||||||
{ fieldFormats: this.fieldFormats }
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (addToAggConfigs) {
|
if (addToAggConfigs) {
|
||||||
|
|
|
@ -159,47 +159,6 @@ describe('AggType Class', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getFormat', function () {
|
|
||||||
let aggConfig: IAggConfig;
|
|
||||||
let field: any;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
aggConfig = ({
|
|
||||||
getField: jest.fn(() => field),
|
|
||||||
} as unknown) as IAggConfig;
|
|
||||||
});
|
|
||||||
|
|
||||||
test('returns the formatter for the aggConfig', () => {
|
|
||||||
const aggType = new AggType(
|
|
||||||
{
|
|
||||||
name: 'name',
|
|
||||||
title: 'title',
|
|
||||||
},
|
|
||||||
dependencies
|
|
||||||
);
|
|
||||||
|
|
||||||
field = {
|
|
||||||
format: 'format',
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(aggType.getFormat(aggConfig)).toBe('format');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('returns default formatter', () => {
|
|
||||||
const aggType = new AggType(
|
|
||||||
{
|
|
||||||
name: 'name',
|
|
||||||
title: 'title',
|
|
||||||
},
|
|
||||||
dependencies
|
|
||||||
);
|
|
||||||
|
|
||||||
field = undefined;
|
|
||||||
|
|
||||||
expect(aggType.getFormat(aggConfig)).toBe('default');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('getSerializedFormat', () => {
|
describe('getSerializedFormat', () => {
|
||||||
test('returns the default serialized field format if it exists', () => {
|
test('returns the default serialized field format if it exists', () => {
|
||||||
const aggConfig = ({
|
const aggConfig = ({
|
||||||
|
|
|
@ -28,7 +28,6 @@ import { IAggConfigs } from './agg_configs';
|
||||||
import { Adapters } from '../../../../../plugins/inspector/public';
|
import { Adapters } from '../../../../../plugins/inspector/public';
|
||||||
import { BaseParamType } from './param_types/base';
|
import { BaseParamType } from './param_types/base';
|
||||||
import { AggParamType } from './param_types/agg';
|
import { AggParamType } from './param_types/agg';
|
||||||
import { KBN_FIELD_TYPES, IFieldFormat } from '../../../common';
|
|
||||||
import { ISearchSource } from '../search_source';
|
import { ISearchSource } from '../search_source';
|
||||||
import { GetInternalStartServicesFn } from '../../types';
|
import { GetInternalStartServicesFn } from '../../types';
|
||||||
|
|
||||||
|
@ -58,7 +57,6 @@ export interface AggTypeConfig<
|
||||||
inspectorAdapters: Adapters,
|
inspectorAdapters: Adapters,
|
||||||
abortSignal?: AbortSignal
|
abortSignal?: AbortSignal
|
||||||
) => Promise<any>;
|
) => Promise<any>;
|
||||||
getFormat?: (agg: TAggConfig) => IFieldFormat;
|
|
||||||
getSerializedFormat?: (agg: TAggConfig) => SerializedFieldFormat;
|
getSerializedFormat?: (agg: TAggConfig) => SerializedFieldFormat;
|
||||||
getValue?: (agg: TAggConfig, bucket: any) => any;
|
getValue?: (agg: TAggConfig, bucket: any) => any;
|
||||||
getKey?: (bucket: any, key: any, agg: TAggConfig) => any;
|
getKey?: (bucket: any, key: any, agg: TAggConfig) => any;
|
||||||
|
@ -197,16 +195,6 @@ export class AggType<
|
||||||
inspectorAdapters: Adapters,
|
inspectorAdapters: Adapters,
|
||||||
abortSignal?: AbortSignal
|
abortSignal?: AbortSignal
|
||||||
) => Promise<any>;
|
) => Promise<any>;
|
||||||
/**
|
|
||||||
* Pick a format for the values produced by this agg type,
|
|
||||||
* overridden by several metrics that always output a simple
|
|
||||||
* number
|
|
||||||
*
|
|
||||||
* @param {agg} agg - the agg to pick a format for
|
|
||||||
* @return {FieldFormat}
|
|
||||||
*/
|
|
||||||
getFormat: (agg: TAggConfig) => IFieldFormat;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the serialized format for the values produced by this agg type,
|
* Get the serialized format for the values produced by this agg type,
|
||||||
* overridden by several metrics that always output a simple number.
|
* overridden by several metrics that always output a simple number.
|
||||||
|
@ -283,15 +271,6 @@ export class AggType<
|
||||||
this.decorateAggConfig = config.decorateAggConfig || (() => ({}));
|
this.decorateAggConfig = config.decorateAggConfig || (() => ({}));
|
||||||
this.postFlightRequest = config.postFlightRequest || identity;
|
this.postFlightRequest = config.postFlightRequest || identity;
|
||||||
|
|
||||||
this.getFormat =
|
|
||||||
config.getFormat ||
|
|
||||||
((agg: TAggConfig) => {
|
|
||||||
const field = agg.getField();
|
|
||||||
const { fieldFormats } = getInternalStartServices();
|
|
||||||
|
|
||||||
return field ? field.format : fieldFormats.getDefaultInstance(KBN_FIELD_TYPES.STRING);
|
|
||||||
});
|
|
||||||
|
|
||||||
this.getSerializedFormat =
|
this.getSerializedFormat =
|
||||||
config.getSerializedFormat ||
|
config.getSerializedFormat ||
|
||||||
((agg: TAggConfig) => {
|
((agg: TAggConfig) => {
|
||||||
|
|
|
@ -26,7 +26,6 @@ import { AggConfigs, CreateAggConfigParams } from '../agg_configs';
|
||||||
import { BUCKET_TYPES } from './bucket_agg_types';
|
import { BUCKET_TYPES } from './bucket_agg_types';
|
||||||
import { IBucketAggConfig } from './bucket_agg_type';
|
import { IBucketAggConfig } from './bucket_agg_type';
|
||||||
import { mockAggTypesRegistry } from '../test_helpers';
|
import { mockAggTypesRegistry } from '../test_helpers';
|
||||||
import { fieldFormatsServiceMock } from '../../../field_formats/mocks';
|
|
||||||
|
|
||||||
const indexPattern = {
|
const indexPattern = {
|
||||||
id: '1234',
|
id: '1234',
|
||||||
|
@ -220,10 +219,9 @@ const nestedOtherResponse = {
|
||||||
|
|
||||||
describe('Terms Agg Other bucket helper', () => {
|
describe('Terms Agg Other bucket helper', () => {
|
||||||
const typesRegistry = mockAggTypesRegistry();
|
const typesRegistry = mockAggTypesRegistry();
|
||||||
const fieldFormats = fieldFormatsServiceMock.createStartContract();
|
|
||||||
|
|
||||||
const getAggConfigs = (aggs: CreateAggConfigParams[] = []) => {
|
const getAggConfigs = (aggs: CreateAggConfigParams[] = []) => {
|
||||||
return new AggConfigs(indexPattern, [...aggs], { typesRegistry, fieldFormats });
|
return new AggConfigs(indexPattern, [...aggs], { typesRegistry });
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('buildOtherBucketAgg', () => {
|
describe('buildOtherBucketAgg', () => {
|
||||||
|
|
|
@ -82,7 +82,6 @@ describe('AggConfig Filters', () => {
|
||||||
],
|
],
|
||||||
{
|
{
|
||||||
typesRegistry: mockAggTypesRegistry([getDateHistogramBucketAgg(aggTypesDependencies)]),
|
typesRegistry: mockAggTypesRegistry([getDateHistogramBucketAgg(aggTypesDependencies)]),
|
||||||
fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats,
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
const bucketKey = 1422579600000;
|
const bucketKey = 1422579600000;
|
||||||
|
|
|
@ -76,7 +76,6 @@ describe('AggConfig Filters', () => {
|
||||||
],
|
],
|
||||||
{
|
{
|
||||||
typesRegistry: mockAggTypesRegistry([getDateRangeBucketAgg(aggTypesDependencies)]),
|
typesRegistry: mockAggTypesRegistry([getDateRangeBucketAgg(aggTypesDependencies)]),
|
||||||
fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats,
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -73,7 +73,6 @@ describe('AggConfig Filters', () => {
|
||||||
],
|
],
|
||||||
{
|
{
|
||||||
typesRegistry: mockAggTypesRegistry([getFiltersBucketAgg(aggTypesDependencies)]),
|
typesRegistry: mockAggTypesRegistry([getFiltersBucketAgg(aggTypesDependencies)]),
|
||||||
fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats,
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -23,12 +23,21 @@ import { mockAggTypesRegistry } from '../../test_helpers';
|
||||||
import { BUCKET_TYPES } from '../bucket_agg_types';
|
import { BUCKET_TYPES } from '../bucket_agg_types';
|
||||||
import { IBucketAggConfig } from '../bucket_agg_type';
|
import { IBucketAggConfig } from '../bucket_agg_type';
|
||||||
import { BytesFormat, FieldFormatsGetConfigFn } from '../../../../../common';
|
import { BytesFormat, FieldFormatsGetConfigFn } from '../../../../../common';
|
||||||
|
import { GetInternalStartServicesFn, InternalStartServices } from '../../../../types';
|
||||||
|
import { FieldFormatsStart } from '../../../../field_formats';
|
||||||
import { fieldFormatsServiceMock } from '../../../../field_formats/mocks';
|
import { fieldFormatsServiceMock } from '../../../../field_formats/mocks';
|
||||||
|
|
||||||
describe('AggConfig Filters', () => {
|
describe('AggConfig Filters', () => {
|
||||||
|
let getInternalStartServices: GetInternalStartServicesFn;
|
||||||
|
let fieldFormats: FieldFormatsStart;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fieldFormats = fieldFormatsServiceMock.createStartContract();
|
||||||
|
getInternalStartServices = () => (({ fieldFormats } as unknown) as InternalStartServices);
|
||||||
|
});
|
||||||
|
|
||||||
describe('histogram', () => {
|
describe('histogram', () => {
|
||||||
const getConfig = (() => {}) as FieldFormatsGetConfigFn;
|
const getConfig = (() => {}) as FieldFormatsGetConfigFn;
|
||||||
const fieldFormats = fieldFormatsServiceMock.createStartContract();
|
|
||||||
const getAggConfigs = () => {
|
const getAggConfigs = () => {
|
||||||
const field = {
|
const field = {
|
||||||
name: 'bytes',
|
name: 'bytes',
|
||||||
|
@ -57,21 +66,25 @@ describe('AggConfig Filters', () => {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
{ typesRegistry: mockAggTypesRegistry(), fieldFormats }
|
{ typesRegistry: mockAggTypesRegistry() }
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
test('should return an range filter for histogram', () => {
|
test('should return an range filter for histogram', () => {
|
||||||
const aggConfigs = getAggConfigs();
|
const aggConfigs = getAggConfigs();
|
||||||
const filter = createFilterHistogram(aggConfigs.aggs[0] as IBucketAggConfig, '2048');
|
const filter = createFilterHistogram(getInternalStartServices)(
|
||||||
|
aggConfigs.aggs[0] as IBucketAggConfig,
|
||||||
|
'2048'
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(fieldFormats.deserialize).toHaveBeenCalledTimes(1);
|
||||||
expect(filter).toHaveProperty('meta');
|
expect(filter).toHaveProperty('meta');
|
||||||
expect(filter.meta).toHaveProperty('index', '1234');
|
expect(filter.meta).toHaveProperty('index', '1234');
|
||||||
expect(filter).toHaveProperty('range');
|
expect(filter).toHaveProperty('range');
|
||||||
expect(filter.range).toHaveProperty('bytes');
|
expect(filter.range).toHaveProperty('bytes');
|
||||||
expect(filter.range.bytes).toHaveProperty('gte', 2048);
|
expect(filter.range.bytes).toHaveProperty('gte', 2048);
|
||||||
expect(filter.range.bytes).toHaveProperty('lt', 3072);
|
expect(filter.range.bytes).toHaveProperty('lt', 3072);
|
||||||
expect(filter.meta).toHaveProperty('formattedValue', '2,048');
|
expect(filter.meta).toHaveProperty('formattedValue');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -19,8 +19,12 @@
|
||||||
|
|
||||||
import { IBucketAggConfig } from '../bucket_agg_type';
|
import { IBucketAggConfig } from '../bucket_agg_type';
|
||||||
import { buildRangeFilter, RangeFilterParams } from '../../../../../common';
|
import { buildRangeFilter, RangeFilterParams } from '../../../../../common';
|
||||||
|
import { GetInternalStartServicesFn } from '../../../../types';
|
||||||
|
|
||||||
export const createFilterHistogram = (aggConfig: IBucketAggConfig, key: string) => {
|
/** @internal */
|
||||||
|
export const createFilterHistogram = (getInternalStartServices: GetInternalStartServicesFn) => {
|
||||||
|
return (aggConfig: IBucketAggConfig, key: string) => {
|
||||||
|
const { fieldFormats } = getInternalStartServices();
|
||||||
const value = parseInt(key, 10);
|
const value = parseInt(key, 10);
|
||||||
const params: RangeFilterParams = { gte: value, lt: value + aggConfig.params.interval };
|
const params: RangeFilterParams = { gte: value, lt: value + aggConfig.params.interval };
|
||||||
|
|
||||||
|
@ -28,6 +32,7 @@ export const createFilterHistogram = (aggConfig: IBucketAggConfig, key: string)
|
||||||
aggConfig.params.field,
|
aggConfig.params.field,
|
||||||
params,
|
params,
|
||||||
aggConfig.getIndexPattern(),
|
aggConfig.getIndexPattern(),
|
||||||
aggConfig.fieldFormatter()(key)
|
fieldFormats.deserialize(aggConfig.toSerializedFieldFormat()).convert(key)
|
||||||
);
|
);
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -55,7 +55,7 @@ describe('AggConfig Filters', () => {
|
||||||
},
|
},
|
||||||
} as any;
|
} as any;
|
||||||
|
|
||||||
return new AggConfigs(indexPattern, aggs, { typesRegistry, fieldFormats });
|
return new AggConfigs(indexPattern, aggs, { typesRegistry });
|
||||||
};
|
};
|
||||||
|
|
||||||
test('should return a range filter for ip_range agg', () => {
|
test('should return a range filter for ip_range agg', () => {
|
||||||
|
|
|
@ -24,19 +24,29 @@ import { AggConfigs } from '../../agg_configs';
|
||||||
import { mockDataServices, mockAggTypesRegistry } from '../../test_helpers';
|
import { mockDataServices, mockAggTypesRegistry } from '../../test_helpers';
|
||||||
import { BUCKET_TYPES } from '../bucket_agg_types';
|
import { BUCKET_TYPES } from '../bucket_agg_types';
|
||||||
import { IBucketAggConfig } from '../bucket_agg_type';
|
import { IBucketAggConfig } from '../bucket_agg_type';
|
||||||
|
import { FieldFormatsStart } from '../../../../field_formats';
|
||||||
import { fieldFormatsServiceMock } from '../../../../field_formats/mocks';
|
import { fieldFormatsServiceMock } from '../../../../field_formats/mocks';
|
||||||
import { notificationServiceMock } from '../../../../../../../core/public/mocks';
|
import { notificationServiceMock } from '../../../../../../../core/public/mocks';
|
||||||
import { InternalStartServices } from '../../../../types';
|
import { GetInternalStartServicesFn, InternalStartServices } from '../../../../types';
|
||||||
|
|
||||||
describe('AggConfig Filters', () => {
|
describe('AggConfig Filters', () => {
|
||||||
describe('range', () => {
|
describe('range', () => {
|
||||||
let aggTypesDependencies: RangeBucketAggDependencies;
|
let aggTypesDependencies: RangeBucketAggDependencies;
|
||||||
|
let getInternalStartServices: GetInternalStartServicesFn;
|
||||||
|
let fieldFormats: FieldFormatsStart;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
fieldFormats = fieldFormatsServiceMock.createStartContract();
|
||||||
|
|
||||||
|
getInternalStartServices = () =>
|
||||||
|
(({
|
||||||
|
fieldFormats,
|
||||||
|
notifications: notificationServiceMock.createStartContract(),
|
||||||
|
} as unknown) as InternalStartServices);
|
||||||
|
|
||||||
aggTypesDependencies = {
|
aggTypesDependencies = {
|
||||||
getInternalStartServices: () =>
|
getInternalStartServices: () =>
|
||||||
(({
|
(({
|
||||||
fieldFormats: fieldFormatsServiceMock.createStartContract(),
|
|
||||||
notifications: notificationServiceMock.createStartContract(),
|
notifications: notificationServiceMock.createStartContract(),
|
||||||
} as unknown) as InternalStartServices),
|
} as unknown) as InternalStartServices),
|
||||||
};
|
};
|
||||||
|
@ -75,25 +85,28 @@ describe('AggConfig Filters', () => {
|
||||||
],
|
],
|
||||||
{
|
{
|
||||||
typesRegistry: mockAggTypesRegistry([getRangeBucketAgg(aggTypesDependencies)]),
|
typesRegistry: mockAggTypesRegistry([getRangeBucketAgg(aggTypesDependencies)]),
|
||||||
fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats,
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
test('should return a range filter for range agg', () => {
|
test('should return a range filter for range agg', () => {
|
||||||
const aggConfigs = getAggConfigs();
|
const aggConfigs = getAggConfigs();
|
||||||
const filter = createFilterRange(aggConfigs.aggs[0] as IBucketAggConfig, {
|
const filter = createFilterRange(getInternalStartServices)(
|
||||||
|
aggConfigs.aggs[0] as IBucketAggConfig,
|
||||||
|
{
|
||||||
gte: 1024,
|
gte: 1024,
|
||||||
lt: 2048.0,
|
lt: 2048.0,
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(fieldFormats.deserialize).toHaveBeenCalledTimes(1);
|
||||||
expect(filter).toHaveProperty('range');
|
expect(filter).toHaveProperty('range');
|
||||||
expect(filter).toHaveProperty('meta');
|
expect(filter).toHaveProperty('meta');
|
||||||
expect(filter.meta).toHaveProperty('index', '1234');
|
expect(filter.meta).toHaveProperty('index', '1234');
|
||||||
expect(filter.range).toHaveProperty('bytes');
|
expect(filter.range).toHaveProperty('bytes');
|
||||||
expect(filter.range.bytes).toHaveProperty('gte', 1024.0);
|
expect(filter.range.bytes).toHaveProperty('gte', 1024.0);
|
||||||
expect(filter.range.bytes).toHaveProperty('lt', 2048.0);
|
expect(filter.range.bytes).toHaveProperty('lt', 2048.0);
|
||||||
expect(filter.meta).toHaveProperty('formattedValue', '≥ 1,024 and < 2,048');
|
expect(filter.meta).toHaveProperty('formattedValue');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -19,12 +19,17 @@
|
||||||
|
|
||||||
import { IBucketAggConfig } from '../bucket_agg_type';
|
import { IBucketAggConfig } from '../bucket_agg_type';
|
||||||
import { buildRangeFilter } from '../../../../../common';
|
import { buildRangeFilter } from '../../../../../common';
|
||||||
|
import { GetInternalStartServicesFn } from '../../../../types';
|
||||||
|
|
||||||
export const createFilterRange = (aggConfig: IBucketAggConfig, params: any) => {
|
/** @internal */
|
||||||
|
export const createFilterRange = (getInternalStartServices: GetInternalStartServicesFn) => {
|
||||||
|
return (aggConfig: IBucketAggConfig, params: any) => {
|
||||||
|
const { fieldFormats } = getInternalStartServices();
|
||||||
return buildRangeFilter(
|
return buildRangeFilter(
|
||||||
aggConfig.params.field,
|
aggConfig.params.field,
|
||||||
params,
|
params,
|
||||||
aggConfig.getIndexPattern(),
|
aggConfig.getIndexPattern(),
|
||||||
aggConfig.fieldFormatter()(params)
|
fieldFormats.deserialize(aggConfig.toSerializedFieldFormat()).convert(params)
|
||||||
);
|
);
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -60,7 +60,6 @@ describe('AggConfig Filters', () => {
|
||||||
|
|
||||||
return new AggConfigs(indexPattern, aggs, {
|
return new AggConfigs(indexPattern, aggs, {
|
||||||
typesRegistry: mockAggTypesRegistry([getTermsBucketAgg(aggTypesDependencies)]),
|
typesRegistry: mockAggTypesRegistry([getTermsBucketAgg(aggTypesDependencies)]),
|
||||||
fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats,
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ import { dateHistogramInterval, TimeRange } from '../../../../common';
|
||||||
import { writeParams } from '../agg_params';
|
import { writeParams } from '../agg_params';
|
||||||
import { isMetricAggType } from '../metrics/metric_agg_type';
|
import { isMetricAggType } from '../metrics/metric_agg_type';
|
||||||
|
|
||||||
import { FIELD_FORMAT_IDS, KBN_FIELD_TYPES, UI_SETTINGS } from '../../../../common';
|
import { KBN_FIELD_TYPES, UI_SETTINGS } from '../../../../common';
|
||||||
import { TimefilterContract } from '../../../query';
|
import { TimefilterContract } from '../../../query';
|
||||||
import { QuerySetup } from '../../../query/query_service';
|
import { QuerySetup } from '../../../query/query_service';
|
||||||
import { GetInternalStartServicesFn } from '../../../types';
|
import { GetInternalStartServicesFn } from '../../../types';
|
||||||
|
@ -137,21 +137,6 @@ export const getDateHistogramBucketAgg = ({
|
||||||
} as any,
|
} as any,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
getFormat(agg) {
|
|
||||||
const { fieldFormats } = getInternalStartServices();
|
|
||||||
const DateFieldFormat = fieldFormats.getType(FIELD_FORMAT_IDS.DATE);
|
|
||||||
|
|
||||||
if (!DateFieldFormat) {
|
|
||||||
throw new Error('Unable to retrieve Date Field Format');
|
|
||||||
}
|
|
||||||
|
|
||||||
return new DateFieldFormat(
|
|
||||||
{
|
|
||||||
pattern: agg.buckets.getScaledDateFormat(),
|
|
||||||
},
|
|
||||||
(key: string) => uiSettings.get(key)
|
|
||||||
);
|
|
||||||
},
|
|
||||||
getSerializedFormat(agg) {
|
getSerializedFormat(agg) {
|
||||||
return {
|
return {
|
||||||
id: 'date',
|
id: 'date',
|
||||||
|
|
|
@ -78,7 +78,6 @@ describe('date_range params', () => {
|
||||||
],
|
],
|
||||||
{
|
{
|
||||||
typesRegistry: mockAggTypesRegistry([getDateRangeBucketAgg(aggTypesDependencies)]),
|
typesRegistry: mockAggTypesRegistry([getDateRangeBucketAgg(aggTypesDependencies)]),
|
||||||
fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats,
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -25,9 +25,9 @@ import { IUiSettingsClient } from 'src/core/public';
|
||||||
import { BUCKET_TYPES } from './bucket_agg_types';
|
import { BUCKET_TYPES } from './bucket_agg_types';
|
||||||
import { BucketAggType, IBucketAggConfig } from './bucket_agg_type';
|
import { BucketAggType, IBucketAggConfig } from './bucket_agg_type';
|
||||||
import { createFilterDateRange } from './create_filter/date_range';
|
import { createFilterDateRange } from './create_filter/date_range';
|
||||||
import { convertDateRangeToString, DateRangeKey } from './lib/date_range';
|
import { DateRangeKey } from './lib/date_range';
|
||||||
|
|
||||||
import { KBN_FIELD_TYPES, FieldFormat, TEXT_CONTEXT_TYPE } from '../../../../common';
|
import { KBN_FIELD_TYPES } from '../../../../common';
|
||||||
import { GetInternalStartServicesFn } from '../../../types';
|
import { GetInternalStartServicesFn } from '../../../types';
|
||||||
import { BaseAggParams } from '../types';
|
import { BaseAggParams } from '../types';
|
||||||
|
|
||||||
|
@ -58,18 +58,6 @@ export const getDateRangeBucketAgg = ({
|
||||||
getKey({ from, to }): DateRangeKey {
|
getKey({ from, to }): DateRangeKey {
|
||||||
return { from, to };
|
return { from, to };
|
||||||
},
|
},
|
||||||
getFormat(agg) {
|
|
||||||
const { fieldFormats } = getInternalStartServices();
|
|
||||||
|
|
||||||
const formatter = agg.fieldOwnFormatter(
|
|
||||||
TEXT_CONTEXT_TYPE,
|
|
||||||
fieldFormats.getDefaultInstance(KBN_FIELD_TYPES.DATE)
|
|
||||||
);
|
|
||||||
const DateRangeFormat = FieldFormat.from(function (range: DateRangeKey) {
|
|
||||||
return convertDateRangeToString(range, formatter);
|
|
||||||
});
|
|
||||||
return new DateRangeFormat();
|
|
||||||
},
|
|
||||||
getSerializedFormat(agg) {
|
getSerializedFormat(agg) {
|
||||||
return {
|
return {
|
||||||
id: 'date_range',
|
id: 'date_range',
|
||||||
|
|
|
@ -41,6 +41,7 @@ export const getFilterBucketAgg = ({ getInternalStartServices }: FilterBucketAgg
|
||||||
{
|
{
|
||||||
name: BUCKET_TYPES.FILTER,
|
name: BUCKET_TYPES.FILTER,
|
||||||
title: filterTitle,
|
title: filterTitle,
|
||||||
|
makeLabel: () => filterTitle,
|
||||||
params: [
|
params: [
|
||||||
{
|
{
|
||||||
name: 'geo_bounding_box',
|
name: 'geo_bounding_box',
|
||||||
|
|
|
@ -71,7 +71,6 @@ describe('Filters Agg', () => {
|
||||||
],
|
],
|
||||||
{
|
{
|
||||||
typesRegistry: mockAggTypesRegistry([getFiltersBucketAgg(aggTypesDependencies)]),
|
typesRegistry: mockAggTypesRegistry([getFiltersBucketAgg(aggTypesDependencies)]),
|
||||||
fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats,
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -81,7 +81,6 @@ describe('Geohash Agg', () => {
|
||||||
],
|
],
|
||||||
{
|
{
|
||||||
typesRegistry: mockAggTypesRegistry(),
|
typesRegistry: mockAggTypesRegistry(),
|
||||||
fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats,
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -54,6 +54,7 @@ export const getGeoHashBucketAgg = ({ getInternalStartServices }: GeoHashBucketA
|
||||||
{
|
{
|
||||||
name: BUCKET_TYPES.GEOHASH_GRID,
|
name: BUCKET_TYPES.GEOHASH_GRID,
|
||||||
title: geohashGridTitle,
|
title: geohashGridTitle,
|
||||||
|
makeLabel: () => geohashGridTitle,
|
||||||
params: [
|
params: [
|
||||||
{
|
{
|
||||||
name: 'field',
|
name: 'field',
|
||||||
|
|
|
@ -74,7 +74,6 @@ describe('Histogram Agg', () => {
|
||||||
],
|
],
|
||||||
{
|
{
|
||||||
typesRegistry: mockAggTypesRegistry([getHistogramBucketAgg(aggTypesDependencies)]),
|
typesRegistry: mockAggTypesRegistry([getHistogramBucketAgg(aggTypesDependencies)]),
|
||||||
fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats,
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -67,7 +67,7 @@ export const getHistogramBucketAgg = ({
|
||||||
makeLabel(aggConfig) {
|
makeLabel(aggConfig) {
|
||||||
return aggConfig.getFieldDisplayName();
|
return aggConfig.getFieldDisplayName();
|
||||||
},
|
},
|
||||||
createFilter: createFilterHistogram,
|
createFilter: createFilterHistogram(getInternalStartServices),
|
||||||
decorateAggConfig() {
|
decorateAggConfig() {
|
||||||
let autoBounds: AutoBounds;
|
let autoBounds: AutoBounds;
|
||||||
|
|
||||||
|
|
|
@ -23,13 +23,8 @@ import { BucketAggType } from './bucket_agg_type';
|
||||||
import { BUCKET_TYPES } from './bucket_agg_types';
|
import { BUCKET_TYPES } from './bucket_agg_types';
|
||||||
|
|
||||||
import { createFilterIpRange } from './create_filter/ip_range';
|
import { createFilterIpRange } from './create_filter/ip_range';
|
||||||
import {
|
import { IpRangeKey, RangeIpRangeAggKey, CidrMaskIpRangeAggKey } from './lib/ip_range';
|
||||||
convertIPRangeToString,
|
import { KBN_FIELD_TYPES } from '../../../../common';
|
||||||
IpRangeKey,
|
|
||||||
RangeIpRangeAggKey,
|
|
||||||
CidrMaskIpRangeAggKey,
|
|
||||||
} from './lib/ip_range';
|
|
||||||
import { KBN_FIELD_TYPES, FieldFormat, TEXT_CONTEXT_TYPE } from '../../../../common';
|
|
||||||
import { GetInternalStartServicesFn } from '../../../types';
|
import { GetInternalStartServicesFn } from '../../../types';
|
||||||
import { BaseAggParams } from '../types';
|
import { BaseAggParams } from '../types';
|
||||||
|
|
||||||
|
@ -67,17 +62,6 @@ export const getIpRangeBucketAgg = ({ getInternalStartServices }: IpRangeBucketA
|
||||||
}
|
}
|
||||||
return { type: 'range', from: bucket.from, to: bucket.to };
|
return { type: 'range', from: bucket.from, to: bucket.to };
|
||||||
},
|
},
|
||||||
getFormat(agg) {
|
|
||||||
const { fieldFormats } = getInternalStartServices();
|
|
||||||
const formatter = agg.fieldOwnFormatter(
|
|
||||||
TEXT_CONTEXT_TYPE,
|
|
||||||
fieldFormats.getDefaultInstance(KBN_FIELD_TYPES.IP)
|
|
||||||
);
|
|
||||||
const IpRangeFormat = FieldFormat.from(function (range: IpRangeKey) {
|
|
||||||
return convertIPRangeToString(range, formatter);
|
|
||||||
});
|
|
||||||
return new IpRangeFormat();
|
|
||||||
},
|
|
||||||
getSerializedFormat(agg) {
|
getSerializedFormat(agg) {
|
||||||
return {
|
return {
|
||||||
id: 'ip_range',
|
id: 'ip_range',
|
||||||
|
|
|
@ -22,30 +22,9 @@ import { AggConfigs } from '../agg_configs';
|
||||||
import { mockDataServices, mockAggTypesRegistry } from '../test_helpers';
|
import { mockDataServices, mockAggTypesRegistry } from '../test_helpers';
|
||||||
import { BUCKET_TYPES } from './bucket_agg_types';
|
import { BUCKET_TYPES } from './bucket_agg_types';
|
||||||
import { FieldFormatsGetConfigFn, NumberFormat } from '../../../../common';
|
import { FieldFormatsGetConfigFn, NumberFormat } from '../../../../common';
|
||||||
import { fieldFormatsServiceMock } from '../../../field_formats/mocks';
|
|
||||||
import { notificationServiceMock } from '../../../../../../../src/core/public/mocks';
|
import { notificationServiceMock } from '../../../../../../../src/core/public/mocks';
|
||||||
import { InternalStartServices } from '../../../types';
|
import { InternalStartServices } from '../../../types';
|
||||||
|
|
||||||
const buckets = [
|
|
||||||
{
|
|
||||||
to: 1024,
|
|
||||||
to_as_string: '1024.0',
|
|
||||||
doc_count: 20904,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
from: 1024,
|
|
||||||
from_as_string: '1024.0',
|
|
||||||
to: 2560,
|
|
||||||
to_as_string: '2560.0',
|
|
||||||
doc_count: 23358,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
from: 2560,
|
|
||||||
from_as_string: '2560.0',
|
|
||||||
doc_count: 174250,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
describe('Range Agg', () => {
|
describe('Range Agg', () => {
|
||||||
let aggTypesDependencies: RangeBucketAggDependencies;
|
let aggTypesDependencies: RangeBucketAggDependencies;
|
||||||
|
|
||||||
|
@ -53,7 +32,6 @@ describe('Range Agg', () => {
|
||||||
aggTypesDependencies = {
|
aggTypesDependencies = {
|
||||||
getInternalStartServices: () =>
|
getInternalStartServices: () =>
|
||||||
(({
|
(({
|
||||||
fieldFormats: fieldFormatsServiceMock.createStartContract(),
|
|
||||||
notifications: notificationServiceMock.createStartContract(),
|
notifications: notificationServiceMock.createStartContract(),
|
||||||
} as unknown) as InternalStartServices),
|
} as unknown) as InternalStartServices),
|
||||||
};
|
};
|
||||||
|
@ -99,23 +77,10 @@ describe('Range Agg', () => {
|
||||||
],
|
],
|
||||||
{
|
{
|
||||||
typesRegistry: mockAggTypesRegistry([getRangeBucketAgg(aggTypesDependencies)]),
|
typesRegistry: mockAggTypesRegistry([getRangeBucketAgg(aggTypesDependencies)]),
|
||||||
fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats,
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('formatting', () => {
|
|
||||||
test('formats bucket keys properly', () => {
|
|
||||||
const aggConfigs = getAggConfigs();
|
|
||||||
const agg = aggConfigs.aggs[0];
|
|
||||||
const format = (val: any) => agg.fieldFormatter()(agg.getKey(val));
|
|
||||||
|
|
||||||
expect(format(buckets[0])).toBe('≥ -∞ and < 1 KB');
|
|
||||||
expect(format(buckets[1])).toBe('≥ 1 KB and < 2.5 KB');
|
|
||||||
expect(format(buckets[2])).toBe('≥ 2.5 KB and < +∞');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('getSerializedFormat', () => {
|
describe('getSerializedFormat', () => {
|
||||||
test('generates a serialized field format in the expected shape', () => {
|
test('generates a serialized field format in the expected shape', () => {
|
||||||
const aggConfigs = getAggConfigs();
|
const aggConfigs = getAggConfigs();
|
||||||
|
|
|
@ -19,16 +19,13 @@
|
||||||
|
|
||||||
import { i18n } from '@kbn/i18n';
|
import { i18n } from '@kbn/i18n';
|
||||||
import { BucketAggType } from './bucket_agg_type';
|
import { BucketAggType } from './bucket_agg_type';
|
||||||
import { FieldFormat, KBN_FIELD_TYPES } from '../../../../common';
|
import { KBN_FIELD_TYPES } from '../../../../common';
|
||||||
import { RangeKey } from './range_key';
|
import { RangeKey } from './range_key';
|
||||||
import { createFilterRange } from './create_filter/range';
|
import { createFilterRange } from './create_filter/range';
|
||||||
import { BUCKET_TYPES } from './bucket_agg_types';
|
import { BUCKET_TYPES } from './bucket_agg_types';
|
||||||
import { GetInternalStartServicesFn } from '../../../types';
|
import { GetInternalStartServicesFn } from '../../../types';
|
||||||
import { BaseAggParams } from '../types';
|
import { BaseAggParams } from '../types';
|
||||||
|
|
||||||
const keyCaches = new WeakMap();
|
|
||||||
const formats = new WeakMap();
|
|
||||||
|
|
||||||
const rangeTitle = i18n.translate('data.search.aggs.buckets.rangeTitle', {
|
const rangeTitle = i18n.translate('data.search.aggs.buckets.rangeTitle', {
|
||||||
defaultMessage: 'Range',
|
defaultMessage: 'Range',
|
||||||
});
|
});
|
||||||
|
@ -45,12 +42,14 @@ export interface AggParamsRange extends BaseAggParams {
|
||||||
}>;
|
}>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getRangeBucketAgg = ({ getInternalStartServices }: RangeBucketAggDependencies) =>
|
export const getRangeBucketAgg = ({ getInternalStartServices }: RangeBucketAggDependencies) => {
|
||||||
new BucketAggType(
|
const keyCaches = new WeakMap();
|
||||||
|
|
||||||
|
return new BucketAggType(
|
||||||
{
|
{
|
||||||
name: BUCKET_TYPES.RANGE,
|
name: BUCKET_TYPES.RANGE,
|
||||||
title: rangeTitle,
|
title: rangeTitle,
|
||||||
createFilter: createFilterRange,
|
createFilter: createFilterRange(getInternalStartServices),
|
||||||
makeLabel(aggConfig) {
|
makeLabel(aggConfig) {
|
||||||
return i18n.translate('data.search.aggs.aggTypesLabel', {
|
return i18n.translate('data.search.aggs.aggTypesLabel', {
|
||||||
defaultMessage: '{fieldName} ranges',
|
defaultMessage: '{fieldName} ranges',
|
||||||
|
@ -77,30 +76,6 @@ export const getRangeBucketAgg = ({ getInternalStartServices }: RangeBucketAggDe
|
||||||
|
|
||||||
return key;
|
return key;
|
||||||
},
|
},
|
||||||
getFormat(agg) {
|
|
||||||
let aggFormat = formats.get(agg);
|
|
||||||
if (aggFormat) return aggFormat;
|
|
||||||
|
|
||||||
const RangeFormat = FieldFormat.from((range: any) => {
|
|
||||||
const format = agg.fieldOwnFormatter();
|
|
||||||
const gte = '\u2265';
|
|
||||||
const lt = '\u003c';
|
|
||||||
return i18n.translate('data.search.aggs.aggTypes.rangesFormatMessage', {
|
|
||||||
defaultMessage: '{gte} {from} and {lt} {to}',
|
|
||||||
values: {
|
|
||||||
gte,
|
|
||||||
from: format(range.gte),
|
|
||||||
lt,
|
|
||||||
to: format(range.lt),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
aggFormat = new RangeFormat();
|
|
||||||
|
|
||||||
formats.set(agg, aggFormat);
|
|
||||||
return aggFormat;
|
|
||||||
},
|
|
||||||
getSerializedFormat(agg) {
|
getSerializedFormat(agg) {
|
||||||
const format = agg.params.field ? agg.params.field.format.toJSON() : {};
|
const format = agg.params.field ? agg.params.field.format.toJSON() : {};
|
||||||
return {
|
return {
|
||||||
|
@ -132,3 +107,4 @@ export const getRangeBucketAgg = ({ getInternalStartServices }: RangeBucketAggDe
|
||||||
},
|
},
|
||||||
{ getInternalStartServices }
|
{ getInternalStartServices }
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
|
@ -72,7 +72,6 @@ describe('Significant Terms Agg', () => {
|
||||||
typesRegistry: mockAggTypesRegistry([
|
typesRegistry: mockAggTypesRegistry([
|
||||||
getSignificantTermsBucketAgg(aggTypesDependencies),
|
getSignificantTermsBucketAgg(aggTypesDependencies),
|
||||||
]),
|
]),
|
||||||
fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats,
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -20,11 +20,9 @@
|
||||||
import { AggConfigs } from '../agg_configs';
|
import { AggConfigs } from '../agg_configs';
|
||||||
import { mockAggTypesRegistry } from '../test_helpers';
|
import { mockAggTypesRegistry } from '../test_helpers';
|
||||||
import { BUCKET_TYPES } from './bucket_agg_types';
|
import { BUCKET_TYPES } from './bucket_agg_types';
|
||||||
import { fieldFormatsServiceMock } from '../../../field_formats/mocks';
|
|
||||||
|
|
||||||
describe('Terms Agg', () => {
|
describe('Terms Agg', () => {
|
||||||
describe('order agg editor UI', () => {
|
describe('order agg editor UI', () => {
|
||||||
const fieldFormats = fieldFormatsServiceMock.createStartContract();
|
|
||||||
const getAggConfigs = (params: Record<string, any> = {}) => {
|
const getAggConfigs = (params: Record<string, any> = {}) => {
|
||||||
const indexPattern = {
|
const indexPattern = {
|
||||||
id: '1234',
|
id: '1234',
|
||||||
|
@ -49,7 +47,7 @@ describe('Terms Agg', () => {
|
||||||
type: BUCKET_TYPES.TERMS,
|
type: BUCKET_TYPES.TERMS,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
{ typesRegistry: mockAggTypesRegistry(), fieldFormats }
|
{ typesRegistry: mockAggTypesRegistry() }
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ import { AggConfigSerialized, BaseAggParams, IAggConfigs } from '../types';
|
||||||
|
|
||||||
import { Adapters } from '../../../../../inspector/public';
|
import { Adapters } from '../../../../../inspector/public';
|
||||||
import { ISearchSource } from '../../search_source';
|
import { ISearchSource } from '../../search_source';
|
||||||
import { IFieldFormat, FieldFormatsContentType, KBN_FIELD_TYPES } from '../../../../common';
|
import { KBN_FIELD_TYPES } from '../../../../common';
|
||||||
import { getRequestInspectorStats, getResponseInspectorStats } from '../../expressions';
|
import { getRequestInspectorStats, getResponseInspectorStats } from '../../expressions';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -88,22 +88,6 @@ export const getTermsBucketAgg = ({ getInternalStartServices }: TermsBucketAggDe
|
||||||
const params = agg.params;
|
const params = agg.params;
|
||||||
return agg.getFieldDisplayName() + ': ' + params.order.text;
|
return agg.getFieldDisplayName() + ': ' + params.order.text;
|
||||||
},
|
},
|
||||||
getFormat(bucket): IFieldFormat {
|
|
||||||
return {
|
|
||||||
getConverterFor: (type: FieldFormatsContentType) => {
|
|
||||||
return (val: any) => {
|
|
||||||
if (val === '__other__') {
|
|
||||||
return bucket.params.otherBucketLabel;
|
|
||||||
}
|
|
||||||
if (val === '__missing__') {
|
|
||||||
return bucket.params.missingBucketLabel;
|
|
||||||
}
|
|
||||||
|
|
||||||
return bucket.params.field.format.convert(val, type);
|
|
||||||
};
|
|
||||||
},
|
|
||||||
} as IFieldFormat;
|
|
||||||
},
|
|
||||||
getSerializedFormat(agg) {
|
getSerializedFormat(agg) {
|
||||||
const format = agg.params.field ? agg.params.field.format.toJSON() : {};
|
const format = agg.params.field ? agg.params.field.format.toJSON() : {};
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -46,7 +46,7 @@ const averageBucketTitle = i18n.translate('data.search.aggs.metrics.averageBucke
|
||||||
export const getBucketAvgMetricAgg = ({
|
export const getBucketAvgMetricAgg = ({
|
||||||
getInternalStartServices,
|
getInternalStartServices,
|
||||||
}: BucketAvgMetricAggDependencies) => {
|
}: BucketAvgMetricAggDependencies) => {
|
||||||
const { subtype, params, getFormat, getSerializedFormat } = siblingPipelineAggHelper;
|
const { subtype, params, getSerializedFormat } = siblingPipelineAggHelper;
|
||||||
|
|
||||||
return new MetricAggType(
|
return new MetricAggType(
|
||||||
{
|
{
|
||||||
|
@ -55,7 +55,6 @@ export const getBucketAvgMetricAgg = ({
|
||||||
makeLabel: (agg) => makeNestedLabel(agg, overallAverageLabel),
|
makeLabel: (agg) => makeNestedLabel(agg, overallAverageLabel),
|
||||||
subtype,
|
subtype,
|
||||||
params: [...params()],
|
params: [...params()],
|
||||||
getFormat,
|
|
||||||
getSerializedFormat,
|
getSerializedFormat,
|
||||||
getValue(agg, bucket) {
|
getValue(agg, bucket) {
|
||||||
const customMetric = agg.getParam('customMetric');
|
const customMetric = agg.getParam('customMetric');
|
||||||
|
|
|
@ -45,7 +45,7 @@ const maxBucketTitle = i18n.translate('data.search.aggs.metrics.maxBucketTitle',
|
||||||
export const getBucketMaxMetricAgg = ({
|
export const getBucketMaxMetricAgg = ({
|
||||||
getInternalStartServices,
|
getInternalStartServices,
|
||||||
}: BucketMaxMetricAggDependencies) => {
|
}: BucketMaxMetricAggDependencies) => {
|
||||||
const { subtype, params, getFormat, getSerializedFormat } = siblingPipelineAggHelper;
|
const { subtype, params, getSerializedFormat } = siblingPipelineAggHelper;
|
||||||
|
|
||||||
return new MetricAggType(
|
return new MetricAggType(
|
||||||
{
|
{
|
||||||
|
@ -54,7 +54,6 @@ export const getBucketMaxMetricAgg = ({
|
||||||
makeLabel: (agg) => makeNestedLabel(agg, overallMaxLabel),
|
makeLabel: (agg) => makeNestedLabel(agg, overallMaxLabel),
|
||||||
subtype,
|
subtype,
|
||||||
params: [...params()],
|
params: [...params()],
|
||||||
getFormat,
|
|
||||||
getSerializedFormat,
|
getSerializedFormat,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -45,7 +45,7 @@ const minBucketTitle = i18n.translate('data.search.aggs.metrics.minBucketTitle',
|
||||||
export const getBucketMinMetricAgg = ({
|
export const getBucketMinMetricAgg = ({
|
||||||
getInternalStartServices,
|
getInternalStartServices,
|
||||||
}: BucketMinMetricAggDependencies) => {
|
}: BucketMinMetricAggDependencies) => {
|
||||||
const { subtype, params, getFormat, getSerializedFormat } = siblingPipelineAggHelper;
|
const { subtype, params, getSerializedFormat } = siblingPipelineAggHelper;
|
||||||
|
|
||||||
return new MetricAggType(
|
return new MetricAggType(
|
||||||
{
|
{
|
||||||
|
@ -54,7 +54,6 @@ export const getBucketMinMetricAgg = ({
|
||||||
makeLabel: (agg) => makeNestedLabel(agg, overallMinLabel),
|
makeLabel: (agg) => makeNestedLabel(agg, overallMinLabel),
|
||||||
subtype,
|
subtype,
|
||||||
params: [...params()],
|
params: [...params()],
|
||||||
getFormat,
|
|
||||||
getSerializedFormat,
|
getSerializedFormat,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -45,7 +45,7 @@ const sumBucketTitle = i18n.translate('data.search.aggs.metrics.sumBucketTitle',
|
||||||
export const getBucketSumMetricAgg = ({
|
export const getBucketSumMetricAgg = ({
|
||||||
getInternalStartServices,
|
getInternalStartServices,
|
||||||
}: BucketSumMetricAggDependencies) => {
|
}: BucketSumMetricAggDependencies) => {
|
||||||
const { subtype, params, getFormat, getSerializedFormat } = siblingPipelineAggHelper;
|
const { subtype, params, getSerializedFormat } = siblingPipelineAggHelper;
|
||||||
|
|
||||||
return new MetricAggType(
|
return new MetricAggType(
|
||||||
{
|
{
|
||||||
|
@ -54,7 +54,6 @@ export const getBucketSumMetricAgg = ({
|
||||||
makeLabel: (agg) => makeNestedLabel(agg, overallSumLabel),
|
makeLabel: (agg) => makeNestedLabel(agg, overallSumLabel),
|
||||||
subtype,
|
subtype,
|
||||||
params: [...params()],
|
params: [...params()],
|
||||||
getFormat,
|
|
||||||
getSerializedFormat,
|
getSerializedFormat,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -49,11 +49,6 @@ export const getCardinalityMetricAgg = ({
|
||||||
values: { field: aggConfig.getFieldDisplayName() },
|
values: { field: aggConfig.getFieldDisplayName() },
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getFormat() {
|
|
||||||
const { fieldFormats } = getInternalStartServices();
|
|
||||||
|
|
||||||
return fieldFormats.getDefaultInstance(KBN_FIELD_TYPES.NUMBER);
|
|
||||||
},
|
|
||||||
getSerializedFormat(agg) {
|
getSerializedFormat(agg) {
|
||||||
return {
|
return {
|
||||||
id: 'number',
|
id: 'number',
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
import { i18n } from '@kbn/i18n';
|
import { i18n } from '@kbn/i18n';
|
||||||
import { MetricAggType } from './metric_agg_type';
|
import { MetricAggType } from './metric_agg_type';
|
||||||
import { METRIC_TYPES } from './metric_agg_types';
|
import { METRIC_TYPES } from './metric_agg_types';
|
||||||
import { KBN_FIELD_TYPES } from '../../../../common';
|
|
||||||
import { GetInternalStartServicesFn } from '../../../types';
|
import { GetInternalStartServicesFn } from '../../../types';
|
||||||
|
|
||||||
export interface CountMetricAggDependencies {
|
export interface CountMetricAggDependencies {
|
||||||
|
@ -40,11 +39,6 @@ export const getCountMetricAgg = ({ getInternalStartServices }: CountMetricAggDe
|
||||||
defaultMessage: 'Count',
|
defaultMessage: 'Count',
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getFormat() {
|
|
||||||
const { fieldFormats } = getInternalStartServices();
|
|
||||||
|
|
||||||
return fieldFormats.getDefaultInstance(KBN_FIELD_TYPES.NUMBER);
|
|
||||||
},
|
|
||||||
getSerializedFormat(agg) {
|
getSerializedFormat(agg) {
|
||||||
return {
|
return {
|
||||||
id: 'number',
|
id: 'number',
|
||||||
|
|
|
@ -46,7 +46,7 @@ const cumulativeSumTitle = i18n.translate('data.search.aggs.metrics.cumulativeSu
|
||||||
export const getCumulativeSumMetricAgg = ({
|
export const getCumulativeSumMetricAgg = ({
|
||||||
getInternalStartServices,
|
getInternalStartServices,
|
||||||
}: CumulativeSumMetricAggDependencies) => {
|
}: CumulativeSumMetricAggDependencies) => {
|
||||||
const { subtype, params, getFormat, getSerializedFormat } = parentPipelineAggHelper;
|
const { subtype, params, getSerializedFormat } = parentPipelineAggHelper;
|
||||||
|
|
||||||
return new MetricAggType(
|
return new MetricAggType(
|
||||||
{
|
{
|
||||||
|
@ -55,7 +55,6 @@ export const getCumulativeSumMetricAgg = ({
|
||||||
makeLabel: (agg) => makeNestedLabel(agg, cumulativeSumLabel),
|
makeLabel: (agg) => makeNestedLabel(agg, cumulativeSumLabel),
|
||||||
subtype,
|
subtype,
|
||||||
params: [...params()],
|
params: [...params()],
|
||||||
getFormat,
|
|
||||||
getSerializedFormat,
|
getSerializedFormat,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -46,7 +46,7 @@ const derivativeTitle = i18n.translate('data.search.aggs.metrics.derivativeTitle
|
||||||
export const getDerivativeMetricAgg = ({
|
export const getDerivativeMetricAgg = ({
|
||||||
getInternalStartServices,
|
getInternalStartServices,
|
||||||
}: DerivativeMetricAggDependencies) => {
|
}: DerivativeMetricAggDependencies) => {
|
||||||
const { subtype, params, getFormat, getSerializedFormat } = parentPipelineAggHelper;
|
const { subtype, params, getSerializedFormat } = parentPipelineAggHelper;
|
||||||
|
|
||||||
return new MetricAggType(
|
return new MetricAggType(
|
||||||
{
|
{
|
||||||
|
@ -57,7 +57,6 @@ export const getDerivativeMetricAgg = ({
|
||||||
},
|
},
|
||||||
subtype,
|
subtype,
|
||||||
params: [...params()],
|
params: [...params()],
|
||||||
getFormat,
|
|
||||||
getSerializedFormat,
|
getSerializedFormat,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,14 +18,12 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { i18n } from '@kbn/i18n';
|
import { i18n } from '@kbn/i18n';
|
||||||
import { noop, identity } from 'lodash';
|
import { noop } from 'lodash';
|
||||||
|
|
||||||
import { forwardModifyAggConfigOnSearchRequestStart } from './nested_agg_helpers';
|
import { forwardModifyAggConfigOnSearchRequestStart } from './nested_agg_helpers';
|
||||||
import { IMetricAggConfig, MetricAggParam } from '../metric_agg_type';
|
import { IMetricAggConfig, MetricAggParam } from '../metric_agg_type';
|
||||||
import { parentPipelineAggWriter } from './parent_pipeline_agg_writer';
|
import { parentPipelineAggWriter } from './parent_pipeline_agg_writer';
|
||||||
|
|
||||||
import { FieldFormat } from '../../../../../common';
|
|
||||||
|
|
||||||
const metricAggFilter = [
|
const metricAggFilter = [
|
||||||
'!top_hits',
|
'!top_hits',
|
||||||
'!percentiles',
|
'!percentiles',
|
||||||
|
@ -73,18 +71,6 @@ export const parentPipelineAggHelper = {
|
||||||
] as Array<MetricAggParam<IMetricAggConfig>>;
|
] as Array<MetricAggParam<IMetricAggConfig>>;
|
||||||
},
|
},
|
||||||
|
|
||||||
getFormat(agg: IMetricAggConfig) {
|
|
||||||
let subAgg;
|
|
||||||
const customMetric = agg.getParam('customMetric');
|
|
||||||
|
|
||||||
if (customMetric) {
|
|
||||||
subAgg = customMetric;
|
|
||||||
} else {
|
|
||||||
subAgg = agg.aggConfigs.byId(agg.getParam('metricAgg'));
|
|
||||||
}
|
|
||||||
return subAgg ? subAgg.type.getFormat(subAgg) : new (FieldFormat.from(identity))();
|
|
||||||
},
|
|
||||||
|
|
||||||
getSerializedFormat(agg: IMetricAggConfig) {
|
getSerializedFormat(agg: IMetricAggConfig) {
|
||||||
let subAgg;
|
let subAgg;
|
||||||
const customMetric = agg.getParam('customMetric');
|
const customMetric = agg.getParam('customMetric');
|
||||||
|
|
|
@ -17,12 +17,10 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { identity } from 'lodash';
|
|
||||||
import { i18n } from '@kbn/i18n';
|
import { i18n } from '@kbn/i18n';
|
||||||
import { siblingPipelineAggWriter } from './sibling_pipeline_agg_writer';
|
import { siblingPipelineAggWriter } from './sibling_pipeline_agg_writer';
|
||||||
import { forwardModifyAggConfigOnSearchRequestStart } from './nested_agg_helpers';
|
import { forwardModifyAggConfigOnSearchRequestStart } from './nested_agg_helpers';
|
||||||
import { IMetricAggConfig, MetricAggParam } from '../metric_agg_type';
|
import { IMetricAggConfig, MetricAggParam } from '../metric_agg_type';
|
||||||
import { FieldFormat } from '../../../../../common';
|
|
||||||
|
|
||||||
const metricAggFilter: string[] = [
|
const metricAggFilter: string[] = [
|
||||||
'!top_hits',
|
'!top_hits',
|
||||||
|
@ -87,13 +85,6 @@ export const siblingPipelineAggHelper = {
|
||||||
] as Array<MetricAggParam<IMetricAggConfig>>;
|
] as Array<MetricAggParam<IMetricAggConfig>>;
|
||||||
},
|
},
|
||||||
|
|
||||||
getFormat(agg: IMetricAggConfig) {
|
|
||||||
const customMetric = agg.getParam('customMetric');
|
|
||||||
return customMetric
|
|
||||||
? customMetric.type.getFormat(customMetric)
|
|
||||||
: new (FieldFormat.from(identity))();
|
|
||||||
},
|
|
||||||
|
|
||||||
getSerializedFormat(agg: IMetricAggConfig) {
|
getSerializedFormat(agg: IMetricAggConfig) {
|
||||||
const customMetric = agg.getParam('customMetric');
|
const customMetric = agg.getParam('customMetric');
|
||||||
return customMetric ? customMetric.type.getSerializedFormat(customMetric) : {};
|
return customMetric ? customMetric.type.getSerializedFormat(customMetric) : {};
|
||||||
|
|
|
@ -63,7 +63,6 @@ describe('AggTypeMetricMedianProvider class', () => {
|
||||||
],
|
],
|
||||||
{
|
{
|
||||||
typesRegistry,
|
typesRegistry,
|
||||||
fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats,
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -22,7 +22,6 @@ import { AggType, AggTypeConfig } from '../agg_type';
|
||||||
import { AggParamType } from '../param_types/agg';
|
import { AggParamType } from '../param_types/agg';
|
||||||
import { AggConfig } from '../agg_config';
|
import { AggConfig } from '../agg_config';
|
||||||
import { METRIC_TYPES } from './metric_agg_types';
|
import { METRIC_TYPES } from './metric_agg_types';
|
||||||
import { KBN_FIELD_TYPES } from '../../../../common';
|
|
||||||
import { FieldTypes } from '../param_types';
|
import { FieldTypes } from '../param_types';
|
||||||
import { GetInternalStartServicesFn } from '../../../types';
|
import { GetInternalStartServicesFn } from '../../../types';
|
||||||
|
|
||||||
|
@ -82,14 +81,6 @@ export class MetricAggType<TMetricAggConfig extends AggConfig = IMetricAggConfig
|
||||||
return bucket[agg.id] && bucket[agg.id].value;
|
return bucket[agg.id] && bucket[agg.id].value;
|
||||||
});
|
});
|
||||||
|
|
||||||
this.getFormat =
|
|
||||||
config.getFormat ||
|
|
||||||
((agg) => {
|
|
||||||
const { fieldFormats } = dependencies.getInternalStartServices();
|
|
||||||
const field = agg.getField();
|
|
||||||
return field ? field.format : fieldFormats.getDefaultInstance(KBN_FIELD_TYPES.NUMBER);
|
|
||||||
});
|
|
||||||
|
|
||||||
this.subtype =
|
this.subtype =
|
||||||
config.subtype ||
|
config.subtype ||
|
||||||
i18n.translate('data.search.aggs.metrics.metricAggregationsSubtypeTitle', {
|
i18n.translate('data.search.aggs.metrics.metricAggregationsSubtypeTitle', {
|
||||||
|
|
|
@ -48,7 +48,7 @@ const movingAvgLabel = i18n.translate('data.search.aggs.metrics.movingAvgLabel',
|
||||||
export const getMovingAvgMetricAgg = ({
|
export const getMovingAvgMetricAgg = ({
|
||||||
getInternalStartServices,
|
getInternalStartServices,
|
||||||
}: MovingAvgMetricAggDependencies) => {
|
}: MovingAvgMetricAggDependencies) => {
|
||||||
const { subtype, params, getFormat, getSerializedFormat } = parentPipelineAggHelper;
|
const { subtype, params, getSerializedFormat } = parentPipelineAggHelper;
|
||||||
|
|
||||||
return new MetricAggType(
|
return new MetricAggType(
|
||||||
{
|
{
|
||||||
|
@ -57,7 +57,6 @@ export const getMovingAvgMetricAgg = ({
|
||||||
title: movingAvgTitle,
|
title: movingAvgTitle,
|
||||||
makeLabel: (agg) => makeNestedLabel(agg, movingAvgLabel),
|
makeLabel: (agg) => makeNestedLabel(agg, movingAvgLabel),
|
||||||
subtype,
|
subtype,
|
||||||
getFormat,
|
|
||||||
getSerializedFormat,
|
getSerializedFormat,
|
||||||
params: [
|
params: [
|
||||||
...params(),
|
...params(),
|
||||||
|
|
|
@ -24,14 +24,12 @@ import { getSerialDiffMetricAgg } from './serial_diff';
|
||||||
import { AggConfigs } from '../agg_configs';
|
import { AggConfigs } from '../agg_configs';
|
||||||
import { mockAggTypesRegistry } from '../test_helpers';
|
import { mockAggTypesRegistry } from '../test_helpers';
|
||||||
import { IMetricAggConfig, MetricAggType } from './metric_agg_type';
|
import { IMetricAggConfig, MetricAggType } from './metric_agg_type';
|
||||||
import { fieldFormatsServiceMock } from '../../../field_formats/mocks';
|
|
||||||
import { GetInternalStartServicesFn, InternalStartServices } from '../../../types';
|
import { GetInternalStartServicesFn, InternalStartServices } from '../../../types';
|
||||||
import { notificationServiceMock } from '../../../../../../../src/core/public/mocks';
|
import { notificationServiceMock } from '../../../../../../../src/core/public/mocks';
|
||||||
|
|
||||||
describe('parent pipeline aggs', function () {
|
describe('parent pipeline aggs', function () {
|
||||||
const getInternalStartServices: GetInternalStartServicesFn = () =>
|
const getInternalStartServices: GetInternalStartServicesFn = () =>
|
||||||
(({
|
(({
|
||||||
fieldFormats: fieldFormatsServiceMock.createStartContract(),
|
|
||||||
notifications: notificationServiceMock.createStartContract(),
|
notifications: notificationServiceMock.createStartContract(),
|
||||||
} as unknown) as InternalStartServices);
|
} as unknown) as InternalStartServices);
|
||||||
|
|
||||||
|
@ -76,9 +74,7 @@ describe('parent pipeline aggs', function () {
|
||||||
const field = {
|
const field = {
|
||||||
name: 'field',
|
name: 'field',
|
||||||
format: {
|
format: {
|
||||||
type: {
|
toJSON: () => ({ id: 'bytes' }),
|
||||||
id: 'bytes',
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const indexPattern = {
|
const indexPattern = {
|
||||||
|
@ -111,7 +107,7 @@ describe('parent pipeline aggs', function () {
|
||||||
schema: 'metric',
|
schema: 'metric',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
{ typesRegistry, fieldFormats: getInternalStartServices().fieldFormats }
|
{ typesRegistry }
|
||||||
);
|
);
|
||||||
|
|
||||||
// Grab the aggConfig off the vis (we don't actually use the vis for anything else)
|
// Grab the aggConfig off the vis (we don't actually use the vis for anything else)
|
||||||
|
@ -197,14 +193,14 @@ describe('parent pipeline aggs', function () {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have correct formatter', () => {
|
it('should have correct serialized format', () => {
|
||||||
init({
|
init({
|
||||||
metricAgg: '3',
|
metricAgg: '3',
|
||||||
});
|
});
|
||||||
expect(metricAgg.getFormat(aggConfig).type.id).toBe('bytes');
|
expect(metricAgg.getSerializedFormat(aggConfig).id).toBe('bytes');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have correct customMetric nested formatter', () => {
|
it('should have correct customMetric nested serialized format', () => {
|
||||||
init({
|
init({
|
||||||
metricAgg: 'custom',
|
metricAgg: 'custom',
|
||||||
customMetric: {
|
customMetric: {
|
||||||
|
@ -222,7 +218,7 @@ describe('parent pipeline aggs', function () {
|
||||||
schema: 'orderAgg',
|
schema: 'orderAgg',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
expect(metricAgg.getFormat(aggConfig).type.id).toBe('bytes');
|
expect(metricAgg.getSerializedFormat(aggConfig).id).toBe('bytes');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should call modifyAggConfigOnSearchRequestStart for its customMetric's parameters", () => {
|
it("should call modifyAggConfigOnSearchRequestStart for its customMetric's parameters", () => {
|
||||||
|
|
|
@ -74,7 +74,7 @@ describe('AggTypesMetricsPercentileRanksProvider class', function () {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
{ typesRegistry, fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats }
|
{ typesRegistry }
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ import { MetricAggType } from './metric_agg_type';
|
||||||
import { getResponseAggConfigClass, IResponseAggConfig } from './lib/get_response_agg_config_class';
|
import { getResponseAggConfigClass, IResponseAggConfig } from './lib/get_response_agg_config_class';
|
||||||
import { getPercentileValue } from './percentiles_get_value';
|
import { getPercentileValue } from './percentiles_get_value';
|
||||||
import { METRIC_TYPES } from './metric_agg_types';
|
import { METRIC_TYPES } from './metric_agg_types';
|
||||||
import { FIELD_FORMAT_IDS, KBN_FIELD_TYPES } from '../../../../common';
|
import { KBN_FIELD_TYPES } from '../../../../common';
|
||||||
import { GetInternalStartServicesFn } from '../../../types';
|
import { GetInternalStartServicesFn } from '../../../types';
|
||||||
import { BaseAggParams } from '../types';
|
import { BaseAggParams } from '../types';
|
||||||
|
|
||||||
|
@ -96,13 +96,6 @@ export const getPercentileRanksMetricAgg = ({
|
||||||
|
|
||||||
return values.map((value: any) => new ValueAggConfig(value));
|
return values.map((value: any) => new ValueAggConfig(value));
|
||||||
},
|
},
|
||||||
getFormat() {
|
|
||||||
const { fieldFormats } = getInternalStartServices();
|
|
||||||
return (
|
|
||||||
fieldFormats.getInstance(FIELD_FORMAT_IDS.PERCENT) ||
|
|
||||||
fieldFormats.getDefaultInstance(KBN_FIELD_TYPES.NUMBER)
|
|
||||||
);
|
|
||||||
},
|
|
||||||
getSerializedFormat(agg) {
|
getSerializedFormat(agg) {
|
||||||
return {
|
return {
|
||||||
id: 'percent',
|
id: 'percent',
|
||||||
|
|
|
@ -67,7 +67,7 @@ describe('AggTypesMetricsPercentilesProvider class', () => {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
{ typesRegistry, fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats }
|
{ typesRegistry }
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ const serialDiffLabel = i18n.translate('data.search.aggs.metrics.serialDiffLabel
|
||||||
export const getSerialDiffMetricAgg = ({
|
export const getSerialDiffMetricAgg = ({
|
||||||
getInternalStartServices,
|
getInternalStartServices,
|
||||||
}: SerialDiffMetricAggDependencies) => {
|
}: SerialDiffMetricAggDependencies) => {
|
||||||
const { subtype, params, getFormat, getSerializedFormat } = parentPipelineAggHelper;
|
const { subtype, params, getSerializedFormat } = parentPipelineAggHelper;
|
||||||
|
|
||||||
return new MetricAggType(
|
return new MetricAggType(
|
||||||
{
|
{
|
||||||
|
@ -55,7 +55,6 @@ export const getSerialDiffMetricAgg = ({
|
||||||
makeLabel: (agg) => makeNestedLabel(agg, serialDiffLabel),
|
makeLabel: (agg) => makeNestedLabel(agg, serialDiffLabel),
|
||||||
subtype,
|
subtype,
|
||||||
params: [...params()],
|
params: [...params()],
|
||||||
getFormat,
|
|
||||||
getSerializedFormat,
|
getSerializedFormat,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -25,14 +25,12 @@ import { getBucketMaxMetricAgg } from './bucket_max';
|
||||||
import { AggConfigs } from '../agg_configs';
|
import { AggConfigs } from '../agg_configs';
|
||||||
import { IMetricAggConfig, MetricAggType } from './metric_agg_type';
|
import { IMetricAggConfig, MetricAggType } from './metric_agg_type';
|
||||||
import { mockAggTypesRegistry } from '../test_helpers';
|
import { mockAggTypesRegistry } from '../test_helpers';
|
||||||
import { fieldFormatsServiceMock } from '../../../field_formats/mocks';
|
|
||||||
import { GetInternalStartServicesFn, InternalStartServices } from '../../../types';
|
import { GetInternalStartServicesFn, InternalStartServices } from '../../../types';
|
||||||
import { notificationServiceMock } from '../../../../../../../src/core/public/mocks';
|
import { notificationServiceMock } from '../../../../../../../src/core/public/mocks';
|
||||||
|
|
||||||
describe('sibling pipeline aggs', () => {
|
describe('sibling pipeline aggs', () => {
|
||||||
const getInternalStartServices: GetInternalStartServicesFn = () =>
|
const getInternalStartServices: GetInternalStartServicesFn = () =>
|
||||||
(({
|
(({
|
||||||
fieldFormats: fieldFormatsServiceMock.createStartContract(),
|
|
||||||
notifications: notificationServiceMock.createStartContract(),
|
notifications: notificationServiceMock.createStartContract(),
|
||||||
} as unknown) as InternalStartServices);
|
} as unknown) as InternalStartServices);
|
||||||
|
|
||||||
|
@ -71,9 +69,7 @@ describe('sibling pipeline aggs', () => {
|
||||||
const field = {
|
const field = {
|
||||||
name: 'field',
|
name: 'field',
|
||||||
format: {
|
format: {
|
||||||
type: {
|
toJSON: () => ({ id: 'bytes' }),
|
||||||
id: 'bytes',
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const indexPattern = {
|
const indexPattern = {
|
||||||
|
@ -112,7 +108,7 @@ describe('sibling pipeline aggs', () => {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
{ typesRegistry, fieldFormats: getInternalStartServices().fieldFormats }
|
{ typesRegistry }
|
||||||
);
|
);
|
||||||
|
|
||||||
// Grab the aggConfig off the vis (we don't actually use the vis for anything else)
|
// Grab the aggConfig off the vis (we don't actually use the vis for anything else)
|
||||||
|
@ -155,7 +151,7 @@ describe('sibling pipeline aggs', () => {
|
||||||
expect(aggDsl.parentAggs['2-bucket'].aggs['2-metric'].avg.field).toEqual('field');
|
expect(aggDsl.parentAggs['2-bucket'].aggs['2-metric'].avg.field).toEqual('field');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have correct formatter', () => {
|
it('should have correct serialized field format', () => {
|
||||||
init({
|
init({
|
||||||
customMetric: {
|
customMetric: {
|
||||||
id: '5',
|
id: '5',
|
||||||
|
@ -171,7 +167,7 @@ describe('sibling pipeline aggs', () => {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(metricAgg.getFormat(aggConfig).type.id).toBe('bytes');
|
expect(metricAgg.getSerializedFormat(aggConfig).id).toBe('bytes');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should call modifyAggConfigOnSearchRequestStart for nested aggs' parameters", () => {
|
it("should call modifyAggConfigOnSearchRequestStart for nested aggs' parameters", () => {
|
||||||
|
|
|
@ -66,7 +66,7 @@ describe('AggTypeMetricStandardDeviationProvider class', () => {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
{ typesRegistry, fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats }
|
{ typesRegistry }
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,7 @@ describe('Top hit metric', () => {
|
||||||
params,
|
params,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
{ typesRegistry, fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats }
|
{ typesRegistry }
|
||||||
);
|
);
|
||||||
|
|
||||||
// Grab the aggConfig off the vis (we don't actually use the vis for anything else)
|
// Grab the aggConfig off the vis (we don't actually use the vis for anything else)
|
||||||
|
|
|
@ -27,7 +27,6 @@ import {
|
||||||
} from './';
|
} from './';
|
||||||
import { SearchAggsSetup, SearchAggsStart } from './types';
|
import { SearchAggsSetup, SearchAggsStart } from './types';
|
||||||
import { mockAggTypesRegistry } from './test_helpers';
|
import { mockAggTypesRegistry } from './test_helpers';
|
||||||
import { fieldFormatsServiceMock } from '../../field_formats/mocks';
|
|
||||||
|
|
||||||
const aggTypeBaseParamMock = () => ({
|
const aggTypeBaseParamMock = () => ({
|
||||||
name: 'some_param',
|
name: 'some_param',
|
||||||
|
@ -73,7 +72,6 @@ export const searchAggsStartMock = (): SearchAggsStart => ({
|
||||||
createAggConfigs: jest.fn().mockImplementation((indexPattern, configStates = [], schemas) => {
|
createAggConfigs: jest.fn().mockImplementation((indexPattern, configStates = [], schemas) => {
|
||||||
return new AggConfigs(indexPattern, configStates, {
|
return new AggConfigs(indexPattern, configStates, {
|
||||||
typesRegistry: mockAggTypesRegistry(),
|
typesRegistry: mockAggTypesRegistry(),
|
||||||
fieldFormats: fieldFormatsServiceMock.createStartContract(),
|
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
types: mockAggTypesRegistry(),
|
types: mockAggTypesRegistry(),
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
import { set } from 'lodash';
|
import { set } from 'lodash';
|
||||||
import { FormattedData } from '../../../../../plugins/inspector/public';
|
import { FormattedData } from '../../../../../plugins/inspector/public';
|
||||||
|
import { FormatFactory } from '../../../common/field_formats/utils';
|
||||||
import { TabbedTable } from '../tabify';
|
import { TabbedTable } from '../tabify';
|
||||||
import { createFilter } from './create_filter';
|
import { createFilter } from './create_filter';
|
||||||
|
|
||||||
|
@ -38,14 +39,30 @@ import { createFilter } from './create_filter';
|
||||||
*/
|
*/
|
||||||
export async function buildTabularInspectorData(
|
export async function buildTabularInspectorData(
|
||||||
table: TabbedTable,
|
table: TabbedTable,
|
||||||
queryFilter: { addFilters: (filter: any) => void }
|
{
|
||||||
|
queryFilter,
|
||||||
|
deserializeFieldFormat,
|
||||||
|
}: {
|
||||||
|
queryFilter: { addFilters: (filter: any) => void };
|
||||||
|
deserializeFieldFormat: FormatFactory;
|
||||||
|
}
|
||||||
) {
|
) {
|
||||||
const aggConfigs = table.columns.map((column) => column.aggConfig);
|
const aggConfigs = table.columns.map((column) => column.aggConfig);
|
||||||
const rows = table.rows.map((row) => {
|
const rows = table.rows.map((row) => {
|
||||||
return table.columns.reduce<Record<string, FormattedData>>((prev, cur, colIndex) => {
|
return table.columns.reduce<Record<string, FormattedData>>((prev, cur, colIndex) => {
|
||||||
const value = row[cur.id];
|
const value = row[cur.id];
|
||||||
const fieldFormatter = cur.aggConfig.fieldFormatter('text');
|
|
||||||
prev[`col-${colIndex}-${cur.aggConfig.id}`] = new FormattedData(value, fieldFormatter(value));
|
let format = cur.aggConfig.toSerializedFieldFormat();
|
||||||
|
if (Object.keys(format).length < 1) {
|
||||||
|
// If no format exists, fall back to string as a default
|
||||||
|
format = { id: 'string' };
|
||||||
|
}
|
||||||
|
const fieldFormatter = deserializeFieldFormat(format);
|
||||||
|
|
||||||
|
prev[`col-${colIndex}-${cur.aggConfig.id}`] = new FormattedData(
|
||||||
|
value,
|
||||||
|
fieldFormatter.convert(value)
|
||||||
|
);
|
||||||
return prev;
|
return prev;
|
||||||
}, {});
|
}, {});
|
||||||
});
|
});
|
||||||
|
|
|
@ -22,12 +22,10 @@ import { AggConfigs, IAggConfig } from '../aggs';
|
||||||
import { TabbedTable } from '../tabify';
|
import { TabbedTable } from '../tabify';
|
||||||
import { isRangeFilter, BytesFormat, FieldFormatsGetConfigFn } from '../../../common';
|
import { isRangeFilter, BytesFormat, FieldFormatsGetConfigFn } from '../../../common';
|
||||||
import { mockDataServices, mockAggTypesRegistry } from '../aggs/test_helpers';
|
import { mockDataServices, mockAggTypesRegistry } from '../aggs/test_helpers';
|
||||||
import { fieldFormatsServiceMock } from '../../field_formats/mocks';
|
|
||||||
|
|
||||||
describe('createFilter', () => {
|
describe('createFilter', () => {
|
||||||
let table: TabbedTable;
|
let table: TabbedTable;
|
||||||
let aggConfig: IAggConfig;
|
let aggConfig: IAggConfig;
|
||||||
const fieldFormats = fieldFormatsServiceMock.createStartContract();
|
|
||||||
|
|
||||||
const typesRegistry = mockAggTypesRegistry();
|
const typesRegistry = mockAggTypesRegistry();
|
||||||
|
|
||||||
|
@ -60,7 +58,7 @@ describe('createFilter', () => {
|
||||||
params,
|
params,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
{ typesRegistry, fieldFormats }
|
{ typesRegistry }
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,12 @@ import { ISearchSource } from '../search_source';
|
||||||
import { tabifyAggResponse } from '../tabify';
|
import { tabifyAggResponse } from '../tabify';
|
||||||
import { Filter, Query, TimeRange, IIndexPattern, isRangeFilter } from '../../../common';
|
import { Filter, Query, TimeRange, IIndexPattern, isRangeFilter } from '../../../common';
|
||||||
import { FilterManager, calculateBounds, getTime } from '../../query';
|
import { FilterManager, calculateBounds, getTime } from '../../query';
|
||||||
import { getSearchService, getQueryService, getIndexPatterns } from '../../services';
|
import {
|
||||||
|
getFieldFormats,
|
||||||
|
getIndexPatterns,
|
||||||
|
getQueryService,
|
||||||
|
getSearchService,
|
||||||
|
} from '../../services';
|
||||||
import { buildTabularInspectorData } from './build_tabular_inspector_data';
|
import { buildTabularInspectorData } from './build_tabular_inspector_data';
|
||||||
import { getRequestInspectorStats, getResponseInspectorStats, serializeAggConfig } from './utils';
|
import { getRequestInspectorStats, getResponseInspectorStats, serializeAggConfig } from './utils';
|
||||||
|
|
||||||
|
@ -220,7 +225,11 @@ const handleCourierRequest = async ({
|
||||||
}
|
}
|
||||||
|
|
||||||
inspectorAdapters.data.setTabularLoader(
|
inspectorAdapters.data.setTabularLoader(
|
||||||
() => buildTabularInspectorData((searchSource as any).tabifiedResponse, filterManager),
|
() =>
|
||||||
|
buildTabularInspectorData((searchSource as any).tabifiedResponse, {
|
||||||
|
queryFilter: filterManager,
|
||||||
|
deserializeFieldFormat: getFieldFormats().deserialize,
|
||||||
|
}),
|
||||||
{ returnsFormattedValues: true }
|
{ returnsFormattedValues: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,6 @@ import {
|
||||||
AggConfigs,
|
AggConfigs,
|
||||||
getCalculateAutoTimeExpression,
|
getCalculateAutoTimeExpression,
|
||||||
} from './aggs';
|
} from './aggs';
|
||||||
import { FieldFormatsStart } from '../field_formats';
|
|
||||||
import { ISearchGeneric } from './i_search';
|
import { ISearchGeneric } from './i_search';
|
||||||
|
|
||||||
interface SearchServiceSetupDependencies {
|
interface SearchServiceSetupDependencies {
|
||||||
|
@ -50,7 +49,6 @@ interface SearchServiceSetupDependencies {
|
||||||
|
|
||||||
interface SearchServiceStartDependencies {
|
interface SearchServiceStartDependencies {
|
||||||
indexPatterns: IndexPatternsContract;
|
indexPatterns: IndexPatternsContract;
|
||||||
fieldFormats: FieldFormatsStart;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -158,7 +156,6 @@ export class SearchService implements Plugin<ISearchSetup, ISearchStart> {
|
||||||
calculateAutoTimeExpression: getCalculateAutoTimeExpression(core.uiSettings),
|
calculateAutoTimeExpression: getCalculateAutoTimeExpression(core.uiSettings),
|
||||||
createAggConfigs: (indexPattern, configStates = [], schemas) => {
|
createAggConfigs: (indexPattern, configStates = [], schemas) => {
|
||||||
return new AggConfigs(indexPattern, configStates, {
|
return new AggConfigs(indexPattern, configStates, {
|
||||||
fieldFormats: dependencies.fieldFormats,
|
|
||||||
typesRegistry: aggTypesStart,
|
typesRegistry: aggTypesStart,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -21,7 +21,6 @@ import { tabifyGetColumns } from './get_columns';
|
||||||
import { TabbedAggColumn } from './types';
|
import { TabbedAggColumn } from './types';
|
||||||
import { AggConfigs } from '../aggs';
|
import { AggConfigs } from '../aggs';
|
||||||
import { mockAggTypesRegistry, mockDataServices } from '../aggs/test_helpers';
|
import { mockAggTypesRegistry, mockDataServices } from '../aggs/test_helpers';
|
||||||
import { fieldFormatsServiceMock } from '../../field_formats/mocks';
|
|
||||||
|
|
||||||
describe('get columns', () => {
|
describe('get columns', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@ -29,7 +28,6 @@ describe('get columns', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const typesRegistry = mockAggTypesRegistry();
|
const typesRegistry = mockAggTypesRegistry();
|
||||||
const fieldFormats = fieldFormatsServiceMock.createStartContract();
|
|
||||||
|
|
||||||
const createAggConfigs = (aggs: any[] = []) => {
|
const createAggConfigs = (aggs: any[] = []) => {
|
||||||
const field = {
|
const field = {
|
||||||
|
@ -45,10 +43,7 @@ describe('get columns', () => {
|
||||||
},
|
},
|
||||||
} as any;
|
} as any;
|
||||||
|
|
||||||
return new AggConfigs(indexPattern, aggs, {
|
return new AggConfigs(indexPattern, aggs, { typesRegistry });
|
||||||
typesRegistry,
|
|
||||||
fieldFormats,
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
test('should inject the metric after each bucket if the vis is hierarchical', () => {
|
test('should inject the metric after each bucket if the vis is hierarchical', () => {
|
||||||
|
|
|
@ -21,7 +21,6 @@ import { TabbedAggResponseWriter } from './response_writer';
|
||||||
import { AggConfigs, BUCKET_TYPES } from '../aggs';
|
import { AggConfigs, BUCKET_TYPES } from '../aggs';
|
||||||
import { mockDataServices, mockAggTypesRegistry } from '../aggs/test_helpers';
|
import { mockDataServices, mockAggTypesRegistry } from '../aggs/test_helpers';
|
||||||
import { TabbedResponseWriterOptions } from './types';
|
import { TabbedResponseWriterOptions } from './types';
|
||||||
import { fieldFormatsServiceMock } from '../../field_formats/mocks';
|
|
||||||
|
|
||||||
describe('TabbedAggResponseWriter class', () => {
|
describe('TabbedAggResponseWriter class', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@ -31,7 +30,6 @@ describe('TabbedAggResponseWriter class', () => {
|
||||||
let responseWriter: TabbedAggResponseWriter;
|
let responseWriter: TabbedAggResponseWriter;
|
||||||
|
|
||||||
const typesRegistry = mockAggTypesRegistry();
|
const typesRegistry = mockAggTypesRegistry();
|
||||||
const fieldFormats = fieldFormatsServiceMock.createStartContract();
|
|
||||||
|
|
||||||
const splitAggConfig = [
|
const splitAggConfig = [
|
||||||
{
|
{
|
||||||
|
@ -73,17 +71,11 @@ describe('TabbedAggResponseWriter class', () => {
|
||||||
},
|
},
|
||||||
} as any;
|
} as any;
|
||||||
|
|
||||||
return new TabbedAggResponseWriter(
|
return new TabbedAggResponseWriter(new AggConfigs(indexPattern, aggs, { typesRegistry }), {
|
||||||
new AggConfigs(indexPattern, aggs, {
|
|
||||||
typesRegistry,
|
|
||||||
fieldFormats,
|
|
||||||
}),
|
|
||||||
{
|
|
||||||
metricsAtAllLevels: false,
|
metricsAtAllLevels: false,
|
||||||
partialRows: false,
|
partialRows: false,
|
||||||
...opts,
|
...opts,
|
||||||
}
|
});
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('Constructor', () => {
|
describe('Constructor', () => {
|
||||||
|
|
|
@ -22,11 +22,9 @@ import { IndexPattern } from '../../index_patterns';
|
||||||
import { AggConfigs, IAggConfig, IAggConfigs } from '../aggs';
|
import { AggConfigs, IAggConfig, IAggConfigs } from '../aggs';
|
||||||
import { mockAggTypesRegistry } from '../aggs/test_helpers';
|
import { mockAggTypesRegistry } from '../aggs/test_helpers';
|
||||||
import { metricOnly, threeTermBuckets } from 'fixtures/fake_hierarchical_data';
|
import { metricOnly, threeTermBuckets } from 'fixtures/fake_hierarchical_data';
|
||||||
import { fieldFormatsServiceMock } from '../../field_formats/mocks';
|
|
||||||
|
|
||||||
describe('tabifyAggResponse Integration', () => {
|
describe('tabifyAggResponse Integration', () => {
|
||||||
const typesRegistry = mockAggTypesRegistry();
|
const typesRegistry = mockAggTypesRegistry();
|
||||||
const fieldFormats = fieldFormatsServiceMock.createStartContract();
|
|
||||||
|
|
||||||
const createAggConfigs = (aggs: IAggConfig[] = []) => {
|
const createAggConfigs = (aggs: IAggConfig[] = []) => {
|
||||||
const field = {
|
const field = {
|
||||||
|
@ -42,10 +40,7 @@ describe('tabifyAggResponse Integration', () => {
|
||||||
},
|
},
|
||||||
} as unknown) as IndexPattern;
|
} as unknown) as IndexPattern;
|
||||||
|
|
||||||
return new AggConfigs(indexPattern, aggs, {
|
return new AggConfigs(indexPattern, aggs, { typesRegistry });
|
||||||
typesRegistry,
|
|
||||||
fieldFormats,
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const mockAggConfig = (agg: any): IAggConfig => (agg as unknown) as IAggConfig;
|
const mockAggConfig = (agg: any): IAggConfig => (agg as unknown) as IAggConfig;
|
||||||
|
|
|
@ -46,7 +46,7 @@ function TableOptions({
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
...tabifyGetColumns(aggs.getResponseAggs(), true)
|
...tabifyGetColumns(aggs.getResponseAggs(), true)
|
||||||
.filter((col) => get(col.aggConfig.type.getFormat(col.aggConfig), 'type.id') === 'number')
|
.filter((col) => get(col.aggConfig.toSerializedFieldFormat(), 'id') === 'number')
|
||||||
.map(({ name }) => ({ value: name, text: name })),
|
.map(({ name }) => ({ value: name, text: name })),
|
||||||
],
|
],
|
||||||
[aggs]
|
[aggs]
|
||||||
|
|
|
@ -207,7 +207,7 @@ export default function ({ getService, getPageObjects }) {
|
||||||
const vizName1 = 'Visualization TileMap';
|
const vizName1 = 'Visualization TileMap';
|
||||||
await PageObjects.visualize.loadSavedVisualization(vizName1);
|
await PageObjects.visualize.loadSavedVisualization(vizName1);
|
||||||
await inspector.open();
|
await inspector.open();
|
||||||
await inspector.expectTableHeaders(['filter', 'geohash_grid', 'Count', 'Geo Centroid']);
|
await inspector.expectTableHeaders(['Filter', 'Geohash', 'Count', 'Geo Centroid']);
|
||||||
await inspector.close();
|
await inspector.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -216,7 +216,7 @@ export default function ({ getService, getPageObjects }) {
|
||||||
await PageObjects.visEditor.setIsFilteredByCollarCheckbox(false);
|
await PageObjects.visEditor.setIsFilteredByCollarCheckbox(false);
|
||||||
await PageObjects.visEditor.clickGo();
|
await PageObjects.visEditor.clickGo();
|
||||||
await inspector.open();
|
await inspector.open();
|
||||||
await inspector.expectTableHeaders(['geohash_grid', 'Count', 'Geo Centroid']);
|
await inspector.expectTableHeaders(['Geohash', 'Count', 'Geo Centroid']);
|
||||||
await inspector.close();
|
await inspector.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -712,7 +712,6 @@
|
||||||
"data.search.aggs.aggGroups.bucketsText": "バケット",
|
"data.search.aggs.aggGroups.bucketsText": "バケット",
|
||||||
"data.search.aggs.aggGroups.metricsText": "メトリック",
|
"data.search.aggs.aggGroups.metricsText": "メトリック",
|
||||||
"data.search.aggs.aggGroups.noneText": "なし",
|
"data.search.aggs.aggGroups.noneText": "なし",
|
||||||
"data.search.aggs.aggTypes.rangesFormatMessage": "{gte} {from} と {lt} {to}",
|
|
||||||
"data.search.aggs.aggTypesLabel": "{fieldName} の範囲",
|
"data.search.aggs.aggTypesLabel": "{fieldName} の範囲",
|
||||||
"data.search.aggs.buckets.dateHistogram.customLabel.help": "このアグリゲーションのカスタムラベルを表します",
|
"data.search.aggs.buckets.dateHistogram.customLabel.help": "このアグリゲーションのカスタムラベルを表します",
|
||||||
"data.search.aggs.buckets.dateHistogram.dropPartials.help": "このアグリゲーションでdrop_partialsを使用するかどうかを指定します",
|
"data.search.aggs.buckets.dateHistogram.dropPartials.help": "このアグリゲーションでdrop_partialsを使用するかどうかを指定します",
|
||||||
|
|
|
@ -713,7 +713,6 @@
|
||||||
"data.search.aggs.aggGroups.bucketsText": "存储桶",
|
"data.search.aggs.aggGroups.bucketsText": "存储桶",
|
||||||
"data.search.aggs.aggGroups.metricsText": "指标",
|
"data.search.aggs.aggGroups.metricsText": "指标",
|
||||||
"data.search.aggs.aggGroups.noneText": "无",
|
"data.search.aggs.aggGroups.noneText": "无",
|
||||||
"data.search.aggs.aggTypes.rangesFormatMessage": "{gte} {from} 和 {lt} {to}",
|
|
||||||
"data.search.aggs.aggTypesLabel": "{fieldName} 范围",
|
"data.search.aggs.aggTypesLabel": "{fieldName} 范围",
|
||||||
"data.search.aggs.buckets.dateHistogram.customLabel.help": "表示此聚合的定制标签",
|
"data.search.aggs.buckets.dateHistogram.customLabel.help": "表示此聚合的定制标签",
|
||||||
"data.search.aggs.buckets.dateHistogram.dropPartials.help": "指定是否将 drop_partials 用于此聚合",
|
"data.search.aggs.buckets.dateHistogram.dropPartials.help": "指定是否将 drop_partials 用于此聚合",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue