[data.search.aggs]: Add AggConfig.toSerializedFieldFormat (#69114)

This commit is contained in:
Luke Elmers 2020-06-24 07:52:21 -06:00 committed by GitHub
parent 82df228c95
commit 51a0b11c29
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
42 changed files with 472 additions and 254 deletions

View file

@ -10,7 +10,6 @@
fieldFormats: {
FieldFormat: typeof FieldFormat;
FieldFormatsRegistry: typeof FieldFormatsRegistry;
serialize: (agg: import("./search").AggConfig) => import("../../expressions").SerializedFieldFormat<object>;
DEFAULT_CONVERTER_COLOR: {
range: string;
regex: string;

View file

@ -10,7 +10,6 @@
fieldFormats: {
FieldFormatsRegistry: typeof FieldFormatsRegistry;
FieldFormat: typeof FieldFormat;
serializeFieldFormat: (agg: import("../public/search").AggConfig) => import("../../expressions").SerializedFieldFormat<object>;
BoolFormat: typeof BoolFormat;
BytesFormat: typeof BytesFormat;
ColorFormat: typeof ColorFormat;

View file

@ -10,7 +10,7 @@
setup(core: CoreSetup<object, DataPluginStart>, { usageCollection }: DataPluginSetupDependencies): {
search: ISearchSetup;
fieldFormats: {
register: (customFieldFormat: import("../public").FieldFormatInstanceType) => number;
register: (customFieldFormat: import("../common").FieldFormatInstanceType) => number;
};
};
```
@ -27,7 +27,7 @@ setup(core: CoreSetup<object, DataPluginStart>, { usageCollection }: DataPluginS
`{
search: ISearchSetup;
fieldFormats: {
register: (customFieldFormat: import("../public").FieldFormatInstanceType) => number;
register: (customFieldFormat: import("../common").FieldFormatInstanceType) => number;
};
}`

View file

@ -1,21 +0,0 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
export { buildPipeline } from '../../../../../../plugins/visualizations/public/legacy/build_pipeline';

View file

@ -1,31 +0,0 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { npStart } from 'ui/new_platform';
import { fieldFormats, IFieldFormat } from '../../../../../../plugins/data/public';
import { SerializedFieldFormat } from '../../../../../../plugins/expressions/common/types';
type FormatFactory = (mapping?: SerializedFieldFormat) => IFieldFormat;
const createFormat = fieldFormats.serialize;
const getFormat: FormatFactory = (mapping?) => {
return npStart.plugins.data.fieldFormats.deserialize(mapping as any);
};
export { getFormat, createFormat, FormatFactory };

View file

@ -40,7 +40,7 @@ export {
TruncateFormat,
} from './converters';
export { getHighlightRequest, serializeFieldFormat } from './utils';
export { getHighlightRequest } from './utils';
export { DEFAULT_CONVERTER_COLOR } from './constants/color_default';
export { FIELD_FORMAT_IDS } from './types';

View file

@ -22,6 +22,5 @@ import { IFieldFormat } from '../index';
export { asPrettyString } from './as_pretty_string';
export { getHighlightHtml, getHighlightRequest } from './highlight';
export { serializeFieldFormat } from './serialize';
export type FormatFactory = (mapping?: SerializedFieldFormat) => IFieldFormat;

View file

@ -1,53 +0,0 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { IAggConfig } from 'src/plugins/data/public';
import { SerializedFieldFormat } from '../../../../expressions/common/types';
export const serializeFieldFormat = (agg: IAggConfig): SerializedFieldFormat => {
const format: SerializedFieldFormat = agg.params.field ? agg.params.field.format.toJSON() : {};
const formats: Record<string, () => SerializedFieldFormat> = {
date_range: () => ({ id: 'date_range', params: format }),
ip_range: () => ({ id: 'ip_range', params: format }),
percentile_ranks: () => ({ id: 'percent' }),
count: () => ({ id: 'number' }),
cardinality: () => ({ id: 'number' }),
date_histogram: () => ({
id: 'date',
params: {
pattern: (agg as any).buckets.getScaledDateFormat(),
},
}),
terms: () => ({
id: 'terms',
params: {
id: format.id,
otherBucketLabel: agg.params.otherBucketLabel,
missingBucketLabel: agg.params.missingBucketLabel,
...format.params,
},
}),
range: () => ({
id: 'range',
params: { id: format.id, ...format.params },
}),
};
return formats[agg.type.name] ? formats[agg.type.name]() : format;
};

View file

@ -168,7 +168,6 @@ import {
UrlFormat,
StringFormat,
TruncateFormat,
serializeFieldFormat,
} from '../common/field_formats';
import { DateFormat } from './field_formats';
@ -179,8 +178,6 @@ export const fieldFormats = {
FieldFormat,
FieldFormatsRegistry, // exported only for tests. Consider mock.
serialize: serializeFieldFormat,
DEFAULT_CONVERTER_COLOR,
HTML_CONTEXT_TYPE,
TEXT_CONTEXT_TYPE,

View file

@ -154,6 +154,7 @@ import { SearchParams } from 'elasticsearch';
import { SearchResponse as SearchResponse_2 } from 'elasticsearch';
import { SearchShardsParams } from 'elasticsearch';
import { SearchTemplateParams } from 'elasticsearch';
import { SerializedFieldFormat as SerializedFieldFormat_2 } from 'src/plugins/expressions/public';
import { SimpleSavedObject } from 'src/core/public';
import { SnapshotCreateParams } from 'elasticsearch';
import { SnapshotCreateRepositoryParams } from 'elasticsearch';
@ -621,7 +622,6 @@ export type FieldFormatInstanceType = (new (params?: any, getConfig?: FieldForma
export const fieldFormats: {
FieldFormat: typeof FieldFormat;
FieldFormatsRegistry: typeof FieldFormatsRegistry;
serialize: (agg: import("./search").AggConfig) => import("../../expressions").SerializedFieldFormat<object>;
DEFAULT_CONVERTER_COLOR: {
range: string;
regex: string;
@ -1954,41 +1954,41 @@ export const UI_SETTINGS: {
// src/plugins/data/public/index.ts:136:21 - (ae-forgotten-export) The symbol "getEsQueryConfig" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:136:21 - (ae-forgotten-export) The symbol "luceneStringToDsl" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:136:21 - (ae-forgotten-export) The symbol "decorateQuery" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:178:26 - (ae-forgotten-export) The symbol "FieldFormatsRegistry" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:178:26 - (ae-forgotten-export) The symbol "BoolFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:178:26 - (ae-forgotten-export) The symbol "BytesFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:178:26 - (ae-forgotten-export) The symbol "ColorFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:178:26 - (ae-forgotten-export) The symbol "DateNanosFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:178:26 - (ae-forgotten-export) The symbol "DurationFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:178:26 - (ae-forgotten-export) The symbol "IpFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:178:26 - (ae-forgotten-export) The symbol "NumberFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:178:26 - (ae-forgotten-export) The symbol "PercentFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:178:26 - (ae-forgotten-export) The symbol "RelativeDateFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:178:26 - (ae-forgotten-export) The symbol "SourceFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:178:26 - (ae-forgotten-export) The symbol "StaticLookupFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:178:26 - (ae-forgotten-export) The symbol "UrlFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:178:26 - (ae-forgotten-export) The symbol "StringFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:178:26 - (ae-forgotten-export) The symbol "TruncateFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:236:27 - (ae-forgotten-export) The symbol "isFilterable" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:236:27 - (ae-forgotten-export) The symbol "isNestedField" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:236:27 - (ae-forgotten-export) The symbol "validateIndexPattern" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:236:27 - (ae-forgotten-export) The symbol "getFromSavedObject" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:236:27 - (ae-forgotten-export) The symbol "flattenHitWrapper" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:236:27 - (ae-forgotten-export) The symbol "formatHitProvider" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:376:20 - (ae-forgotten-export) The symbol "getRequestInspectorStats" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:376:20 - (ae-forgotten-export) The symbol "getResponseInspectorStats" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:376:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:376:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:378:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:379:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:388:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:389:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:390:1 - (ae-forgotten-export) The symbol "isDateHistogramBucketAggConfig" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:394:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:395:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:398:1 - (ae-forgotten-export) The symbol "parseInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:399:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:402:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:177:26 - (ae-forgotten-export) The symbol "FieldFormatsRegistry" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:177:26 - (ae-forgotten-export) The symbol "BoolFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:177:26 - (ae-forgotten-export) The symbol "BytesFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:177:26 - (ae-forgotten-export) The symbol "ColorFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:177:26 - (ae-forgotten-export) The symbol "DateNanosFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:177:26 - (ae-forgotten-export) The symbol "DurationFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:177:26 - (ae-forgotten-export) The symbol "IpFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:177:26 - (ae-forgotten-export) The symbol "NumberFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:177:26 - (ae-forgotten-export) The symbol "PercentFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:177:26 - (ae-forgotten-export) The symbol "RelativeDateFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:177:26 - (ae-forgotten-export) The symbol "SourceFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:177:26 - (ae-forgotten-export) The symbol "StaticLookupFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:177:26 - (ae-forgotten-export) The symbol "UrlFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:177:26 - (ae-forgotten-export) The symbol "StringFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:177:26 - (ae-forgotten-export) The symbol "TruncateFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:233:27 - (ae-forgotten-export) The symbol "isFilterable" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:233:27 - (ae-forgotten-export) The symbol "isNestedField" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:233:27 - (ae-forgotten-export) The symbol "validateIndexPattern" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:233:27 - (ae-forgotten-export) The symbol "getFromSavedObject" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:233:27 - (ae-forgotten-export) The symbol "flattenHitWrapper" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:233:27 - (ae-forgotten-export) The symbol "formatHitProvider" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:373:20 - (ae-forgotten-export) The symbol "getRequestInspectorStats" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:373:20 - (ae-forgotten-export) The symbol "getResponseInspectorStats" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:373:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:373:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:375:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:376:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:385:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:386:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:387:1 - (ae-forgotten-export) The symbol "isDateHistogramBucketAggConfig" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:391:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:392:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:395:1 - (ae-forgotten-export) The symbol "parseInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:396:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:399:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/query/state_sync/connect_to_query_state.ts:40:60 - (ae-forgotten-export) The symbol "FilterStateStore" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/types.ts:52:5 - (ae-forgotten-export) The symbol "createFiltersFromValueClickAction" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/types.ts:53:5 - (ae-forgotten-export) The symbol "createFiltersFromRangeSelectAction" needs to be exported by the entry point index.d.ts

View file

@ -25,7 +25,11 @@ import { AggType } from './agg_type';
import { AggTypesRegistryStart } from './agg_types_registry';
import { mockDataServices, mockAggTypesRegistry } from './test_helpers';
import { MetricAggType } from './metrics/metric_agg_type';
import { Field as IndexPatternField, IndexPattern } from '../../index_patterns';
import {
Field as IndexPatternField,
IndexPattern,
IIndexPatternFieldList,
} from '../../index_patterns';
import { stubIndexPatternWithFields } from '../../../public/stubs';
import { FieldFormatsStart } from '../../field_formats';
import { fieldFormatsServiceMock } from '../../field_formats/mocks';
@ -370,6 +374,109 @@ describe('AggConfig', () => {
});
});
describe('#toSerializedFieldFormat', () => {
beforeEach(() => {
indexPattern.fields.getByName = identity as IIndexPatternFieldList['getByName'];
});
it('works with aggs that have a special format type', () => {
const configStates = [
{
type: 'count',
params: {},
},
{
type: 'date_histogram',
params: { field: '@timestamp' },
},
{
type: 'terms',
params: { field: 'machine.os.keyword' },
},
];
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry, fieldFormats });
expect(ac.aggs.map((agg) => agg.toSerializedFieldFormat())).toMatchInlineSnapshot(`
Array [
Object {
"id": "number",
},
Object {
"id": "date",
"params": Object {
"pattern": "HH:mm:ss.SSS",
},
},
Object {
"id": "terms",
"params": Object {
"id": undefined,
"missingBucketLabel": "Missing",
"otherBucketLabel": "Other",
},
},
]
`);
});
it('works with pipeline aggs', () => {
const configStates = [
{
type: 'max_bucket',
params: {
customMetric: {
type: 'cardinality',
params: {
field: 'bytes',
},
},
},
},
{
type: 'cumulative_sum',
params: {
buckets_path: '1',
customMetric: {
type: 'cardinality',
params: {
field: 'bytes',
},
},
},
},
{
type: 'percentile_ranks',
id: 'myMetricAgg',
params: {},
},
{
type: 'cumulative_sum',
params: {
metricAgg: 'myMetricAgg',
},
},
];
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry, fieldFormats });
expect(ac.aggs.map((agg) => agg.toSerializedFieldFormat())).toMatchInlineSnapshot(`
Array [
Object {
"id": "number",
},
Object {
"id": "number",
},
Object {
"id": "percent",
},
Object {
"id": "percent",
},
]
`);
});
});
describe('#toExpressionAst', () => {
beforeEach(() => {
fieldFormats.getDefaultInstance = (() => ({

View file

@ -20,7 +20,11 @@
import _ from 'lodash';
import { i18n } from '@kbn/i18n';
import { Assign, Ensure } from '@kbn/utility-types';
import { ExpressionAstFunction, ExpressionAstArgument } from 'src/plugins/expressions/public';
import {
ExpressionAstFunction,
ExpressionAstArgument,
SerializedFieldFormat,
} from 'src/plugins/expressions/public';
import { IAggType } from './agg_type';
import { writeParams } from './agg_params';
import { IAggConfigs } from './agg_configs';
@ -42,7 +46,7 @@ export type AggConfigSerialized = Ensure<
type: string;
enabled?: boolean;
id?: string;
params?: SerializableState;
params?: {} | SerializableState;
schema?: string;
},
SerializableState
@ -298,8 +302,8 @@ export class AggConfig {
id: this.id,
enabled: this.enabled,
type: this.type && this.type.name,
schema: this.schema,
params: outParams as SerializableState,
...(this.schema && { schema: this.schema }),
};
}
@ -310,6 +314,19 @@ export class AggConfig {
return this.serialize();
}
/**
* Returns a serialized field format for the field used in this agg.
* This can be passed to fieldFormats.deserialize to get the field
* format instance.
*
* @public
*/
toSerializedFieldFormat():
| {}
| Ensure<SerializedFieldFormat<SerializableState>, SerializableState> {
return this.type ? this.type.getSerializedFormat(this) : {};
}
/**
* @returns Returns an ExpressionAst representing the function for this agg type.
*/

View file

@ -199,5 +199,73 @@ describe('AggType Class', () => {
expect(aggType.getFormat(aggConfig)).toBe('default');
});
});
describe('getSerializedFormat', () => {
test('returns the default serialized field format if it exists', () => {
const aggConfig = ({
params: {
field: {
format: {
toJSON: () => ({ id: 'format' }),
},
},
},
} as unknown) as IAggConfig;
const aggType = new AggType(
{
name: 'name',
title: 'title',
},
dependencies
);
expect(aggType.getSerializedFormat(aggConfig)).toMatchInlineSnapshot(`
Object {
"id": "format",
}
`);
});
test('returns an empty object if a field param does not exist', () => {
const aggConfig = ({
params: {},
} as unknown) as IAggConfig;
const aggType = new AggType(
{
name: 'name',
title: 'title',
},
dependencies
);
expect(aggType.getSerializedFormat(aggConfig)).toMatchInlineSnapshot(`Object {}`);
});
test('uses a custom getSerializedFormat function if defined', () => {
const aggConfig = ({
params: {
field: {
format: {
toJSON: () => ({ id: 'format' }),
},
},
},
} as unknown) as IAggConfig;
const getSerializedFormat = jest.fn().mockReturnValue({ id: 'hello' });
const aggType = new AggType(
{
name: 'name',
title: 'title',
getSerializedFormat,
},
dependencies
);
const serialized = aggType.getSerializedFormat(aggConfig);
expect(getSerializedFormat).toHaveBeenCalledWith(aggConfig);
expect(serialized).toMatchInlineSnapshot(`
Object {
"id": "hello",
}
`);
});
});
});
});

View file

@ -19,8 +19,10 @@
import { constant, noop, identity } from 'lodash';
import { i18n } from '@kbn/i18n';
import { initParams } from './agg_params';
import { SerializedFieldFormat } from 'src/plugins/expressions/public';
import { initParams } from './agg_params';
import { AggConfig } from './agg_config';
import { IAggConfigs } from './agg_configs';
import { Adapters } from '../../../../../plugins/inspector/public';
@ -57,6 +59,7 @@ export interface AggTypeConfig<
abortSignal?: AbortSignal
) => Promise<any>;
getFormat?: (agg: TAggConfig) => IFieldFormat;
getSerializedFormat?: (agg: TAggConfig) => SerializedFieldFormat;
getValue?: (agg: TAggConfig, bucket: any) => any;
getKey?: (bucket: any, key: any, agg: TAggConfig) => any;
}
@ -204,6 +207,17 @@ export class AggType<
*/
getFormat: (agg: TAggConfig) => IFieldFormat;
/**
* Get the serialized format for the values produced by this agg type,
* overridden by several metrics that always output a simple number.
* You can pass this output to fieldFormatters.deserialize to get
* the formatter instance.
*
* @param {agg} agg - the agg to pick a format for
* @return {SerializedFieldFormat}
*/
getSerializedFormat: (agg: TAggConfig) => SerializedFieldFormat;
getValue: (agg: TAggConfig, bucket: any) => any;
getKey?: (bucket: any, key: any, agg: TAggConfig) => any;
@ -277,6 +291,13 @@ export class AggType<
return field ? field.format : fieldFormats.getDefaultInstance(KBN_FIELD_TYPES.STRING);
});
this.getSerializedFormat =
config.getSerializedFormat ||
((agg: TAggConfig) => {
return agg.params.field ? agg.params.field.format.toJSON() : {};
});
this.getValue = config.getValue || ((agg: TAggConfig, bucket: any) => {});
}
}

View file

@ -152,6 +152,14 @@ export const getDateHistogramBucketAgg = ({
(key: string) => uiSettings.get(key)
);
},
getSerializedFormat(agg) {
return {
id: 'date',
params: {
pattern: agg.buckets.getScaledDateFormat(),
},
};
},
params: [
{
name: 'field',

View file

@ -70,6 +70,12 @@ export const getDateRangeBucketAgg = ({
});
return new DateRangeFormat();
},
getSerializedFormat(agg) {
return {
id: 'date_range',
params: agg.params.field ? agg.params.field.format.toJSON() : {},
};
},
makeLabel(aggConfig) {
return aggConfig.getFieldDisplayName() + ' date ranges';
},

View file

@ -78,6 +78,12 @@ export const getIpRangeBucketAgg = ({ getInternalStartServices }: IpRangeBucketA
});
return new IpRangeFormat();
},
getSerializedFormat(agg) {
return {
id: 'ip_range',
params: agg.params.field ? agg.params.field.format.toJSON() : {},
};
},
makeLabel(aggConfig) {
return i18n.translate('data.search.aggs.buckets.ipRangeLabel', {
defaultMessage: '{fieldName} IP ranges',

View file

@ -48,7 +48,7 @@ function isValidMoment(m: any): boolean {
return m && 'isValid' in m && m.isValid();
}
export interface TimeBucketsConfig {
export interface TimeBucketsConfig extends Record<string, any> {
'histogram:maxBars': number;
'histogram:barTarget': number;
dateFormat: string;

View file

@ -104,7 +104,7 @@ describe('Range Agg', () => {
);
};
describe('formating', () => {
describe('formatting', () => {
test('formats bucket keys properly', () => {
const aggConfigs = getAggConfigs();
const agg = aggConfigs.aggs[0];
@ -115,4 +115,22 @@ describe('Range Agg', () => {
expect(format(buckets[2])).toBe('≥ 2.5 KB and < +∞');
});
});
describe('getSerializedFormat', () => {
test('generates a serialized field format in the expected shape', () => {
const aggConfigs = getAggConfigs();
const agg = aggConfigs.aggs[0];
expect(agg.type.getSerializedFormat(agg)).toMatchInlineSnapshot(`
Object {
"id": "range",
"params": Object {
"id": "number",
"params": Object {
"pattern": "0,0.[000] b",
},
},
}
`);
});
});
});

View file

@ -101,6 +101,16 @@ export const getRangeBucketAgg = ({ getInternalStartServices }: RangeBucketAggDe
formats.set(agg, aggFormat);
return aggFormat;
},
getSerializedFormat(agg) {
const format = agg.params.field ? agg.params.field.format.toJSON() : {};
return {
id: 'range',
params: {
id: format.id,
params: format.params,
},
};
},
params: [
{
name: 'field',

View file

@ -104,6 +104,18 @@ export const getTermsBucketAgg = ({ getInternalStartServices }: TermsBucketAggDe
},
} as IFieldFormat;
},
getSerializedFormat(agg) {
const format = agg.params.field ? agg.params.field.format.toJSON() : {};
return {
id: 'terms',
params: {
id: format.id,
otherBucketLabel: agg.params.otherBucketLabel,
missingBucketLabel: agg.params.missingBucketLabel,
...format.params,
},
};
},
createFilter: createFilterTerms,
postFlightRequest: async (
resp: any,

View file

@ -46,14 +46,17 @@ const averageBucketTitle = i18n.translate('data.search.aggs.metrics.averageBucke
export const getBucketAvgMetricAgg = ({
getInternalStartServices,
}: BucketAvgMetricAggDependencies) => {
const { subtype, params, getFormat, getSerializedFormat } = siblingPipelineAggHelper;
return new MetricAggType(
{
name: METRIC_TYPES.AVG_BUCKET,
title: averageBucketTitle,
makeLabel: (agg) => makeNestedLabel(agg, overallAverageLabel),
subtype: siblingPipelineAggHelper.subtype,
params: [...siblingPipelineAggHelper.params()],
getFormat: siblingPipelineAggHelper.getFormat,
subtype,
params: [...params()],
getFormat,
getSerializedFormat,
getValue(agg, bucket) {
const customMetric = agg.getParam('customMetric');
const customBucket = agg.getParam('customBucket');

View file

@ -45,14 +45,17 @@ const maxBucketTitle = i18n.translate('data.search.aggs.metrics.maxBucketTitle',
export const getBucketMaxMetricAgg = ({
getInternalStartServices,
}: BucketMaxMetricAggDependencies) => {
const { subtype, params, getFormat, getSerializedFormat } = siblingPipelineAggHelper;
return new MetricAggType(
{
name: METRIC_TYPES.MAX_BUCKET,
title: maxBucketTitle,
makeLabel: (agg) => makeNestedLabel(agg, overallMaxLabel),
subtype: siblingPipelineAggHelper.subtype,
params: [...siblingPipelineAggHelper.params()],
getFormat: siblingPipelineAggHelper.getFormat,
subtype,
params: [...params()],
getFormat,
getSerializedFormat,
},
{
getInternalStartServices,

View file

@ -45,14 +45,17 @@ const minBucketTitle = i18n.translate('data.search.aggs.metrics.minBucketTitle',
export const getBucketMinMetricAgg = ({
getInternalStartServices,
}: BucketMinMetricAggDependencies) => {
const { subtype, params, getFormat, getSerializedFormat } = siblingPipelineAggHelper;
return new MetricAggType(
{
name: METRIC_TYPES.MIN_BUCKET,
title: minBucketTitle,
makeLabel: (agg) => makeNestedLabel(agg, overallMinLabel),
subtype: siblingPipelineAggHelper.subtype,
params: [...siblingPipelineAggHelper.params()],
getFormat: siblingPipelineAggHelper.getFormat,
subtype,
params: [...params()],
getFormat,
getSerializedFormat,
},
{
getInternalStartServices,

View file

@ -45,14 +45,17 @@ const sumBucketTitle = i18n.translate('data.search.aggs.metrics.sumBucketTitle',
export const getBucketSumMetricAgg = ({
getInternalStartServices,
}: BucketSumMetricAggDependencies) => {
const { subtype, params, getFormat, getSerializedFormat } = siblingPipelineAggHelper;
return new MetricAggType(
{
name: METRIC_TYPES.SUM_BUCKET,
title: sumBucketTitle,
makeLabel: (agg) => makeNestedLabel(agg, overallSumLabel),
subtype: siblingPipelineAggHelper.subtype,
params: [...siblingPipelineAggHelper.params()],
getFormat: siblingPipelineAggHelper.getFormat,
subtype,
params: [...params()],
getFormat,
getSerializedFormat,
},
{
getInternalStartServices,

View file

@ -54,6 +54,11 @@ export const getCardinalityMetricAgg = ({
return fieldFormats.getDefaultInstance(KBN_FIELD_TYPES.NUMBER);
},
getSerializedFormat(agg) {
return {
id: 'number',
};
},
params: [
{
name: 'field',

View file

@ -45,6 +45,11 @@ export const getCountMetricAgg = ({ getInternalStartServices }: CountMetricAggDe
return fieldFormats.getDefaultInstance(KBN_FIELD_TYPES.NUMBER);
},
getSerializedFormat(agg) {
return {
id: 'number',
};
},
getValue(agg, bucket) {
return bucket.doc_count;
},

View file

@ -46,14 +46,17 @@ const cumulativeSumTitle = i18n.translate('data.search.aggs.metrics.cumulativeSu
export const getCumulativeSumMetricAgg = ({
getInternalStartServices,
}: CumulativeSumMetricAggDependencies) => {
const { subtype, params, getFormat, getSerializedFormat } = parentPipelineAggHelper;
return new MetricAggType(
{
name: METRIC_TYPES.CUMULATIVE_SUM,
title: cumulativeSumTitle,
subtype: parentPipelineAggHelper.subtype,
makeLabel: (agg) => makeNestedLabel(agg, cumulativeSumLabel),
params: [...parentPipelineAggHelper.params()],
getFormat: parentPipelineAggHelper.getFormat,
subtype,
params: [...params()],
getFormat,
getSerializedFormat,
},
{
getInternalStartServices,

View file

@ -46,16 +46,19 @@ const derivativeTitle = i18n.translate('data.search.aggs.metrics.derivativeTitle
export const getDerivativeMetricAgg = ({
getInternalStartServices,
}: DerivativeMetricAggDependencies) => {
const { subtype, params, getFormat, getSerializedFormat } = parentPipelineAggHelper;
return new MetricAggType(
{
name: METRIC_TYPES.DERIVATIVE,
title: derivativeTitle,
subtype: parentPipelineAggHelper.subtype,
makeLabel(agg) {
return makeNestedLabel(agg, derivativeLabel);
},
params: [...parentPipelineAggHelper.params()],
getFormat: parentPipelineAggHelper.getFormat,
subtype,
params: [...params()],
getFormat,
getSerializedFormat,
},
{
getInternalStartServices,

View file

@ -84,4 +84,16 @@ export const parentPipelineAggHelper = {
}
return subAgg ? subAgg.type.getFormat(subAgg) : new (FieldFormat.from(identity))();
},
getSerializedFormat(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.getSerializedFormat(subAgg) : {};
},
};

View file

@ -93,4 +93,9 @@ export const siblingPipelineAggHelper = {
? customMetric.type.getFormat(customMetric)
: new (FieldFormat.from(identity))();
},
getSerializedFormat(agg: IMetricAggConfig) {
const customMetric = agg.getParam('customMetric');
return customMetric ? customMetric.type.getSerializedFormat(customMetric) : {};
},
};

View file

@ -48,15 +48,19 @@ const movingAvgLabel = i18n.translate('data.search.aggs.metrics.movingAvgLabel',
export const getMovingAvgMetricAgg = ({
getInternalStartServices,
}: MovingAvgMetricAggDependencies) => {
const { subtype, params, getFormat, getSerializedFormat } = parentPipelineAggHelper;
return new MetricAggType(
{
name: METRIC_TYPES.MOVING_FN,
dslName: 'moving_fn',
title: movingAvgTitle,
subtype: parentPipelineAggHelper.subtype,
makeLabel: (agg) => makeNestedLabel(agg, movingAvgLabel),
subtype,
getFormat,
getSerializedFormat,
params: [
...parentPipelineAggHelper.params(),
...params(),
{
name: 'window',
default: 5,
@ -78,7 +82,6 @@ export const getMovingAvgMetricAgg = ({
*/
return bucket[agg.id] ? bucket[agg.id].value : null;
},
getFormat: parentPipelineAggHelper.getFormat,
},
{
getInternalStartServices,

View file

@ -103,6 +103,11 @@ export const getPercentileRanksMetricAgg = ({
fieldFormats.getDefaultInstance(KBN_FIELD_TYPES.NUMBER)
);
},
getSerializedFormat(agg) {
return {
id: 'percent',
};
},
getValue(agg, bucket) {
return getPercentileValue(agg, bucket) / 100;
},

View file

@ -46,14 +46,17 @@ const serialDiffLabel = i18n.translate('data.search.aggs.metrics.serialDiffLabel
export const getSerialDiffMetricAgg = ({
getInternalStartServices,
}: SerialDiffMetricAggDependencies) => {
const { subtype, params, getFormat, getSerializedFormat } = parentPipelineAggHelper;
return new MetricAggType(
{
name: METRIC_TYPES.SERIAL_DIFF,
title: serialDiffTitle,
subtype: parentPipelineAggHelper.subtype,
makeLabel: (agg) => makeNestedLabel(agg, serialDiffLabel),
params: [...parentPipelineAggHelper.params()],
getFormat: parentPipelineAggHelper.getFormat,
subtype,
params: [...params()],
getFormat,
getSerializedFormat,
},
{
getInternalStartServices,

View file

@ -25,6 +25,25 @@ import { MetricAggType } from '../metrics/metric_agg_type';
import { queryServiceMock } from '../../../query/mocks';
import { fieldFormatsServiceMock } from '../../../field_formats/mocks';
import { InternalStartServices } from '../../../types';
import { TimeBucketsConfig } from '../buckets/lib/time_buckets/time_buckets';
// Mocked uiSettings shared among aggs unit tests
const mockUiSettings = jest.fn().mockImplementation((key: string) => {
const config: TimeBucketsConfig = {
'histogram:maxBars': 4,
'histogram:barTarget': 3,
dateFormat: 'YYYY-MM-DD',
'dateFormat:scaled': [
['', 'HH:mm:ss.SSS'],
['PT1S', 'HH:mm:ss'],
['PT1M', 'HH:mm'],
['PT1H', 'YYYY-MM-DD HH:mm'],
['P1DT', 'YYYY-MM-DD'],
['P1YT', 'YYYY'],
],
};
return config[key] ?? key;
});
/**
* Testing utility which creates a new instance of AggTypesRegistry,
@ -54,7 +73,10 @@ export function mockAggTypesRegistry<T extends BucketAggType<any> | MetricAggTyp
});
} else {
const coreSetup = coreMock.createSetup();
coreSetup.uiSettings.get = mockUiSettings;
const coreStart = coreMock.createStart();
coreSetup.uiSettings.get = mockUiSettings;
const aggTypes = getAggTypes({
uiSettings: coreSetup.uiSettings,

View file

@ -32,14 +32,7 @@ import { Adapters } from '../../../../../plugins/inspector/public';
import { IAggConfigs } from '../aggs';
import { ISearchSource } from '../search_source';
import { tabifyAggResponse } from '../tabify';
import {
Filter,
Query,
serializeFieldFormat,
TimeRange,
IIndexPattern,
isRangeFilter,
} from '../../../common';
import { Filter, Query, TimeRange, IIndexPattern, isRangeFilter } from '../../../common';
import { FilterManager, calculateBounds, getTime } from '../../query';
import { getSearchService, getQueryService, getIndexPatterns } from '../../services';
import { buildTabularInspectorData } from './build_tabular_inspector_data';
@ -313,7 +306,7 @@ export const esaggs = (): ExpressionFunctionDefinition<typeof name, Input, Argum
meta: serializeAggConfig(column.aggConfig),
};
if (args.includeFormatHints) {
cleanedColumn.formatHint = serializeFieldFormat(column.aggConfig);
cleanedColumn.formatHint = column.aggConfig.toSerializedFieldFormat();
}
return cleanedColumn;
}),

View file

@ -97,13 +97,11 @@ import {
UrlFormat,
StringFormat,
TruncateFormat,
serializeFieldFormat,
} from '../common/field_formats';
export const fieldFormats = {
FieldFormatsRegistry,
FieldFormat,
serializeFieldFormat,
BoolFormat,
BytesFormat,
ColorFormat,

View file

@ -288,7 +288,6 @@ export interface FieldFormatConfig {
export const fieldFormats: {
FieldFormatsRegistry: typeof FieldFormatsRegistry;
FieldFormat: typeof FieldFormat;
serializeFieldFormat: (agg: import("../public/search").AggConfig) => import("../../expressions").SerializedFieldFormat<object>;
BoolFormat: typeof BoolFormat;
BytesFormat: typeof BytesFormat;
ColorFormat: typeof ColorFormat;
@ -631,7 +630,7 @@ export class Plugin implements Plugin_2<PluginSetup, PluginStart> {
setup(core: CoreSetup<object, PluginStart>, { usageCollection }: DataPluginSetupDependencies): {
search: ISearchSetup;
fieldFormats: {
register: (customFieldFormat: import("../public").FieldFormatInstanceType) => number;
register: (customFieldFormat: import("../common").FieldFormatInstanceType) => number;
};
};
// Warning: (ae-forgotten-export) The symbol "CoreStart" needs to be exported by the entry point index.d.ts
@ -774,30 +773,30 @@ export const UI_SETTINGS: {
// src/plugins/data/server/index.ts:40:23 - (ae-forgotten-export) The symbol "buildFilter" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:71:21 - (ae-forgotten-export) The symbol "getEsQueryConfig" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:71:21 - (ae-forgotten-export) The symbol "buildEsQuery" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "FieldFormatsRegistry" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "FieldFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "BoolFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "BytesFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "ColorFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "DateNanosFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "DurationFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "IpFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "NumberFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "PercentFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "RelativeDateFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "SourceFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "StaticLookupFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "UrlFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "StringFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:103:26 - (ae-forgotten-export) The symbol "TruncateFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:131:27 - (ae-forgotten-export) The symbol "isFilterable" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:131:27 - (ae-forgotten-export) The symbol "isNestedField" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:186:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:187:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:188:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:189:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:190:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:193:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "FieldFormatsRegistry" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "FieldFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "BoolFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "BytesFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "ColorFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "DateNanosFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "DurationFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "IpFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "NumberFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "PercentFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "RelativeDateFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "SourceFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "StaticLookupFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "UrlFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "StringFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:102:26 - (ae-forgotten-export) The symbol "TruncateFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:129:27 - (ae-forgotten-export) The symbol "isFilterable" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:129:27 - (ae-forgotten-export) The symbol "isNestedField" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:184:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:185:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:186:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:187:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:188:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:191:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts
// (No @packageDocumentation comment for this package)

View file

@ -66,7 +66,6 @@ const {
import { getRootBreadcrumbs, getSavedSearchBreadcrumbs } from '../helpers/breadcrumbs';
import {
esFilters,
fieldFormats,
indexPatterns as indexPatternsUtils,
connectToQueryState,
syncQueryStateWithUrl,
@ -851,7 +850,7 @@ function discoverController(
x: {
accessor: 0,
label: agg.makeLabel(),
format: fieldFormats.serialize(agg),
format: agg.toSerializedFieldFormat(),
params: {
date: true,
interval: moment.duration(esValue, esUnit),
@ -863,7 +862,7 @@ function discoverController(
},
y: {
accessor: 1,
format: fieldFormats.serialize(metric),
format: metric.toSerializedFieldFormat(),
label: metric.makeLabel(),
},
};

View file

@ -28,7 +28,7 @@ import {
} from './build_pipeline';
import { Vis } from '..';
import { dataPluginMock } from '../../../../plugins/data/public/mocks';
import { IAggConfig } from '../../../../plugins/data/public';
import { IndexPattern, IAggConfigs } from '../../../../plugins/data/public';
describe('visualize loader pipeline helpers: build pipeline', () => {
describe('prepareJson', () => {
@ -344,23 +344,20 @@ describe('visualize loader pipeline helpers: build pipeline', () => {
describe('buildVislibDimensions', () => {
const dataStart = dataPluginMock.createStartContract();
let aggs: IAggConfig[];
let aggs: IAggConfigs;
let vis: Vis;
let params: any;
beforeEach(() => {
aggs = [
aggs = dataStart.search.aggs.createAggConfigs({} as IndexPattern, [
{
id: '0',
enabled: true,
type: {
type: 'metrics',
name: 'count',
},
type: 'count',
schema: 'metric',
params: {},
} as IAggConfig,
];
},
]);
params = {
searchSource: null,
@ -393,11 +390,7 @@ describe('visualize loader pipeline helpers: build pipeline', () => {
],
},
data: {
aggs: {
getResponseAggs: () => {
return aggs;
},
} as any,
aggs,
searchSource: {} as any,
},
isHierarchical: () => {
@ -422,8 +415,13 @@ describe('visualize loader pipeline helpers: build pipeline', () => {
});
it('with two numeric metrics, mixed normal and percent mode should have corresponding formatters', async () => {
const aggConfig = aggs[0];
aggs = [{ ...aggConfig } as IAggConfig, { ...aggConfig, id: '5' } as IAggConfig];
aggs.createAggConfig({
id: '5',
enabled: true,
type: 'count',
schema: 'metric',
params: {},
});
vis.params = {
seriesParams: [
@ -469,11 +467,7 @@ describe('visualize loader pipeline helpers: build pipeline', () => {
},
params: { gauge: {} },
data: {
aggs: {
getResponseAggs: () => {
return aggs;
},
} as any,
aggs,
searchSource: {} as any,
},
isHierarchical: () => {

View file

@ -20,12 +20,7 @@
import { get } from 'lodash';
import moment from 'moment';
import { SerializedFieldFormat } from '../../../../plugins/expressions/public';
import {
IAggConfig,
fieldFormats,
search,
TimefilterContract,
} from '../../../../plugins/data/public';
import { IAggConfig, search, TimefilterContract } from '../../../../plugins/data/public';
import { Vis, VisParams } from '../types';
const { isDateHistogramBucketAggConfig } = search.aggs;
@ -113,11 +108,9 @@ const getSchemas = (
'max_bucket',
].includes(agg.type.name);
const format = fieldFormats.serialize(
hasSubAgg
? agg.params.customMetric || agg.aggConfigs.getRequestAggById(agg.params.metricAgg)
: agg
);
const formatAgg = hasSubAgg
? agg.params.customMetric || agg.aggConfigs.getRequestAggById(agg.params.metricAgg)
: agg;
const params: SchemaConfigParams = {};
@ -130,7 +123,7 @@ const getSchemas = (
return {
accessor,
format,
format: formatAgg.toSerializedFieldFormat(),
params,
label,
aggType: agg.type.name,

View file

@ -10,6 +10,8 @@
"include": [
"src/core/server/index.ts",
"src/core/public/index.ts",
"src/plugins/data/server/index.ts",
"src/plugins/data/public/index.ts",
"typings"
]
}