forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[data views] Default field formatters based on field meta values (ela…
…stic#174973) ## Summary Default field formatters based on field meta units data. Note: the smallest unit our formatter will show is milliseconds which means micro and nanoseconds may round down to zero for smaller values. elastic#176112 Closes: elastic#82318 Mapping and doc setup for testing - ``` PUT my-index-000001 PUT my-index-000001/_mapping { "properties": { "nanos": { "type": "long", "meta": { "unit": "nanos" } }, "micros": { "type": "long", "meta": { "unit": "micros" } }, "ms": { "type": "long", "meta": { "unit": "ms" } }, "second": { "type": "long", "meta": { "unit": "s" } }, "minute": { "type": "long", "meta": { "unit": "m" } }, "hour": { "type": "long", "meta": { "unit": "h" } }, "day": { "type": "long", "meta": { "unit": "d" } }, "percent": { "type": "long", "meta": { "unit": "percent" } }, "bytes": { "type": "long", "meta": { "unit": "byte" } } } } POST my-index-000001/_doc { "nanos" : 1234.5, "micros" : 1234.5, "ms" : 1234.5, "second" : 1234.5, "minute" : 1234.5, "hour" : 1234.5, "day" : 1234.5, "percent" : 1234.5, "bytes" : 1234.5 } ```
- Loading branch information
Showing
10 changed files
with
128 additions
and
1 deletion.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
src/plugins/data_views/common/data_views/__snapshots__/data_views.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/plugins/data_views/common/data_views/meta_units_to_formatter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* 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 { FieldFormatParams } from '@kbn/field-formats-plugin/common'; | ||
|
||
const timeUnitToDurationFmt = (inputFormat = 'milliseconds') => { | ||
return { | ||
id: 'duration', | ||
params: { | ||
inputFormat, | ||
outputFormat: 'humanizePrecise', | ||
outputPrecision: 2, | ||
includeSpaceWithSuffix: true, | ||
useShortSuffix: true, | ||
}, | ||
}; | ||
}; | ||
|
||
export const metaUnitsToFormatter: Record<string, { id: string; params?: FieldFormatParams }> = { | ||
percent: { id: 'percent' }, | ||
byte: { id: 'bytes' }, | ||
nanos: timeUnitToDurationFmt('nanoseconds'), | ||
micros: timeUnitToDurationFmt('microseconds'), | ||
ms: timeUnitToDurationFmt('milliseconds'), | ||
s: timeUnitToDurationFmt('seconds'), | ||
m: timeUnitToDurationFmt('minutes'), | ||
h: timeUnitToDurationFmt('hours'), | ||
d: timeUnitToDurationFmt('days'), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters