[Field formats] Correctly format numeric histograms outside Discover (#91576)

* [Field formats] Correctly format numeric histograms outside Discover

* Fix types

* Fix types

* Fix failures

* Fix merge issue

* Fix tests

* Fix i18n

* Fix i18n

* Add doc and fix integration

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Wylie Conlon 2021-03-03 13:13:57 -05:00 committed by GitHub
parent eec777b7ef
commit cae9ca4c19
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 415 additions and 81 deletions

View file

@ -34,5 +34,6 @@ fieldFormats: {
UrlFormat: typeof UrlFormat;
StringFormat: typeof StringFormat;
TruncateFormat: typeof TruncateFormat;
HistogramFormat: typeof HistogramFormat;
}
```

View file

@ -23,5 +23,6 @@ fieldFormats: {
UrlFormat: typeof UrlFormat;
StringFormat: typeof StringFormat;
TruncateFormat: typeof TruncateFormat;
HistogramFormat: typeof HistogramFormat;
}
```

View file

@ -57,11 +57,17 @@ include::field-formatters/string-formatter.asciidoc[]
[[field-formatters-numeric]]
=== Numeric field formatters
Numeric fields support the `Url`, `Bytes`, `Duration`, `Number`, `Percentage`, `String`, and `Color` formatters.
Numeric fields support the `Url`, `Bytes`, `Duration`, `Number`, `Percentage`, `Histogram`, `String`, and `Color` formatters.
The `Bytes`, `Number`, and `Percentage` formatters enable you to choose the display formats of numbers in this field using
the <<numeral, Elastic numeral pattern>> syntax that {kib} maintains.
The `Histogram` formatter is only used for the {ref}/histogram.html[histogram field type]. When using the `Histogram` formatter,
you can apply the `Number`, `Bytes`, or `Percentage` format to the aggregated data.
`Number`, and `Percentage` formatters enable you to choose the display formats of numbers in this field using
the <<numeral, Elastic numeral pattern>> syntax that {kib} maintains.
include::field-formatters/url-formatter.asciidoc[]
include::field-formatters/string-formatter.asciidoc[]

View file

@ -22,6 +22,7 @@ import {
StringFormat,
TruncateFormat,
UrlFormat,
HistogramFormat,
} from '../converters';
export const baseFormatters: FieldFormatInstanceType[] = [
@ -38,4 +39,5 @@ export const baseFormatters: FieldFormatInstanceType[] = [
StringFormat,
TruncateFormat,
UrlFormat,
HistogramFormat,
];

View file

@ -0,0 +1,51 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { i18n } from '@kbn/i18n';
import { FieldFormat } from '../field_format';
import { KBN_FIELD_TYPES } from '../../kbn_field_types/types';
import { TextContextTypeConvert, FIELD_FORMAT_IDS } from '../types';
import { BytesFormat } from './bytes';
import { NumberFormat } from './number';
import { PercentFormat } from './percent';
export class HistogramFormat extends FieldFormat {
static id = FIELD_FORMAT_IDS.HISTOGRAM;
static fieldType = KBN_FIELD_TYPES.HISTOGRAM;
static title = i18n.translate('data.fieldFormats.histogram.title', {
defaultMessage: 'Histogram',
});
id = HistogramFormat.id;
title = HistogramFormat.title;
allowsNumericalAggregations = true;
// Nested internal formatter
getParamDefaults() {
return {
id: 'number',
params: {},
};
}
textConvert: TextContextTypeConvert = (val) => {
if (typeof val === 'number') {
const subFormatId = this.param('id');
const SubFormat =
subFormatId === 'bytes'
? BytesFormat
: subFormatId === 'percent'
? PercentFormat
: NumberFormat;
const converter = new SubFormat(this.param('params'), this.getConfig);
return converter.textConvert(val);
} else {
return JSON.stringify(val);
}
};
}

View file

@ -19,3 +19,4 @@ export { ColorFormat } from './color';
export { TruncateFormat } from './truncate';
export { BoolFormat } from './boolean';
export { StaticLookupFormat } from './static_lookup';
export { HistogramFormat } from './histogram';

View file

@ -27,6 +27,7 @@ export {
UrlFormat,
StringFormat,
TruncateFormat,
HistogramFormat,
} from './converters';
export { getHighlightRequest } from './utils';

View file

@ -56,6 +56,7 @@ export enum FIELD_FORMAT_IDS {
STRING = 'string',
TRUNCATE = 'truncate',
URL = 'url',
HISTOGRAM = 'histogram',
}
export interface FieldFormatConfig {

View file

@ -26,6 +26,7 @@ export const getAvgMetricAgg = () => {
name: METRIC_TYPES.AVG,
expressionName: aggAvgFnName,
title: averageTitle,
valueType: 'number',
makeLabel: (aggConfig) => {
return i18n.translate('data.search.aggs.metrics.averageLabel', {
defaultMessage: 'Average {field}',

View file

@ -26,6 +26,7 @@ export const getMaxMetricAgg = () => {
name: METRIC_TYPES.MAX,
expressionName: aggMaxFnName,
title: maxTitle,
valueType: 'number',
makeLabel(aggConfig) {
return i18n.translate('data.search.aggs.metrics.maxLabel', {
defaultMessage: 'Max {field}',

View file

@ -27,6 +27,7 @@ export const getMedianMetricAgg = () => {
expressionName: aggMedianFnName,
dslName: 'percentiles',
title: medianTitle,
valueType: 'number',
makeLabel(aggConfig) {
return i18n.translate('data.search.aggs.metrics.medianLabel', {
defaultMessage: 'Median {field}',

View file

@ -26,6 +26,7 @@ export const getMinMetricAgg = () => {
name: METRIC_TYPES.MIN,
expressionName: aggMinFnName,
title: minTitle,
valueType: 'number',
makeLabel(aggConfig) {
return i18n.translate('data.search.aggs.metrics.minLabel', {
defaultMessage: 'Min {field}',

View file

@ -42,6 +42,7 @@ export const getPercentilesMetricAgg = () => {
title: i18n.translate('data.search.aggs.metrics.percentilesTitle', {
defaultMessage: 'Percentiles',
}),
valueType: 'number',
makeLabel(agg) {
return i18n.translate('data.search.aggs.metrics.percentilesLabel', {
defaultMessage: 'Percentiles of {field}',

View file

@ -26,6 +26,7 @@ export const getSumMetricAgg = () => {
name: METRIC_TYPES.SUM,
expressionName: aggSumFnName,
title: sumTitle,
valueType: 'number',
makeLabel(aggConfig) {
return i18n.translate('data.search.aggs.metrics.sumLabel', {
defaultMessage: 'Sum of {field}',

View file

@ -158,6 +158,7 @@ import {
UrlFormat,
StringFormat,
TruncateFormat,
HistogramFormat,
} from '../common/field_formats';
import { DateNanosFormat, DateFormat } from './field_formats';
@ -188,6 +189,7 @@ export const fieldFormats = {
UrlFormat,
StringFormat,
TruncateFormat,
HistogramFormat,
};
export {

View file

@ -960,6 +960,7 @@ export const fieldFormats: {
UrlFormat: typeof UrlFormat;
StringFormat: typeof StringFormat;
TruncateFormat: typeof TruncateFormat;
HistogramFormat: typeof HistogramFormat;
};
// @public (undocumented)
@ -2638,41 +2639,42 @@ export const UI_SETTINGS: {
// src/plugins/data/public/index.ts:127:21 - (ae-forgotten-export) The symbol "getEsQueryConfig" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:127:21 - (ae-forgotten-export) The symbol "luceneStringToDsl" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:127:21 - (ae-forgotten-export) The symbol "decorateQuery" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:167:26 - (ae-forgotten-export) The symbol "FieldFormatsRegistry" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:167:26 - (ae-forgotten-export) The symbol "BoolFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:167:26 - (ae-forgotten-export) The symbol "BytesFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:167:26 - (ae-forgotten-export) The symbol "ColorFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:167:26 - (ae-forgotten-export) The symbol "DurationFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:167:26 - (ae-forgotten-export) The symbol "IpFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:167:26 - (ae-forgotten-export) The symbol "NumberFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:167:26 - (ae-forgotten-export) The symbol "PercentFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:167:26 - (ae-forgotten-export) The symbol "RelativeDateFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:167:26 - (ae-forgotten-export) The symbol "SourceFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:167:26 - (ae-forgotten-export) The symbol "StaticLookupFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:167:26 - (ae-forgotten-export) The symbol "UrlFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:167:26 - (ae-forgotten-export) The symbol "StringFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:167:26 - (ae-forgotten-export) The symbol "TruncateFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:209:23 - (ae-forgotten-export) The symbol "datatableToCSV" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:234:27 - (ae-forgotten-export) The symbol "isFilterable" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:234:27 - (ae-forgotten-export) The symbol "isNestedField" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:234:27 - (ae-forgotten-export) The symbol "validateIndexPattern" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:234:27 - (ae-forgotten-export) The symbol "flattenHitWrapper" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:234:27 - (ae-forgotten-export) The symbol "formatHitProvider" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:399:20 - (ae-forgotten-export) The symbol "getRequestInspectorStats" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:399:20 - (ae-forgotten-export) The symbol "getResponseInspectorStats" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:399:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:399:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:401:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:402:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:411:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:412:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:413:1 - (ae-forgotten-export) The symbol "Ipv4Address" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:414:1 - (ae-forgotten-export) The symbol "isDateHistogramBucketAggConfig" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:418:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:419:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:422:1 - (ae-forgotten-export) The symbol "parseInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:423:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:426:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:168:26 - (ae-forgotten-export) The symbol "FieldFormatsRegistry" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:168:26 - (ae-forgotten-export) The symbol "BoolFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:168:26 - (ae-forgotten-export) The symbol "BytesFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:168:26 - (ae-forgotten-export) The symbol "ColorFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:168:26 - (ae-forgotten-export) The symbol "DurationFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:168:26 - (ae-forgotten-export) The symbol "IpFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:168:26 - (ae-forgotten-export) The symbol "NumberFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:168:26 - (ae-forgotten-export) The symbol "PercentFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:168:26 - (ae-forgotten-export) The symbol "RelativeDateFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:168:26 - (ae-forgotten-export) The symbol "SourceFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:168:26 - (ae-forgotten-export) The symbol "StaticLookupFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:168:26 - (ae-forgotten-export) The symbol "UrlFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:168:26 - (ae-forgotten-export) The symbol "StringFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:168:26 - (ae-forgotten-export) The symbol "TruncateFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:168:26 - (ae-forgotten-export) The symbol "HistogramFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:211:23 - (ae-forgotten-export) The symbol "datatableToCSV" 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 "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:401:20 - (ae-forgotten-export) The symbol "getRequestInspectorStats" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:401:20 - (ae-forgotten-export) The symbol "getResponseInspectorStats" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:401:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:401:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:403:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:404:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:413:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:414:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:415:1 - (ae-forgotten-export) The symbol "Ipv4Address" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:416:1 - (ae-forgotten-export) The symbol "isDateHistogramBucketAggConfig" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:420:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:421:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:424:1 - (ae-forgotten-export) The symbol "parseInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:425:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:428: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:34:5 - (ae-forgotten-export) The symbol "FilterStateStore" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/search/session/session_service.ts:42:5 - (ae-forgotten-export) The symbol "UrlGeneratorStateMapping" needs to be exported by the entry point index.d.ts

View file

@ -95,6 +95,7 @@ import {
UrlFormat,
StringFormat,
TruncateFormat,
HistogramFormat,
} from '../common/field_formats';
export const fieldFormats = {
@ -113,6 +114,7 @@ export const fieldFormats = {
UrlFormat,
StringFormat,
TruncateFormat,
HistogramFormat,
};
export { IFieldFormatsRegistry, FieldFormatsGetConfigFn, FieldFormatConfig } from '../common';

View file

@ -533,6 +533,7 @@ export const fieldFormats: {
UrlFormat: typeof UrlFormat;
StringFormat: typeof StringFormat;
TruncateFormat: typeof TruncateFormat;
HistogramFormat: typeof HistogramFormat;
};
// Warning: (ae-forgotten-export) The symbol "GetConfigFn" needs to be exported by the entry point index.d.ts
@ -1444,37 +1445,38 @@ export function usageProvider(core: CoreSetup_2): SearchUsage;
// src/plugins/data/server/index.ts:46:23 - (ae-forgotten-export) The symbol "datatableToCSV" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:70:21 - (ae-forgotten-export) The symbol "getEsQueryConfig" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:70:21 - (ae-forgotten-export) The symbol "buildEsQuery" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:100:26 - (ae-forgotten-export) The symbol "FieldFormatsRegistry" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:100:26 - (ae-forgotten-export) The symbol "FieldFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:100:26 - (ae-forgotten-export) The symbol "BoolFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:100:26 - (ae-forgotten-export) The symbol "BytesFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:100:26 - (ae-forgotten-export) The symbol "ColorFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:100:26 - (ae-forgotten-export) The symbol "DurationFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:100:26 - (ae-forgotten-export) The symbol "IpFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:100:26 - (ae-forgotten-export) The symbol "NumberFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:100:26 - (ae-forgotten-export) The symbol "PercentFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:100:26 - (ae-forgotten-export) The symbol "RelativeDateFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:100:26 - (ae-forgotten-export) The symbol "SourceFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:100:26 - (ae-forgotten-export) The symbol "StaticLookupFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:100:26 - (ae-forgotten-export) The symbol "UrlFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:100:26 - (ae-forgotten-export) The symbol "StringFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:100:26 - (ae-forgotten-export) The symbol "TruncateFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:126:27 - (ae-forgotten-export) The symbol "isFilterable" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:126:27 - (ae-forgotten-export) The symbol "isNestedField" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:241:20 - (ae-forgotten-export) The symbol "getRequestInspectorStats" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:241:20 - (ae-forgotten-export) The symbol "getResponseInspectorStats" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:241:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:241:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:243:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:244:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:253:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:254:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:255:1 - (ae-forgotten-export) The symbol "Ipv4Address" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:259:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:260:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:264:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:267:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:268:1 - (ae-forgotten-export) The symbol "calcAutoIntervalLessThan" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:101:26 - (ae-forgotten-export) The symbol "FieldFormatsRegistry" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:101:26 - (ae-forgotten-export) The symbol "FieldFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:101:26 - (ae-forgotten-export) The symbol "BoolFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:101:26 - (ae-forgotten-export) The symbol "BytesFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:101:26 - (ae-forgotten-export) The symbol "ColorFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:101:26 - (ae-forgotten-export) The symbol "DurationFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:101:26 - (ae-forgotten-export) The symbol "IpFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:101:26 - (ae-forgotten-export) The symbol "NumberFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:101:26 - (ae-forgotten-export) The symbol "PercentFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:101:26 - (ae-forgotten-export) The symbol "RelativeDateFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:101:26 - (ae-forgotten-export) The symbol "SourceFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:101:26 - (ae-forgotten-export) The symbol "StaticLookupFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:101:26 - (ae-forgotten-export) The symbol "UrlFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:101:26 - (ae-forgotten-export) The symbol "StringFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:101:26 - (ae-forgotten-export) The symbol "TruncateFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:101:26 - (ae-forgotten-export) The symbol "HistogramFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:128:27 - (ae-forgotten-export) The symbol "isFilterable" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:128:27 - (ae-forgotten-export) The symbol "isNestedField" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:243:20 - (ae-forgotten-export) The symbol "getRequestInspectorStats" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:243:20 - (ae-forgotten-export) The symbol "getResponseInspectorStats" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:243:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:243:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:245:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:246:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:255:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:256:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:257:1 - (ae-forgotten-export) The symbol "Ipv4Address" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:261:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:262:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:266:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:269:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:270:1 - (ae-forgotten-export) The symbol "calcAutoIntervalLessThan" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/plugin.ts:79:74 - (ae-forgotten-export) The symbol "DataEnhancements" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/search/types.ts:114:5 - (ae-forgotten-export) The symbol "ISearchStartSearchSource" needs to be exported by the entry point index.d.ts

View file

@ -355,6 +355,7 @@ export function getUiSettings(): Record<string, UiSettingsParams<unknown>> {
"date_nanos": { "id": "date_nanos", "params": {}, "es": true },
"number": { "id": "number", "params": {} },
"boolean": { "id": "boolean", "params": {} },
"histogram": { "id": "histogram", "params": {} },
"_source": { "id": "_source", "params": {} },
"_default_": { "id": "string", "params": {} }
}`,
@ -389,6 +390,10 @@ export function getUiSettings(): Record<string, UiSettingsParams<unknown>> {
id: schema.string(),
params: schema.object({}),
}),
histogram: schema.object({
id: schema.string(),
params: schema.object({}),
}),
_source: schema.object({
id: schema.string(),
params: schema.object({}),

View file

@ -102,6 +102,9 @@ export const fieldMappings = {
bytes: {
type: 'long',
},
bytes_histogram: {
type: 'histogram',
},
tags: {
type: 'text',
fields: {

View file

@ -10,7 +10,8 @@ import React from 'react';
import { shallow } from 'enzyme';
import { FieldFormat } from 'src/plugins/data/public';
import { DefaultFormatEditor, convertSampleInput, ConverterParams } from './default';
import { SampleInput } from '../../types';
import { DefaultFormatEditor, convertSampleInput } from './default';
const fieldType = 'number';
const format = {
@ -22,7 +23,7 @@ const onError = jest.fn();
describe('DefaultFormatEditor', () => {
describe('convertSampleInput', () => {
const converter = (input: ConverterParams) => {
const converter = (input: SampleInput) => {
if (typeof input !== 'number') {
throw new Error('Input is not a number');
} else {

View file

@ -10,14 +10,12 @@ import React, { PureComponent, ReactText } from 'react';
import { i18n } from '@kbn/i18n';
import { FieldFormat, FieldFormatsContentType } from 'src/plugins/data/public';
import { Sample } from '../../types';
import { Sample, SampleInput } from '../../types';
import { FormatSelectEditorProps } from '../../field_format_editor';
export type ConverterParams = string | number | Array<string | number>;
export const convertSampleInput = (
converter: (input: ConverterParams) => string,
inputs: ConverterParams[]
converter: (input: SampleInput) => string,
inputs: SampleInput[]
) => {
let error;
let samples: Sample[] = [];
@ -55,7 +53,7 @@ export interface FormatEditorProps<P> {
}
export interface FormatEditorState {
sampleInputs: ReactText[];
sampleInputs: SampleInput[];
sampleConverterType: FieldFormatsContentType;
error?: string;
samples: Sample[];
@ -63,7 +61,7 @@ export interface FormatEditorState {
}
export const defaultState = {
sampleInputs: [] as ReactText[],
sampleInputs: [] as SampleInput[],
sampleConverterType: 'text' as FieldFormatsContentType,
error: undefined,
samples: [] as Sample[],

View file

@ -0,0 +1,74 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`HistogramFormatEditor should render normally 1`] = `
<Fragment>
<EuiFormRow
describedByIds={Array []}
display="row"
fullWidth={false}
hasChildLabel={true}
hasEmptyLabelSpace={false}
label="Aggregated number format"
labelType="label"
>
<EuiSelect
onChange={[Function]}
options={
Array [
Object {
"text": "Number",
"value": "number",
},
Object {
"text": "Bytes",
"value": "bytes",
},
Object {
"text": "Percentage",
"value": "percent",
},
]
}
value="number"
/>
</EuiFormRow>
<EuiFormRow
describedByIds={Array []}
display="row"
fullWidth={false}
hasChildLabel={true}
hasEmptyLabelSpace={false}
helpText={
<span>
<EuiLink
href="https://adamwdraper.github.io/Numeral-js/"
target="_blank"
>
<FormattedMessage
defaultMessage="Documentation"
id="indexPatternFieldEditor.number.documentationLabel"
values={Object {}}
/>
 
<EuiIcon
type="link"
/>
</EuiLink>
</span>
}
isInvalid={false}
label="Numeral format pattern (optional)"
labelType="label"
>
<EuiFieldText
isInvalid={false}
onChange={[Function]}
value=""
/>
</EuiFormRow>
<FormatEditorSamples
sampleType="text"
samples={Array []}
/>
</Fragment>
`;

View file

@ -0,0 +1,51 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import React from 'react';
import { shallow } from 'enzyme';
import { FieldFormat } from 'src/plugins/data/public';
import { HistogramFormatEditor } from './histogram';
const fieldType = 'histogram';
const format = {
getConverterFor: jest
.fn()
.mockImplementation(() => (input: number | Record<string, number[]>) =>
typeof input === 'number' ? input.toFixed(2) : JSON.stringify(input)
),
getParamDefaults: jest.fn().mockImplementation(() => {
return { id: 'number', params: {} };
}),
};
const formatParams = {
type: 'histogram',
id: 'number' as const,
params: {},
};
const onChange = jest.fn();
const onError = jest.fn();
describe('HistogramFormatEditor', () => {
it('should have a formatId', () => {
expect(HistogramFormatEditor.formatId).toEqual('histogram');
});
it('should render normally', async () => {
const component = shallow(
<HistogramFormatEditor
fieldType={fieldType}
format={(format as unknown) as FieldFormat}
formatParams={formatParams}
onChange={onChange}
onError={onError}
/>
);
expect(component).toMatchSnapshot();
});
});

View file

@ -0,0 +1,109 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import React, { Fragment } from 'react';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiSelect, EuiFieldText, EuiFormRow, EuiIcon, EuiLink } from '@elastic/eui';
import { DefaultFormatEditor, defaultState } from '../default';
import { FormatEditorSamples } from '../../samples';
export interface HistogramFormatEditorParams {
id: 'bytes' | 'percent' | 'number';
params: { pattern?: string } & Record<string, unknown>;
}
export class HistogramFormatEditor extends DefaultFormatEditor<HistogramFormatEditorParams> {
static formatId = 'histogram';
state = {
...defaultState,
sampleInputs: [
50.1234,
100.0001,
99.9999,
{ values: [0.00001, 99.9999, 200, 300], counts: [573, 102, 482] },
],
};
render() {
const { formatParams } = this.props;
const { error, samples } = this.state;
const numberOptions = [
{
value: 'number',
text: i18n.translate('indexPatternFieldEditor.histogram.subFormat.number', {
defaultMessage: 'Number',
}),
},
{
value: 'bytes',
text: i18n.translate('indexPatternFieldEditor.histogram.subFormat.bytes', {
defaultMessage: 'Bytes',
}),
},
{
value: 'percent',
text: i18n.translate('indexPatternFieldEditor.histogram.subFormat.percent', {
defaultMessage: 'Percentage',
}),
},
];
return (
<Fragment>
<EuiFormRow
label={i18n.translate('indexPatternFieldEditor.histogram.histogramAsNumberLabel', {
defaultMessage: 'Aggregated number format',
})}
>
<EuiSelect
options={numberOptions}
value={formatParams.id || 'number'}
onChange={(e) => {
this.onChange({ id: e.target.value });
}}
/>
</EuiFormRow>
<EuiFormRow
label={i18n.translate('indexPatternFieldEditor.histogram.numeralLabel', {
defaultMessage: 'Numeral format pattern (optional)',
})}
helpText={
<span>
<EuiLink target="_blank" href="https://adamwdraper.github.io/Numeral-js/">
<FormattedMessage
id="indexPatternFieldEditor.number.documentationLabel"
defaultMessage="Documentation"
/>
&nbsp;
<EuiIcon type="link" />
</EuiLink>
</span>
}
isInvalid={!!error}
error={error}
>
<EuiFieldText
value={formatParams?.params?.pattern ?? ''}
onChange={(e) => {
this.onChange({
params: {
pattern: e.target.value,
},
});
}}
isInvalid={!!error}
/>
</EuiFormRow>
<FormatEditorSamples samples={samples} />
</Fragment>
);
}
}

View file

@ -0,0 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
export { HistogramFormatEditor } from './histogram';

View file

@ -19,3 +19,4 @@ export { StaticLookupFormatEditor } from './static_lookup';
export { StringFormatEditor } from './string';
export { TruncateFormatEditor } from './truncate';
export { UrlFormatEditor } from './url';
export { HistogramFormatEditor } from './histogram';

View file

@ -8,7 +8,9 @@
import { ReactText } from 'react';
export type SampleInput = ReactText | ReactText[] | Record<string, ReactText[]>;
export interface Sample {
input: ReactText | ReactText[];
input: SampleInput;
output: string;
}

View file

@ -20,6 +20,7 @@ import {
StringFormatEditor,
TruncateFormatEditor,
UrlFormatEditor,
HistogramFormatEditor,
} from '../components';
/**
@ -47,6 +48,7 @@ export class FormatEditorService {
StringFormatEditor,
TruncateFormatEditor,
UrlFormatEditor,
HistogramFormatEditor,
];
const fieldFormatEditorsSetup = this.fieldFormatEditors.setup(defaultFieldFormatEditors);

View file

@ -10,8 +10,9 @@ import { ReactText } from 'react';
import { Query } from 'src/plugins/data/public';
import { HttpStart } from 'src/core/public';
export type SampleInput = ReactText | ReactText[] | Record<string, ReactText | ReactText[]>;
export interface Sample {
input: ReactText | ReactText[];
input: SampleInput;
output: string;
}

View file

@ -28,7 +28,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
it('appears correctly in discover', async function () {
await PageObjects.common.navigateToApp('discover');
const rowData = await PageObjects.discover.getDocTableIndex(1);
expect(rowData.includes('"values": [ 0.3, 1, 3, 4.2, 4.8 ]')).to.be.ok();
expect(rowData.includes('"values":[0.3,1,3,4.2,4.8]')).to.be.ok();
});
describe('works in visualizations', () => {
@ -64,7 +64,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
it('with average aggregation', async () => {
const data = await renderTableForAggregation('Average');
expect(data).to.eql([['2.8653795982259327']]);
expect(data).to.eql([['2.865']]);
});
it('with median aggregation', async () => {
@ -79,7 +79,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
it('with sum aggregation', async () => {
const data = await renderTableForAggregation('Sum');
expect(data).to.eql([['10983']]);
expect(data).to.eql([['10,983']]);
});
});
});