Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
"@elastic/eui": "18.3.0",
"@elastic/filesaver": "1.1.2",
"@elastic/good": "8.1.1-kibana2",
"@elastic/numeral": "2.3.3",
"@elastic/numeral": "2.3.5",
"@elastic/request-crypto": "^1.0.2",
"@elastic/ui-ace": "0.2.3",
"@hapi/wreck": "^15.0.1",
Expand Down
3 changes: 3 additions & 0 deletions src/legacy/core_plugins/kibana/ui_setting_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,9 @@ export function getUiSettingDefaults() {
value: 'en',
type: 'select',
options: numeralLanguageIds,
optionLabels: Object.fromEntries(
numeralLanguages.map(language => [language.id, language.name])
),
description: i18n.translate('kbn.advancedSettings.format.formattingLocaleText', {
defaultMessage: `{numeralLanguageLink} locale`,
description:
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/data/common/field_formats/converters/boolean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@
* under the License.
*/

import { i18n } from '@kbn/i18n';
import { KBN_FIELD_TYPES } from '../../kbn_field_types/types';
import { FieldFormat } from '../field_format';
import { TextContextTypeConvert, FIELD_FORMAT_IDS } from '../types';
import { asPrettyString } from '../utils';

export class BoolFormat extends FieldFormat {
static id = FIELD_FORMAT_IDS.BOOLEAN;
static title = 'Boolean';
static title = i18n.translate('data.fieldFormats.boolean.title', {
defaultMessage: 'Boolean',
});
static fieldType = [KBN_FIELD_TYPES.BOOLEAN, KBN_FIELD_TYPES.NUMBER, KBN_FIELD_TYPES.STRING];

textConvert: TextContextTypeConvert = value => {
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/data/common/field_formats/converters/bytes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
* under the License.
*/

import { i18n } from '@kbn/i18n';
import { NumeralFormat } from './numeral';
import { FIELD_FORMAT_IDS } from '../types';

export class BytesFormat extends NumeralFormat {
static id = FIELD_FORMAT_IDS.BYTES;
static title = 'Bytes';
static title = i18n.translate('data.fieldFormats.bytes.title', {
defaultMessage: 'Bytes',
});

id = BytesFormat.id;
title = BytesFormat.title;
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/data/common/field_formats/converters/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/

import { i18n } from '@kbn/i18n';
import { findLast, cloneDeep, template, escape } from 'lodash';
import { KBN_FIELD_TYPES } from '../../kbn_field_types/types';
import { FieldFormat } from '../field_format';
Expand All @@ -28,7 +29,9 @@ const convertTemplate = template('<span style="<%- style %>"><%- val %></span>')

export class ColorFormat extends FieldFormat {
static id = FIELD_FORMAT_IDS.COLOR;
static title = 'Color';
static title = i18n.translate('data.fieldFormats.color.title', {
defaultMessage: 'Color',
});
static fieldType = [KBN_FIELD_TYPES.NUMBER, KBN_FIELD_TYPES.STRING];

getParamDefaults() {
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/data/common/field_formats/converters/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/

import { i18n } from '@kbn/i18n';
import { memoize, noop } from 'lodash';
import moment from 'moment';
import { KBN_FIELD_TYPES } from '../../kbn_field_types/types';
Expand All @@ -25,7 +26,9 @@ import { TextContextTypeConvert, FIELD_FORMAT_IDS } from '../types';

export class DateFormat extends FieldFormat {
static id = FIELD_FORMAT_IDS.DATE;
static title = 'Date';
static title = i18n.translate('data.fieldFormats.date.title', {
defaultMessage: 'Date',
});
static fieldType = KBN_FIELD_TYPES.DATE;

private memoizedConverter: Function = noop;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/

import { i18n } from '@kbn/i18n';
import moment, { Moment } from 'moment';
import { memoize, noop } from 'lodash';
import { KBN_FIELD_TYPES } from '../../kbn_field_types/types';
Expand Down Expand Up @@ -70,7 +71,9 @@ export function formatWithNanos(

export class DateNanosFormat extends FieldFormat {
static id = FIELD_FORMAT_IDS.DATE_NANOS;
static title = 'Date Nanos';
static title = i18n.translate('data.fieldFormats.date_nanos.title', {
defaultMessage: 'Date nanos',
});
static fieldType = KBN_FIELD_TYPES.DATE;

private memoizedConverter: Function = noop;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/

import { i18n } from '@kbn/i18n';
import { memoize, noop } from 'lodash';
import moment from 'moment-timezone';
import { KBN_FIELD_TYPES } from '../../kbn_field_types/types';
Expand All @@ -30,14 +31,16 @@ import {

export class DateFormat extends FieldFormat {
static id = FIELD_FORMAT_IDS.DATE;
static title = 'Date';
static title = i18n.translate('data.fieldFormats.date.title', {
defaultMessage: 'Date',
});
static fieldType = KBN_FIELD_TYPES.DATE;

private memoizedConverter: Function = noop;
private memoizedPattern: string = '';
private timeZone: string = '';

constructor(params: IFieldFormatMetaParams, getConfig: GetConfigFn) {
constructor(params: IFieldFormatMetaParams, getConfig?: GetConfigFn) {
super(params, getConfig);

this.memoizedConverter = memoize((val: any) => {
Expand Down
51 changes: 29 additions & 22 deletions src/plugins/data/common/field_formats/converters/duration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,126 +31,126 @@ const ratioToSeconds: Record<string, number> = {
const HUMAN_FRIENDLY = 'humanize';
const DEFAULT_OUTPUT_PRECISION = 2;
const DEFAULT_INPUT_FORMAT = {
text: i18n.translate('data.common.fieldFormats.duration.inputFormats.seconds', {
text: i18n.translate('data.fieldFormats.duration.inputFormats.seconds', {
defaultMessage: 'Seconds',
}),
kind: 'seconds',
};
const inputFormats = [
{
text: i18n.translate('data.common.fieldFormats.duration.inputFormats.picoseconds', {
text: i18n.translate('data.fieldFormats.duration.inputFormats.picoseconds', {
defaultMessage: 'Picoseconds',
}),
kind: 'picoseconds',
},
{
text: i18n.translate('data.common.fieldFormats.duration.inputFormats.nanoseconds', {
text: i18n.translate('data.fieldFormats.duration.inputFormats.nanoseconds', {
defaultMessage: 'Nanoseconds',
}),
kind: 'nanoseconds',
},
{
text: i18n.translate('data.common.fieldFormats.duration.inputFormats.microseconds', {
text: i18n.translate('data.fieldFormats.duration.inputFormats.microseconds', {
defaultMessage: 'Microseconds',
}),
kind: 'microseconds',
},
{
text: i18n.translate('data.common.fieldFormats.duration.inputFormats.milliseconds', {
text: i18n.translate('data.fieldFormats.duration.inputFormats.milliseconds', {
defaultMessage: 'Milliseconds',
}),
kind: 'milliseconds',
},
{ ...DEFAULT_INPUT_FORMAT },
{
text: i18n.translate('data.common.fieldFormats.duration.inputFormats.minutes', {
text: i18n.translate('data.fieldFormats.duration.inputFormats.minutes', {
defaultMessage: 'Minutes',
}),
kind: 'minutes',
},
{
text: i18n.translate('data.common.fieldFormats.duration.inputFormats.hours', {
text: i18n.translate('data.fieldFormats.duration.inputFormats.hours', {
defaultMessage: 'Hours',
}),
kind: 'hours',
},
{
text: i18n.translate('data.common.fieldFormats.duration.inputFormats.days', {
text: i18n.translate('data.fieldFormats.duration.inputFormats.days', {
defaultMessage: 'Days',
}),
kind: 'days',
},
{
text: i18n.translate('data.common.fieldFormats.duration.inputFormats.weeks', {
text: i18n.translate('data.fieldFormats.duration.inputFormats.weeks', {
defaultMessage: 'Weeks',
}),
kind: 'weeks',
},
{
text: i18n.translate('data.common.fieldFormats.duration.inputFormats.months', {
text: i18n.translate('data.fieldFormats.duration.inputFormats.months', {
defaultMessage: 'Months',
}),
kind: 'months',
},
{
text: i18n.translate('data.common.fieldFormats.duration.inputFormats.years', {
text: i18n.translate('data.fieldFormats.duration.inputFormats.years', {
defaultMessage: 'Years',
}),
kind: 'years',
},
];
const DEFAULT_OUTPUT_FORMAT = {
text: i18n.translate('data.common.fieldFormats.duration.outputFormats.humanize', {
text: i18n.translate('data.fieldFormats.duration.outputFormats.humanize', {
defaultMessage: 'Human Readable',
}),
method: 'humanize',
};
const outputFormats = [
{ ...DEFAULT_OUTPUT_FORMAT },
{
text: i18n.translate('data.common.fieldFormats.duration.outputFormats.asMilliseconds', {
text: i18n.translate('data.fieldFormats.duration.outputFormats.asMilliseconds', {
defaultMessage: 'Milliseconds',
}),
method: 'asMilliseconds',
},
{
text: i18n.translate('data.common.fieldFormats.duration.outputFormats.asSeconds', {
text: i18n.translate('data.fieldFormats.duration.outputFormats.asSeconds', {
defaultMessage: 'Seconds',
}),
method: 'asSeconds',
},
{
text: i18n.translate('data.common.fieldFormats.duration.outputFormats.asMinutes', {
text: i18n.translate('data.fieldFormats.duration.outputFormats.asMinutes', {
defaultMessage: 'Minutes',
}),
method: 'asMinutes',
},
{
text: i18n.translate('data.common.fieldFormats.duration.outputFormats.asHours', {
text: i18n.translate('data.fieldFormats.duration.outputFormats.asHours', {
defaultMessage: 'Hours',
}),
method: 'asHours',
},
{
text: i18n.translate('data.common.fieldFormats.duration.outputFormats.asDays', {
text: i18n.translate('data.fieldFormats.duration.outputFormats.asDays', {
defaultMessage: 'Days',
}),
method: 'asDays',
},
{
text: i18n.translate('data.common.fieldFormats.duration.outputFormats.asWeeks', {
text: i18n.translate('data.fieldFormats.duration.outputFormats.asWeeks', {
defaultMessage: 'Weeks',
}),
method: 'asWeeks',
},
{
text: i18n.translate('data.common.fieldFormats.duration.outputFormats.asMonths', {
text: i18n.translate('data.fieldFormats.duration.outputFormats.asMonths', {
defaultMessage: 'Months',
}),
method: 'asMonths',
},
{
text: i18n.translate('data.common.fieldFormats.duration.outputFormats.asYears', {
text: i18n.translate('data.fieldFormats.duration.outputFormats.asYears', {
defaultMessage: 'Years',
}),
method: 'asYears',
Expand All @@ -167,7 +167,9 @@ function parseInputAsDuration(val: number, inputFormat: string) {

export class DurationFormat extends FieldFormat {
static id = FIELD_FORMAT_IDS.DURATION;
static title = 'Duration';
static title = i18n.translate('data.fieldFormats.duration.title', {
defaultMessage: 'Duration',
});
static fieldType = KBN_FIELD_TYPES.NUMBER;
static inputFormats = inputFormats;
static outputFormats = outputFormats;
Expand All @@ -189,7 +191,12 @@ export class DurationFormat extends FieldFormat {
const outputFormat = this.param('outputFormat') as keyof Duration;
const outputPrecision = this.param('outputPrecision');
const human = this.isHuman();
const prefix = val < 0 && human ? 'minus ' : '';
const prefix =
val < 0 && human
? i18n.translate('data.fieldFormats.duration.negativeLabel', {
defaultMessage: 'minus',
}) + ' '
: '';
const duration = parseInputAsDuration(val, inputFormat) as Record<keyof Duration, Function>;
const formatted = duration[outputFormat]();
const precise = human ? formatted : formatted.toFixed(outputPrecision);
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/data/common/field_formats/converters/ip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@
* under the License.
*/

import { i18n } from '@kbn/i18n';
import { KBN_FIELD_TYPES } from '../../kbn_field_types/types';
import { FieldFormat } from '../field_format';
import { TextContextTypeConvert, FIELD_FORMAT_IDS } from '../types';

export class IpFormat extends FieldFormat {
static id = FIELD_FORMAT_IDS.IP;
static title = 'IP Address';
static title = i18n.translate('data.fieldFormats.ip.title', {
defaultMessage: 'IP address',
});
static fieldType = KBN_FIELD_TYPES.IP;

textConvert: TextContextTypeConvert = val => {
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/data/common/field_formats/converters/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
* under the License.
*/

import { i18n } from '@kbn/i18n';
import { NumeralFormat } from './numeral';
import { FIELD_FORMAT_IDS } from '../types';

export class NumberFormat extends NumeralFormat {
static id = FIELD_FORMAT_IDS.NUMBER;
static title = 'Number';
static title = i18n.translate('data.fieldFormats.number.title', {
defaultMessage: 'Number',
});

id = NumberFormat.id;
title = NumberFormat.title;
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/data/common/field_formats/converters/percent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
* under the License.
*/

import { i18n } from '@kbn/i18n';
import { NumeralFormat } from './numeral';
import { TextContextTypeConvert, FIELD_FORMAT_IDS } from '../types';

export class PercentFormat extends NumeralFormat {
static id = FIELD_FORMAT_IDS.PERCENT;
static title = 'Percentage';
static title = i18n.translate('data.fieldFormats.percent.title', {
defaultMessage: 'Percentage',
});

id = PercentFormat.id;
title = PercentFormat.title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@
* under the License.
*/

import { i18n } from '@kbn/i18n';
import moment from 'moment';
import { KBN_FIELD_TYPES } from '../../kbn_field_types/types';
import { FieldFormat } from '../field_format';
import { TextContextTypeConvert, FIELD_FORMAT_IDS } from '../types';

export class RelativeDateFormat extends FieldFormat {
static id = FIELD_FORMAT_IDS.RELATIVE_DATE;
static title = 'Relative Date';
static title = i18n.translate('data.fieldFormats.relative_date.title', {
defaultMessage: 'Relative date',
});
static fieldType = KBN_FIELD_TYPES.DATE;

textConvert: TextContextTypeConvert = val => {
Expand Down
Loading