Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Formatters] Add new currency and short number formatter, replacing default number and percent #53972

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
6a1a77e
[Formatters] Add new field formatters
wylieconlon Jan 2, 2020
3785cc3
Merge remote-tracking branch 'origin/master' into add-formatters
wylieconlon Jan 7, 2020
5682ade
Remove locale override. Support browser locale.
wylieconlon Jan 9, 2020
44f02c0
Merge remote-tracking branch 'origin/master' into add-formatters
wylieconlon Jan 9, 2020
c600fee
i18n currency names in field format editor
Jan 10, 2020
c834a3e
Merge remote-tracking branch 'origin/master' into add-formatters
wylieconlon Jan 10, 2020
aba8e7c
Add migration and update tests
wylieconlon Jan 10, 2020
f9d89df
Merge remote-tracking branch 'origin/master' into add-formatters
wylieconlon Jan 10, 2020
2a6eced
Remove unused
wylieconlon Jan 10, 2020
47ec996
Remove deprecated settings use
wylieconlon Jan 10, 2020
4f3175a
Fix lint error
wylieconlon Jan 10, 2020
8679335
Merge remote-tracking branch 'origin/master' into add-formatters
wylieconlon Jan 13, 2020
4e43465
Stop formatting numbers in CSV export
wylieconlon Jan 13, 2020
e217a48
Add advanced setting for max decimals
wylieconlon Jan 13, 2020
3af88d1
Move currency to i18n
wylieconlon Jan 13, 2020
bb44874
Merge remote-tracking branch 'origin/master' into add-formatters
wylieconlon Jan 14, 2020
fa1797c
Add snapshots for format editors
wylieconlon Jan 14, 2020
a7c3d17
Fix tests
wylieconlon Jan 14, 2020
4ffa130
Merge remote-tracking branch 'origin/master' into add-formatters
wylieconlon Jan 14, 2020
d2e32ee
Merge remote-tracking branch 'origin/master' into add-formatters
wylieconlon Jan 15, 2020
d1a1fdb
Merge remote-tracking branch 'origin/master' into add-formatters
wylieconlon Jan 17, 2020
3fbdfb0
Update reporting to include locale
wylieconlon Jan 17, 2020
8ec6d98
Merge remote-tracking branch 'origin/master' into add-formatters
wylieconlon Jan 17, 2020
6b34bac
Remove settings change
wylieconlon Jan 17, 2020
ec25c3e
Fix integration test that was using custom formatting
wylieconlon Jan 17, 2020
3754f11
Fix test again
wylieconlon Jan 17, 2020
381c584
Merge remote-tracking branch 'origin/master' into add-formatters
wylieconlon Jan 21, 2020
fa1d6d9
Fix tests again
wylieconlon Jan 21, 2020
1efcfc2
Merge remote-tracking branch 'origin/master' into add-formatters
wylieconlon Jan 21, 2020
b96444a
More test fixing
wylieconlon Jan 21, 2020
fbbfaf5
More test fixes
wylieconlon Jan 22, 2020
aeefd35
Hopefully final tweaks
wylieconlon Jan 22, 2020
40f6c5c
Merge remote-tracking branch 'origin/master' into add-formatters
wylieconlon Jan 22, 2020
f7bb12e
More fixes
wylieconlon Jan 22, 2020
ecd2198
Fix tests
wylieconlon Jan 22, 2020
ff46904
Fix tests
wylieconlon Jan 22, 2020
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
27 changes: 26 additions & 1 deletion src/legacy/core_plugins/kibana/migrations/migrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,31 @@ function migrateSubTypeAndParentFieldProperties(doc) {
};
}

function migrateNumeralFieldFormatters(doc) {
if (!doc.attributes.fieldFormatMap) return doc;

const fieldFormatMap = doc.attributes.fieldFormatMap;
const fieldFormats = JSON.parse(fieldFormatMap);
wylieconlon marked this conversation as resolved.
Show resolved Hide resolved
// const migratedFields = fields.map(field => {
wylieconlon marked this conversation as resolved.
Show resolved Hide resolved
// if (field.subType === 'multi') {
// return {
// ...omit(field, 'parent'),
// subType: { multi: { parent: field.parent } },
// };
// }

// return field;
// });

return {
...doc,
attributes: {
...doc.attributes,
fieldFormatMap: JSON.stringify(fieldFormats),
},
};
}

const executeMigrations720 = flow(
migratePercentileRankAggregation,
migrateDateHistogramAggregation
Expand All @@ -508,7 +533,7 @@ export const migrations = {
doc.attributes.typeMeta = doc.attributes.typeMeta || undefined;
return doc;
},
'7.6.0': flow(migrateSubTypeAndParentFieldProperties),
'7.6.0': flow(migrateSubTypeAndParentFieldProperties, migrateNumeralFieldFormatters),
},
visualization: {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/kibana/ui_setting_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ export function getUiSettingDefaults() {
"ip": { "id": "ip", "params": {} },
"date": { "id": "date", "params": {} },
"date_nanos": { "id": "date_nanos", "params": {}, "es": true },
"number": { "id": "number", "params": {} },
"number": { "id": "default_number", "params": {} },
"boolean": { "id": "boolean", "params": {} },
"_source": { "id": "_source", "params": {} },
"_default_": { "id": "string", "params": {} }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
* under the License.
*/

import { NumberFormatEditor } from '../number';
import React, { Fragment } from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import { DefaultFormatEditor } from '../default';
import { FormatEditorSamples } from '../../samples';

export class BytesFormatEditor extends NumberFormatEditor {
export class BytesFormatEditor extends DefaultFormatEditor {
static formatId = 'bytes';

constructor(props) {
Expand All @@ -30,4 +33,20 @@ export class BytesFormatEditor extends NumberFormatEditor {
sampleInputs: [256, 1024, 5150000, 1990000000],
};
}

render() {
const { samples } = this.state;
const locale = this.props.format.getConfig('format:number:defaultLocale');

return (
<Fragment>
<FormattedMessage
id="common.ui.fieldEditor.numberLocaleLabel"
defaultMessage="The number locale ({locale}) is controlled by the Kibana advanced setting format:number:defaultLocale"
values={{ locale }}
/>
<FormatEditorSamples samples={samples} />
</Fragment>
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/*
* 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 React, { Fragment } from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiFormRow, EuiComboBox } from '@elastic/eui';

import { DefaultNumberFormatEditor } from '../default_number';
import { FormatEditorSamples } from '../../samples';

// Top 35 most traded currencies per https://en.wikipedia.org/wiki/Template:Most_traded_currencies
// This list is not a full list of currencies, but the ISO standard full list of currencies
// does not provide some of the amenities of this Wiki list- a mashup of sources would be required
// to provide country name, currency name, and currency symbol.
// The full ISO reference: https://www.currency-iso.org/en/home/tables/table-a1.html
const topCurrencies = [
{ name: 'United States dollar', code: 'USD', symbol: 'US$' },
{ name: 'Euro', code: 'EUR', symbol: '€' },
{ name: 'Japanese yen', code: 'JPY', symbol: '¥' },
{ name: 'Pound sterling', code: 'GBP', symbol: '£' },
{ name: 'Australian dollar', code: 'AUD', symbol: 'A$' },
{ name: 'Canadian dollar', code: 'CAD', symbol: 'C$' },
{ name: 'Swiss franc', code: 'CHF', symbol: 'CHF' },
{ name: 'Renminbi', code: 'CNY', symbol: '元' },
{ name: 'Hong Kong dollar', code: 'HKD', symbol: 'HK$' },
{ name: 'New Zealand dollar', code: 'NZD', symbol: 'NZ$' },
{ name: 'Swedish krona', code: 'SEK', symbol: 'kr' },
{ name: 'South Korean won', code: 'KRW', symbol: '₩' },
{ name: 'Singapore dollar', code: 'SGD', symbol: 'S$' },
{ name: 'Norwegian krone', code: 'NOK', symbol: 'kr' },
{ name: 'Mexican peso', code: 'MXN', symbol: '$' },
{ name: 'Indian rupee', code: 'INR', symbol: '₹' },
{ name: 'Russian ruble', code: 'RUB', symbol: '₽' },
{ name: 'South African rand', code: 'ZAR', symbol: 'R' },
{ name: 'Turkish lira', code: 'TRY', symbol: '₺' },
{ name: 'Brazilian real', code: 'BRL', symbol: 'R$' },
{ name: 'New Taiwan dollar', code: 'TWD', symbol: 'NT$' },
{ name: 'Danish krone', code: 'DKK', symbol: 'kr' },
{ name: 'Polish zloty', code: 'PLN', symbol: 'zł' },
{ name: 'Thai baht', code: 'THB', symbol: '฿' },
{ name: 'Indonesian rupiah', code: 'IDR', symbol: 'Rp' },
{ name: 'Hungarian forint', code: 'HUF', symbol: 'Ft' },
{ name: 'Czech koruna', code: 'CZK', symbol: 'Kč' },
{ name: 'Israeli new shekel', code: 'ILS', symbol: '₪' },
{ name: 'Chilean peso', code: 'CLP', symbol: 'CLP$' },
{ name: 'Philippine peso', code: 'PHP', symbol: '₱' },
{ name: 'UAE dirham', code: 'AED', symbol: 'د.إ' },
{ name: 'Colombian peso', code: 'COP', symbol: 'COL$' },
{ name: 'Saudi riyal', code: 'SAR', symbol: '﷼' },
{ name: 'Malaysian ringgit', code: 'MYR', symbol: 'RM' },
{ name: 'Romanian leu', code: 'RON', symbol: 'L' },
];

export class CurrencyFormatEditor extends DefaultNumberFormatEditor {
static formatId = 'currency';

constructor(props) {
super(props);

this.state = {
...this.state,
sampleInputs: [1234, 99.9999, 5150000.0001, 0.00005],
};
}

render() {
const { formatParams } = this.props;
const { samples } = this.state;
const currencyCode = formatParams.currencyCode;
const currencyMatch = topCurrencies.find(cur => cur.code === currencyCode);
let currencyLabel = currencyCode;
if (currencyMatch) {
currencyLabel = `${currencyMatch.name} (${currencyMatch.code}) ${currencyMatch.symbol}`;
wylieconlon marked this conversation as resolved.
Show resolved Hide resolved
}

return (
<Fragment>
<EuiFormRow
label={
<FormattedMessage
id="common.ui.fieldEditor.currency.currencyCodeLabel"
defaultMessage="Select currency"
/>
}
>
<EuiComboBox
fullWidth
compressed
isClearable={false}
selectedOptions={[{ value: currencyCode, label: currencyLabel }]}
singleSelection={{ asPlainText: true }}
options={topCurrencies.map(cur => ({
value: cur.code,
label: `${cur.name} (${cur.code}) ${cur.symbol}`,
}))}
onChange={choices => {
this.onChange({ currencyCode: choices[0].value });
}}
/>
</EuiFormRow>

{this.renderLocaleOverride()}

<FormatEditorSamples samples={samples} />
</Fragment>
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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.
*/

export { CurrencyFormatEditor } from './currency';
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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.
*/

export { DefaultNumberFormatEditor } from './number';
Loading