mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[data.search.aggs] Remove service getters from agg types (AggConfig part) (#62548)
* removed getFieldFormats from aggConfig * made new properties is private * Fixed ci * Fixed tests * Fixes clone method * move filedFotmats inside opt fro AggConfigs * Added readonly Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
8264352bbe
commit
18687a3531
33 changed files with 156 additions and 66 deletions
|
@ -453,6 +453,7 @@ export const npStart = {
|
|||
createAggConfigs: (indexPattern, configStates = []) => {
|
||||
return new AggConfigs(indexPattern, configStates, {
|
||||
typesRegistry: aggTypesRegistry.start(),
|
||||
fieldFormats: getFieldFormatsRegistry(mockCoreStart),
|
||||
});
|
||||
},
|
||||
types: aggTypesRegistry.start(),
|
||||
|
|
|
@ -155,7 +155,7 @@ export class DataPublicPlugin implements Plugin<DataPublicPluginSetup, DataPubli
|
|||
const query = this.queryService.start(savedObjects);
|
||||
setQueryService(query);
|
||||
|
||||
const search = this.searchService.start(core, indexPatterns);
|
||||
const search = this.searchService.start(core, { fieldFormats, indexPatterns });
|
||||
setSearchService(search);
|
||||
|
||||
uiActions.attachAction(APPLY_FILTER_TRIGGER, uiActions.getAction(ACTION_GLOBAL_APPLY_FILTER));
|
||||
|
|
|
@ -26,10 +26,12 @@ import { AggTypesRegistryStart } from './agg_types_registry';
|
|||
import { mockDataServices, mockAggTypesRegistry } from './test_helpers';
|
||||
import { Field as IndexPatternField, IndexPattern } from '../../index_patterns';
|
||||
import { stubIndexPatternWithFields } from '../../../public/stubs';
|
||||
import { fieldFormatsServiceMock } from '../../field_formats/mocks';
|
||||
|
||||
describe('AggConfig', () => {
|
||||
let indexPattern: IndexPattern;
|
||||
let typesRegistry: AggTypesRegistryStart;
|
||||
const fieldFormats = fieldFormatsServiceMock.createStartContract();
|
||||
|
||||
beforeEach(() => {
|
||||
jest.restoreAllMocks();
|
||||
|
@ -40,7 +42,7 @@ describe('AggConfig', () => {
|
|||
|
||||
describe('#toDsl', () => {
|
||||
it('calls #write()', () => {
|
||||
const ac = new AggConfigs(indexPattern, [], { typesRegistry });
|
||||
const ac = new AggConfigs(indexPattern, [], { typesRegistry, fieldFormats });
|
||||
const configStates = {
|
||||
enabled: true,
|
||||
type: 'date_histogram',
|
||||
|
@ -55,7 +57,7 @@ describe('AggConfig', () => {
|
|||
});
|
||||
|
||||
it('uses the type name as the agg name', () => {
|
||||
const ac = new AggConfigs(indexPattern, [], { typesRegistry });
|
||||
const ac = new AggConfigs(indexPattern, [], { typesRegistry, fieldFormats });
|
||||
const configStates = {
|
||||
enabled: true,
|
||||
type: 'date_histogram',
|
||||
|
@ -70,7 +72,7 @@ describe('AggConfig', () => {
|
|||
});
|
||||
|
||||
it('uses the params from #write() output as the agg params', () => {
|
||||
const ac = new AggConfigs(indexPattern, [], { typesRegistry });
|
||||
const ac = new AggConfigs(indexPattern, [], { typesRegistry, fieldFormats });
|
||||
const configStates = {
|
||||
enabled: true,
|
||||
type: 'date_histogram',
|
||||
|
@ -100,7 +102,7 @@ describe('AggConfig', () => {
|
|||
params: {},
|
||||
},
|
||||
];
|
||||
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry });
|
||||
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry, fieldFormats });
|
||||
|
||||
const histoConfig = ac.byName('date_histogram')[0];
|
||||
const avgConfig = ac.byName('avg')[0];
|
||||
|
@ -210,8 +212,8 @@ describe('AggConfig', () => {
|
|||
|
||||
testsIdentical.forEach((configState, index) => {
|
||||
it(`identical aggregations (${index})`, () => {
|
||||
const ac1 = new AggConfigs(indexPattern, configState, { typesRegistry });
|
||||
const ac2 = new AggConfigs(indexPattern, configState, { typesRegistry });
|
||||
const ac1 = new AggConfigs(indexPattern, configState, { typesRegistry, fieldFormats });
|
||||
const ac2 = new AggConfigs(indexPattern, configState, { typesRegistry, fieldFormats });
|
||||
expect(ac1.jsonDataEquals(ac2.aggs)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
@ -251,8 +253,8 @@ describe('AggConfig', () => {
|
|||
|
||||
testsIdenticalDifferentOrder.forEach((test, index) => {
|
||||
it(`identical aggregations (${index}) - init json is in different order`, () => {
|
||||
const ac1 = new AggConfigs(indexPattern, test.config1, { typesRegistry });
|
||||
const ac2 = new AggConfigs(indexPattern, test.config2, { typesRegistry });
|
||||
const ac1 = new AggConfigs(indexPattern, test.config1, { typesRegistry, fieldFormats });
|
||||
const ac2 = new AggConfigs(indexPattern, test.config2, { typesRegistry, fieldFormats });
|
||||
expect(ac1.jsonDataEquals(ac2.aggs)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
@ -316,8 +318,8 @@ describe('AggConfig', () => {
|
|||
|
||||
testsDifferent.forEach((test, index) => {
|
||||
it(`different aggregations (${index})`, () => {
|
||||
const ac1 = new AggConfigs(indexPattern, test.config1, { typesRegistry });
|
||||
const ac2 = new AggConfigs(indexPattern, test.config2, { typesRegistry });
|
||||
const ac1 = new AggConfigs(indexPattern, test.config1, { typesRegistry, fieldFormats });
|
||||
const ac2 = new AggConfigs(indexPattern, test.config2, { typesRegistry, fieldFormats });
|
||||
expect(ac1.jsonDataEquals(ac2.aggs)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
@ -325,7 +327,7 @@ describe('AggConfig', () => {
|
|||
|
||||
describe('#toJSON', () => {
|
||||
it('includes the aggs id, params, type and schema', () => {
|
||||
const ac = new AggConfigs(indexPattern, [], { typesRegistry });
|
||||
const ac = new AggConfigs(indexPattern, [], { typesRegistry, fieldFormats });
|
||||
const configStates = {
|
||||
enabled: true,
|
||||
type: 'date_histogram',
|
||||
|
@ -356,8 +358,8 @@ describe('AggConfig', () => {
|
|||
params: {},
|
||||
},
|
||||
];
|
||||
const ac1 = new AggConfigs(indexPattern, configStates, { typesRegistry });
|
||||
const ac2 = new AggConfigs(indexPattern, configStates, { typesRegistry });
|
||||
const ac1 = new AggConfigs(indexPattern, configStates, { typesRegistry, fieldFormats });
|
||||
const ac2 = new AggConfigs(indexPattern, configStates, { typesRegistry, fieldFormats });
|
||||
|
||||
// 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.
|
||||
|
@ -369,7 +371,7 @@ describe('AggConfig', () => {
|
|||
let aggConfig: AggConfig;
|
||||
|
||||
beforeEach(() => {
|
||||
const ac = new AggConfigs(indexPattern, [], { typesRegistry });
|
||||
const ac = new AggConfigs(indexPattern, [], { typesRegistry, fieldFormats });
|
||||
aggConfig = ac.createAggConfig({ type: 'count' } as CreateAggConfigParams);
|
||||
});
|
||||
|
||||
|
@ -398,7 +400,7 @@ describe('AggConfig', () => {
|
|||
|
||||
describe('#fieldFormatter - custom getFormat handler', () => {
|
||||
it('returns formatter from getFormat handler', () => {
|
||||
const ac = new AggConfigs(indexPattern, [], { typesRegistry });
|
||||
const ac = new AggConfigs(indexPattern, [], { typesRegistry, fieldFormats });
|
||||
const configStates = {
|
||||
enabled: true,
|
||||
type: 'count',
|
||||
|
@ -439,7 +441,7 @@ describe('AggConfig', () => {
|
|||
},
|
||||
},
|
||||
};
|
||||
const ac = new AggConfigs(indexPattern, [configStates], { typesRegistry });
|
||||
const ac = new AggConfigs(indexPattern, [configStates], { typesRegistry, fieldFormats });
|
||||
aggConfig = ac.createAggConfig(configStates);
|
||||
});
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ import { IAggConfigs } from './agg_configs';
|
|||
import { FetchOptions } from '../fetch';
|
||||
import { ISearchSource } from '../search_source';
|
||||
import { FieldFormatsContentType, KBN_FIELD_TYPES } from '../../../common';
|
||||
import { getFieldFormats } from '../../../public/services';
|
||||
import { FieldFormatsStart } from '../../field_formats';
|
||||
|
||||
export interface AggConfigOptions {
|
||||
type: IAggType;
|
||||
|
@ -35,6 +35,10 @@ export interface AggConfigOptions {
|
|||
schema?: string;
|
||||
}
|
||||
|
||||
export interface AggConfigDependencies {
|
||||
fieldFormats: FieldFormatsStart;
|
||||
}
|
||||
|
||||
/**
|
||||
* @name AggConfig
|
||||
*
|
||||
|
@ -93,8 +97,13 @@ export class AggConfig {
|
|||
private __type: IAggType;
|
||||
private __typeDecorations: any;
|
||||
private subAggs: AggConfig[] = [];
|
||||
private readonly fieldFormats: FieldFormatsStart;
|
||||
|
||||
constructor(aggConfigs: IAggConfigs, opts: AggConfigOptions) {
|
||||
constructor(
|
||||
aggConfigs: IAggConfigs,
|
||||
opts: AggConfigOptions,
|
||||
{ fieldFormats }: AggConfigDependencies
|
||||
) {
|
||||
this.aggConfigs = aggConfigs;
|
||||
this.id = String(opts.id || AggConfig.nextId(aggConfigs.aggs as any));
|
||||
this.enabled = typeof opts.enabled === 'boolean' ? opts.enabled : true;
|
||||
|
@ -115,6 +124,8 @@ export class AggConfig {
|
|||
|
||||
// @ts-ignore
|
||||
this.__type = this.__type;
|
||||
|
||||
this.fieldFormats = fieldFormats;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -341,12 +352,10 @@ export class AggConfig {
|
|||
}
|
||||
|
||||
fieldOwnFormatter(contentType?: FieldFormatsContentType, defaultFormat?: any) {
|
||||
const fieldFormatsService = getFieldFormats();
|
||||
|
||||
const field = this.getField();
|
||||
let format = field && field.format;
|
||||
if (!format) format = defaultFormat;
|
||||
if (!format) format = fieldFormatsService.getDefaultInstance(KBN_FIELD_TYPES.STRING);
|
||||
if (!format) format = this.fieldFormats.getDefaultInstance(KBN_FIELD_TYPES.STRING);
|
||||
return format.getConverterFor(contentType);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,10 +24,12 @@ import { AggTypesRegistryStart } from './agg_types_registry';
|
|||
import { mockDataServices, mockAggTypesRegistry } from './test_helpers';
|
||||
import { Field as IndexPatternField, IndexPattern } from '../../index_patterns';
|
||||
import { stubIndexPattern, stubIndexPatternWithFields } from '../../../public/stubs';
|
||||
import { fieldFormatsServiceMock } from '../../field_formats/mocks';
|
||||
|
||||
describe('AggConfigs', () => {
|
||||
let indexPattern: IndexPattern;
|
||||
let typesRegistry: AggTypesRegistryStart;
|
||||
const fieldFormats = fieldFormatsServiceMock.createStartContract();
|
||||
|
||||
beforeEach(() => {
|
||||
mockDataServices();
|
||||
|
@ -45,7 +47,7 @@ describe('AggConfigs', () => {
|
|||
},
|
||||
];
|
||||
|
||||
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry });
|
||||
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry, fieldFormats });
|
||||
expect(ac.aggs).toHaveLength(1);
|
||||
});
|
||||
|
||||
|
@ -70,7 +72,7 @@ describe('AggConfigs', () => {
|
|||
];
|
||||
|
||||
const spy = jest.spyOn(AggConfig, 'ensureIds');
|
||||
new AggConfigs(indexPattern, configStates, { typesRegistry });
|
||||
new AggConfigs(indexPattern, configStates, { typesRegistry, fieldFormats });
|
||||
expect(spy).toHaveBeenCalledTimes(1);
|
||||
expect(spy.mock.calls[0]).toEqual([configStates]);
|
||||
spy.mockRestore();
|
||||
|
@ -92,16 +94,20 @@ describe('AggConfigs', () => {
|
|||
},
|
||||
];
|
||||
|
||||
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry });
|
||||
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry, fieldFormats });
|
||||
expect(ac.aggs).toHaveLength(2);
|
||||
|
||||
ac.createAggConfig(
|
||||
new AggConfig(ac, {
|
||||
enabled: true,
|
||||
type: typesRegistry.get('terms'),
|
||||
params: {},
|
||||
schema: 'split',
|
||||
})
|
||||
new AggConfig(
|
||||
ac,
|
||||
{
|
||||
enabled: true,
|
||||
type: typesRegistry.get('terms'),
|
||||
params: {},
|
||||
schema: 'split',
|
||||
},
|
||||
{ fieldFormats }
|
||||
)
|
||||
);
|
||||
expect(ac.aggs).toHaveLength(3);
|
||||
});
|
||||
|
@ -115,7 +121,7 @@ describe('AggConfigs', () => {
|
|||
},
|
||||
];
|
||||
|
||||
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry });
|
||||
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry, fieldFormats });
|
||||
expect(ac.aggs).toHaveLength(1);
|
||||
|
||||
ac.createAggConfig({
|
||||
|
@ -136,7 +142,7 @@ describe('AggConfigs', () => {
|
|||
},
|
||||
];
|
||||
|
||||
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry });
|
||||
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry, fieldFormats });
|
||||
expect(ac.aggs).toHaveLength(1);
|
||||
|
||||
ac.createAggConfig(
|
||||
|
@ -164,7 +170,7 @@ describe('AggConfigs', () => {
|
|||
{ type: 'percentiles', enabled: true, params: {}, schema: 'metric' },
|
||||
];
|
||||
|
||||
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry });
|
||||
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry, fieldFormats });
|
||||
const sorted = ac.getRequestAggs();
|
||||
const aggs = indexBy(ac.aggs, agg => agg.type.name);
|
||||
|
||||
|
@ -187,7 +193,7 @@ describe('AggConfigs', () => {
|
|||
{ type: 'count', enabled: true, params: {}, schema: 'metric' },
|
||||
];
|
||||
|
||||
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry });
|
||||
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry, fieldFormats });
|
||||
const sorted = ac.getResponseAggs();
|
||||
const aggs = indexBy(ac.aggs, agg => agg.type.name);
|
||||
|
||||
|
@ -204,7 +210,7 @@ describe('AggConfigs', () => {
|
|||
{ type: 'percentiles', enabled: true, params: { percents: [1, 2, 3] }, schema: 'metric' },
|
||||
];
|
||||
|
||||
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry });
|
||||
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry, fieldFormats });
|
||||
const sorted = ac.getResponseAggs();
|
||||
const aggs = indexBy(ac.aggs, agg => agg.type.name);
|
||||
|
||||
|
@ -225,7 +231,7 @@ describe('AggConfigs', () => {
|
|||
|
||||
it('uses the sorted aggs', () => {
|
||||
const configStates = [{ enabled: true, type: 'avg', params: { field: 'bytes' } }];
|
||||
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry });
|
||||
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry, fieldFormats });
|
||||
const spy = jest.spyOn(AggConfigs.prototype, 'getRequestAggs');
|
||||
ac.toDsl();
|
||||
expect(spy).toHaveBeenCalledTimes(1);
|
||||
|
@ -241,6 +247,7 @@ describe('AggConfigs', () => {
|
|||
|
||||
const ac = new AggConfigs(indexPattern, configStates, {
|
||||
typesRegistry,
|
||||
fieldFormats,
|
||||
});
|
||||
|
||||
const aggInfos = ac.aggs.map(aggConfig => {
|
||||
|
@ -284,7 +291,7 @@ describe('AggConfigs', () => {
|
|||
},
|
||||
];
|
||||
|
||||
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry });
|
||||
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry, fieldFormats });
|
||||
const dsl = ac.toDsl();
|
||||
const histo = ac.byName('date_histogram')[0];
|
||||
const count = ac.byName('count')[0];
|
||||
|
@ -311,6 +318,7 @@ describe('AggConfigs', () => {
|
|||
|
||||
const ac = new AggConfigs(indexPattern, configStates, {
|
||||
typesRegistry,
|
||||
fieldFormats,
|
||||
});
|
||||
const dsl = ac.toDsl();
|
||||
const histo = ac.byName('date_histogram')[0];
|
||||
|
@ -336,7 +344,7 @@ describe('AggConfigs', () => {
|
|||
{ enabled: true, type: 'max', schema: 'metric', params: { field: 'bytes' } },
|
||||
];
|
||||
|
||||
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry });
|
||||
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry, fieldFormats });
|
||||
const topLevelDsl = ac.toDsl(true);
|
||||
const buckets = ac.bySchemaName('buckets');
|
||||
const metrics = ac.bySchemaName('metrics');
|
||||
|
@ -406,7 +414,7 @@ describe('AggConfigs', () => {
|
|||
},
|
||||
];
|
||||
|
||||
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry });
|
||||
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry, fieldFormats });
|
||||
const topLevelDsl = ac.toDsl(true)['2'];
|
||||
|
||||
expect(Object.keys(topLevelDsl.aggs)).toContain('1');
|
||||
|
|
|
@ -28,6 +28,7 @@ import { IndexPattern } from '../../index_patterns';
|
|||
import { ISearchSource } from '../search_source';
|
||||
import { FetchOptions } from '../fetch';
|
||||
import { TimeRange } from '../../../common';
|
||||
import { FieldFormatsStart } from '../../field_formats';
|
||||
|
||||
function removeParentAggs(obj: any) {
|
||||
for (const prop in obj) {
|
||||
|
@ -47,6 +48,7 @@ function parseParentAggs(dslLvlCursor: any, dsl: any) {
|
|||
|
||||
export interface AggConfigsOptions {
|
||||
typesRegistry: AggTypesRegistryStart;
|
||||
fieldFormats: FieldFormatsStart;
|
||||
}
|
||||
|
||||
export type CreateAggConfigParams = Assign<AggConfigOptions, { type: string | IAggType }>;
|
||||
|
@ -68,6 +70,7 @@ export type IAggConfigs = AggConfigs;
|
|||
export class AggConfigs {
|
||||
public indexPattern: IndexPattern;
|
||||
public timeRange?: TimeRange;
|
||||
private readonly fieldFormats: FieldFormatsStart;
|
||||
private readonly typesRegistry: AggTypesRegistryStart;
|
||||
|
||||
aggs: IAggConfig[];
|
||||
|
@ -83,6 +86,7 @@ export class AggConfigs {
|
|||
|
||||
this.aggs = [];
|
||||
this.indexPattern = indexPattern;
|
||||
this.fieldFormats = opts.fieldFormats;
|
||||
|
||||
configStates.forEach((params: any) => this.createAggConfig(params));
|
||||
}
|
||||
|
@ -113,6 +117,7 @@ export class AggConfigs {
|
|||
|
||||
const aggConfigs = new AggConfigs(this.indexPattern, this.aggs.filter(filterAggs), {
|
||||
typesRegistry: this.typesRegistry,
|
||||
fieldFormats: this.fieldFormats,
|
||||
});
|
||||
|
||||
return aggConfigs;
|
||||
|
@ -129,10 +134,14 @@ export class AggConfigs {
|
|||
aggConfig = params;
|
||||
params.parent = this;
|
||||
} else {
|
||||
aggConfig = new AggConfig(this, {
|
||||
...params,
|
||||
type: typeof type === 'string' ? this.typesRegistry.get(type) : type,
|
||||
});
|
||||
aggConfig = new AggConfig(
|
||||
this,
|
||||
{
|
||||
...params,
|
||||
type: typeof type === 'string' ? this.typesRegistry.get(type) : type,
|
||||
},
|
||||
{ fieldFormats: this.fieldFormats }
|
||||
);
|
||||
}
|
||||
|
||||
if (addToAggConfigs) {
|
||||
|
|
|
@ -26,6 +26,7 @@ import { AggConfigs, CreateAggConfigParams } from '../agg_configs';
|
|||
import { BUCKET_TYPES } from './bucket_agg_types';
|
||||
import { IBucketAggConfig } from './bucket_agg_type';
|
||||
import { mockAggTypesRegistry } from '../test_helpers';
|
||||
import { fieldFormatsServiceMock } from '../../../field_formats/mocks';
|
||||
|
||||
const indexPattern = {
|
||||
id: '1234',
|
||||
|
@ -219,8 +220,10 @@ const nestedOtherResponse = {
|
|||
|
||||
describe('Terms Agg Other bucket helper', () => {
|
||||
const typesRegistry = mockAggTypesRegistry();
|
||||
const fieldFormats = fieldFormatsServiceMock.createStartContract();
|
||||
|
||||
const getAggConfigs = (aggs: CreateAggConfigParams[] = []) => {
|
||||
return new AggConfigs(indexPattern, [...aggs], { typesRegistry });
|
||||
return new AggConfigs(indexPattern, [...aggs], { typesRegistry, fieldFormats });
|
||||
};
|
||||
|
||||
describe('buildOtherBucketAgg', () => {
|
||||
|
|
|
@ -78,7 +78,10 @@ describe('AggConfig Filters', () => {
|
|||
params: { field: field.name, interval, customInterval: '5d' },
|
||||
},
|
||||
],
|
||||
{ typesRegistry: mockAggTypesRegistry([getDateHistogramBucketAgg(aggTypesDependencies)]) }
|
||||
{
|
||||
typesRegistry: mockAggTypesRegistry([getDateHistogramBucketAgg(aggTypesDependencies)]),
|
||||
fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats,
|
||||
}
|
||||
);
|
||||
const bucketKey = 1422579600000;
|
||||
|
||||
|
|
|
@ -72,7 +72,10 @@ describe('AggConfig Filters', () => {
|
|||
},
|
||||
},
|
||||
],
|
||||
{ typesRegistry: mockAggTypesRegistry([getDateRangeBucketAgg(aggTypesDependencies)]) }
|
||||
{
|
||||
typesRegistry: mockAggTypesRegistry([getDateRangeBucketAgg(aggTypesDependencies)]),
|
||||
fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats,
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
|
|
|
@ -69,7 +69,10 @@ describe('AggConfig Filters', () => {
|
|||
},
|
||||
},
|
||||
],
|
||||
{ typesRegistry: mockAggTypesRegistry([getFiltersBucketAgg(aggTypesDependencies)]) }
|
||||
{
|
||||
typesRegistry: mockAggTypesRegistry([getFiltersBucketAgg(aggTypesDependencies)]),
|
||||
fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats,
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
|
|
|
@ -23,10 +23,12 @@ import { mockAggTypesRegistry } from '../../test_helpers';
|
|||
import { BUCKET_TYPES } from '../bucket_agg_types';
|
||||
import { IBucketAggConfig } from '../bucket_agg_type';
|
||||
import { BytesFormat, FieldFormatsGetConfigFn } from '../../../../../common';
|
||||
import { fieldFormatsServiceMock } from '../../../../field_formats/mocks';
|
||||
|
||||
describe('AggConfig Filters', () => {
|
||||
describe('histogram', () => {
|
||||
const getConfig = (() => {}) as FieldFormatsGetConfigFn;
|
||||
const fieldFormats = fieldFormatsServiceMock.createStartContract();
|
||||
const getAggConfigs = () => {
|
||||
const field = {
|
||||
name: 'bytes',
|
||||
|
@ -55,7 +57,7 @@ describe('AggConfig Filters', () => {
|
|||
},
|
||||
},
|
||||
],
|
||||
{ typesRegistry: mockAggTypesRegistry() }
|
||||
{ typesRegistry: mockAggTypesRegistry(), fieldFormats }
|
||||
);
|
||||
};
|
||||
|
||||
|
|
|
@ -29,10 +29,11 @@ import { notificationServiceMock } from '../../../../../../../core/public/mocks'
|
|||
|
||||
describe('AggConfig Filters', () => {
|
||||
describe('IP range', () => {
|
||||
const fieldFormats = fieldFormatsServiceMock.createStartContract();
|
||||
const typesRegistry = mockAggTypesRegistry([
|
||||
getIpRangeBucketAgg({
|
||||
getInternalStartServices: () => ({
|
||||
fieldFormats: fieldFormatsServiceMock.createStartContract(),
|
||||
fieldFormats,
|
||||
notifications: notificationServiceMock.createStartContract(),
|
||||
}),
|
||||
}),
|
||||
|
@ -52,7 +53,7 @@ describe('AggConfig Filters', () => {
|
|||
},
|
||||
} as any;
|
||||
|
||||
return new AggConfigs(indexPattern, aggs, { typesRegistry });
|
||||
return new AggConfigs(indexPattern, aggs, { typesRegistry, fieldFormats });
|
||||
};
|
||||
|
||||
test('should return a range filter for ip_range agg', () => {
|
||||
|
|
|
@ -71,7 +71,10 @@ describe('AggConfig Filters', () => {
|
|||
},
|
||||
},
|
||||
],
|
||||
{ typesRegistry: mockAggTypesRegistry([getRangeBucketAgg(aggTypesDependencies)]) }
|
||||
{
|
||||
typesRegistry: mockAggTypesRegistry([getRangeBucketAgg(aggTypesDependencies)]),
|
||||
fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats,
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
|
|
|
@ -58,6 +58,7 @@ describe('AggConfig Filters', () => {
|
|||
|
||||
return new AggConfigs(indexPattern, aggs, {
|
||||
typesRegistry: mockAggTypesRegistry([getTermsBucketAgg(aggTypesDependencies)]),
|
||||
fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats,
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -74,7 +74,10 @@ describe('date_range params', () => {
|
|||
params,
|
||||
},
|
||||
],
|
||||
{ typesRegistry: mockAggTypesRegistry([getDateRangeBucketAgg(aggTypesDependencies)]) }
|
||||
{
|
||||
typesRegistry: mockAggTypesRegistry([getDateRangeBucketAgg(aggTypesDependencies)]),
|
||||
fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats,
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
|
|
|
@ -77,7 +77,10 @@ describe('Geohash Agg', () => {
|
|||
},
|
||||
},
|
||||
],
|
||||
{ typesRegistry: mockAggTypesRegistry() }
|
||||
{
|
||||
typesRegistry: mockAggTypesRegistry(),
|
||||
fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats,
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
|
|
|
@ -70,7 +70,10 @@ describe('Histogram Agg', () => {
|
|||
params,
|
||||
},
|
||||
],
|
||||
{ typesRegistry: mockAggTypesRegistry([getHistogramBucketAgg(aggTypesDependencies)]) }
|
||||
{
|
||||
typesRegistry: mockAggTypesRegistry([getHistogramBucketAgg(aggTypesDependencies)]),
|
||||
fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats,
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
|
|
|
@ -95,7 +95,10 @@ describe('Range Agg', () => {
|
|||
},
|
||||
},
|
||||
],
|
||||
{ typesRegistry: mockAggTypesRegistry([getRangeBucketAgg(aggTypesDependencies)]) }
|
||||
{
|
||||
typesRegistry: mockAggTypesRegistry([getRangeBucketAgg(aggTypesDependencies)]),
|
||||
fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats,
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
|
|
|
@ -70,6 +70,7 @@ describe('Significant Terms Agg', () => {
|
|||
typesRegistry: mockAggTypesRegistry([
|
||||
getSignificantTermsBucketAgg(aggTypesDependencies),
|
||||
]),
|
||||
fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats,
|
||||
}
|
||||
);
|
||||
};
|
||||
|
|
|
@ -20,9 +20,11 @@
|
|||
import { AggConfigs } from '../agg_configs';
|
||||
import { mockAggTypesRegistry } from '../test_helpers';
|
||||
import { BUCKET_TYPES } from './bucket_agg_types';
|
||||
import { fieldFormatsServiceMock } from '../../../field_formats/mocks';
|
||||
|
||||
describe('Terms Agg', () => {
|
||||
describe('order agg editor UI', () => {
|
||||
const fieldFormats = fieldFormatsServiceMock.createStartContract();
|
||||
const getAggConfigs = (params: Record<string, any> = {}) => {
|
||||
const indexPattern = {
|
||||
id: '1234',
|
||||
|
@ -47,7 +49,7 @@ describe('Terms Agg', () => {
|
|||
type: BUCKET_TYPES.TERMS,
|
||||
},
|
||||
],
|
||||
{ typesRegistry: mockAggTypesRegistry() }
|
||||
{ typesRegistry: mockAggTypesRegistry(), fieldFormats }
|
||||
);
|
||||
};
|
||||
|
||||
|
|
|
@ -59,7 +59,10 @@ describe('AggTypeMetricMedianProvider class', () => {
|
|||
},
|
||||
},
|
||||
],
|
||||
{ typesRegistry }
|
||||
{
|
||||
typesRegistry,
|
||||
fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats,
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -110,7 +110,7 @@ describe('parent pipeline aggs', function() {
|
|||
schema: 'metric',
|
||||
},
|
||||
],
|
||||
{ typesRegistry }
|
||||
{ typesRegistry, fieldFormats: getInternalStartServices().fieldFormats }
|
||||
);
|
||||
|
||||
// Grab the aggConfig off the vis (we don't actually use the vis for anything else)
|
||||
|
|
|
@ -70,7 +70,7 @@ describe('AggTypesMetricsPercentileRanksProvider class', function() {
|
|||
},
|
||||
},
|
||||
],
|
||||
{ typesRegistry }
|
||||
{ typesRegistry, fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats }
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ describe('AggTypesMetricsPercentilesProvider class', () => {
|
|||
},
|
||||
},
|
||||
],
|
||||
{ typesRegistry }
|
||||
{ typesRegistry, fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats }
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -111,7 +111,7 @@ describe('sibling pipeline aggs', () => {
|
|||
},
|
||||
},
|
||||
],
|
||||
{ typesRegistry }
|
||||
{ typesRegistry, fieldFormats: getInternalStartServices().fieldFormats }
|
||||
);
|
||||
|
||||
// Grab the aggConfig off the vis (we don't actually use the vis for anything else)
|
||||
|
|
|
@ -64,7 +64,7 @@ describe('AggTypeMetricStandardDeviationProvider class', () => {
|
|||
},
|
||||
},
|
||||
],
|
||||
{ typesRegistry }
|
||||
{ typesRegistry, fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats }
|
||||
);
|
||||
};
|
||||
|
||||
|
|
|
@ -89,7 +89,7 @@ describe('Top hit metric', () => {
|
|||
params,
|
||||
},
|
||||
],
|
||||
{ typesRegistry }
|
||||
{ typesRegistry, fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats }
|
||||
);
|
||||
|
||||
// Grab the aggConfig off the vis (we don't actually use the vis for anything else)
|
||||
|
|
|
@ -27,6 +27,7 @@ import {
|
|||
} from './';
|
||||
import { SearchAggsSetup, SearchAggsStart } from './types';
|
||||
import { mockAggTypesRegistry } from './test_helpers';
|
||||
import { fieldFormatsServiceMock } from '../../field_formats/mocks';
|
||||
|
||||
const aggTypeBaseParamMock = () => ({
|
||||
name: 'some_param',
|
||||
|
@ -72,6 +73,7 @@ export const searchAggsStartMock = (): SearchAggsStart => ({
|
|||
createAggConfigs: jest.fn().mockImplementation((indexPattern, configStates = [], schemas) => {
|
||||
return new AggConfigs(indexPattern, configStates, {
|
||||
typesRegistry: mockAggTypesRegistry(),
|
||||
fieldFormats: fieldFormatsServiceMock.createStartContract(),
|
||||
});
|
||||
}),
|
||||
types: mockAggTypesRegistry(),
|
||||
|
|
|
@ -22,10 +22,12 @@ import { AggConfigs, IAggConfig } from '../aggs';
|
|||
import { TabbedTable } from '../tabify';
|
||||
import { isRangeFilter, BytesFormat, FieldFormatsGetConfigFn } from '../../../common';
|
||||
import { mockDataServices, mockAggTypesRegistry } from '../aggs/test_helpers';
|
||||
import { fieldFormatsServiceMock } from '../../field_formats/mocks';
|
||||
|
||||
describe('createFilter', () => {
|
||||
let table: TabbedTable;
|
||||
let aggConfig: IAggConfig;
|
||||
const fieldFormats = fieldFormatsServiceMock.createStartContract();
|
||||
|
||||
const typesRegistry = mockAggTypesRegistry();
|
||||
|
||||
|
@ -58,7 +60,7 @@ describe('createFilter', () => {
|
|||
params,
|
||||
},
|
||||
],
|
||||
{ typesRegistry }
|
||||
{ typesRegistry, fieldFormats }
|
||||
);
|
||||
};
|
||||
|
||||
|
|
|
@ -44,12 +44,19 @@ import {
|
|||
siblingPipelineAggHelper,
|
||||
} from './aggs';
|
||||
|
||||
import { FieldFormatsStart } from '../field_formats';
|
||||
|
||||
interface SearchServiceSetupDependencies {
|
||||
packageInfo: PackageInfo;
|
||||
query: QuerySetup;
|
||||
getInternalStartServices: GetInternalStartServicesFn;
|
||||
}
|
||||
|
||||
interface SearchStartDependencies {
|
||||
fieldFormats: FieldFormatsStart;
|
||||
indexPatterns: IndexPatternsContract;
|
||||
}
|
||||
|
||||
/**
|
||||
* The search plugin exposes two registration methods for other plugins:
|
||||
* - registerSearchStrategyProvider for plugins to add their own custom
|
||||
|
@ -110,7 +117,10 @@ export class SearchService implements Plugin<ISearchSetup, ISearchStart> {
|
|||
};
|
||||
}
|
||||
|
||||
public start(core: CoreStart, indexPatterns: IndexPatternsContract): ISearchStart {
|
||||
public start(
|
||||
core: CoreStart,
|
||||
{ fieldFormats, indexPatterns }: SearchStartDependencies
|
||||
): ISearchStart {
|
||||
/**
|
||||
* A global object that intercepts all searches and provides convenience methods for cancelling
|
||||
* all pending search requests, as well as getting the number of pending search requests.
|
||||
|
@ -131,6 +141,7 @@ export class SearchService implements Plugin<ISearchSetup, ISearchStart> {
|
|||
createAggConfigs: (indexPattern, configStates = [], schemas) => {
|
||||
return new AggConfigs(indexPattern, configStates, {
|
||||
typesRegistry: aggTypesStart,
|
||||
fieldFormats,
|
||||
});
|
||||
},
|
||||
types: aggTypesStart,
|
||||
|
|
|
@ -21,6 +21,7 @@ import { tabifyGetColumns } from './get_columns';
|
|||
import { TabbedAggColumn } from './types';
|
||||
import { AggConfigs } from '../aggs';
|
||||
import { mockAggTypesRegistry, mockDataServices } from '../aggs/test_helpers';
|
||||
import { fieldFormatsServiceMock } from '../../field_formats/mocks';
|
||||
|
||||
describe('get columns', () => {
|
||||
beforeEach(() => {
|
||||
|
@ -28,6 +29,7 @@ describe('get columns', () => {
|
|||
});
|
||||
|
||||
const typesRegistry = mockAggTypesRegistry();
|
||||
const fieldFormats = fieldFormatsServiceMock.createStartContract();
|
||||
|
||||
const createAggConfigs = (aggs: any[] = []) => {
|
||||
const field = {
|
||||
|
@ -45,6 +47,7 @@ describe('get columns', () => {
|
|||
|
||||
return new AggConfigs(indexPattern, aggs, {
|
||||
typesRegistry,
|
||||
fieldFormats,
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ import { TabbedAggResponseWriter } from './response_writer';
|
|||
import { AggConfigs, BUCKET_TYPES } from '../aggs';
|
||||
import { mockDataServices, mockAggTypesRegistry } from '../aggs/test_helpers';
|
||||
import { TabbedResponseWriterOptions } from './types';
|
||||
import { fieldFormatsServiceMock } from '../../field_formats/mocks';
|
||||
|
||||
describe('TabbedAggResponseWriter class', () => {
|
||||
beforeEach(() => {
|
||||
|
@ -30,6 +31,7 @@ describe('TabbedAggResponseWriter class', () => {
|
|||
let responseWriter: TabbedAggResponseWriter;
|
||||
|
||||
const typesRegistry = mockAggTypesRegistry();
|
||||
const fieldFormats = fieldFormatsServiceMock.createStartContract();
|
||||
|
||||
const splitAggConfig = [
|
||||
{
|
||||
|
@ -74,6 +76,7 @@ describe('TabbedAggResponseWriter class', () => {
|
|||
return new TabbedAggResponseWriter(
|
||||
new AggConfigs(indexPattern, aggs, {
|
||||
typesRegistry,
|
||||
fieldFormats,
|
||||
}),
|
||||
{
|
||||
metricsAtAllLevels: false,
|
||||
|
|
|
@ -22,9 +22,11 @@ import { IndexPattern } from '../../index_patterns';
|
|||
import { AggConfigs, IAggConfig, IAggConfigs } from '../aggs';
|
||||
import { mockAggTypesRegistry } from '../aggs/test_helpers';
|
||||
import { metricOnly, threeTermBuckets } from 'fixtures/fake_hierarchical_data';
|
||||
import { fieldFormatsServiceMock } from '../../field_formats/mocks';
|
||||
|
||||
describe('tabifyAggResponse Integration', () => {
|
||||
const typesRegistry = mockAggTypesRegistry();
|
||||
const fieldFormats = fieldFormatsServiceMock.createStartContract();
|
||||
|
||||
const createAggConfigs = (aggs: IAggConfig[] = []) => {
|
||||
const field = {
|
||||
|
@ -42,6 +44,7 @@ describe('tabifyAggResponse Integration', () => {
|
|||
|
||||
return new AggConfigs(indexPattern, aggs, {
|
||||
typesRegistry,
|
||||
fieldFormats,
|
||||
});
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue