Skip to content

Commit

Permalink
[Field_Format][Numeral] Convert null values to '-' (elastic#193722)
Browse files Browse the repository at this point in the history
## Summary
Fixes elastic#191629

When export to csv, converts `null` to `'-'` instead of the `'null'`
string.

<img width="1321" alt="image"
src="https://github.com/user-attachments/assets/5232487a-474e-46e3-9621-22ec8b46d4c9">

---------

Co-authored-by: Elastic Machine <[email protected]>
Co-authored-by: Davis McPhee <[email protected]>
  • Loading branch information
3 people authored Sep 30, 2024
1 parent 0ac6965 commit 2bb992e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 25 deletions.
6 changes: 6 additions & 0 deletions src/plugins/field_formats/common/converters/number.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,10 @@ describe('NumberFormat', () => {
}"
`);
});

test('null input', () => {
const formatter = new NumberFormat({}, getConfig);
expect(formatter.convert(null)).toMatchInlineSnapshot(`"-"`);
expect(formatter.convert(null, 'html')).toMatchInlineSnapshot(`" - "`);
});
});
1 change: 1 addition & 0 deletions src/plugins/field_formats/common/converters/numeral.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export abstract class NumeralFormat extends FieldFormat {
if (val === -Infinity) return '-∞';
if (val === +Infinity) return '+∞';
if (typeof val === 'object') {
if (val === null) return '-';
return JSON.stringify(val);
} else if (typeof val !== 'number') {
val = parseFloat(val);
Expand Down
50 changes: 25 additions & 25 deletions x-pack/test/functional/apps/lens/group6/metric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const inspector = getService('inspector');

const inspectorTrendlineData = [
['2015-09-19 06:00', 'null'],
['2015-09-19 09:00', 'null'],
['2015-09-19 12:00', 'null'],
['2015-09-19 15:00', 'null'],
['2015-09-19 18:00', 'null'],
['2015-09-19 21:00', 'null'],
['2015-09-19 06:00', '-'],
['2015-09-19 09:00', '-'],
['2015-09-19 12:00', '-'],
['2015-09-19 15:00', '-'],
['2015-09-19 18:00', '-'],
['2015-09-19 21:00', '-'],
['2015-09-20 00:00', '6,011.351'],
['2015-09-20 03:00', '5,849.901'],
['2015-09-20 06:00', '5,722.622'],
Expand All @@ -39,26 +39,26 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
];

const inspectorExpectedTrenlineDataWithBreakdown = [
['97.220.3.248', '2015-09-19 06:00', 'null'],
['97.220.3.248', '2015-09-19 09:00', 'null'],
['97.220.3.248', '2015-09-19 12:00', 'null'],
['97.220.3.248', '2015-09-19 15:00', 'null'],
['97.220.3.248', '2015-09-19 18:00', 'null'],
['97.220.3.248', '2015-09-19 21:00', 'null'],
['97.220.3.248', '2015-09-20 00:00', 'null'],
['97.220.3.248', '2015-09-20 03:00', 'null'],
['97.220.3.248', '2015-09-20 06:00', 'null'],
['97.220.3.248', '2015-09-20 09:00', 'null'],
['97.220.3.248', '2015-09-20 12:00', 'null'],
['97.220.3.248', '2015-09-20 15:00', 'null'],
['97.220.3.248', '2015-09-20 18:00', 'null'],
['97.220.3.248', '2015-09-20 21:00', 'null'],
['97.220.3.248', '2015-09-21 00:00', 'null'],
['97.220.3.248', '2015-09-21 03:00', 'null'],
['97.220.3.248', '2015-09-21 06:00', 'null'],
['97.220.3.248', '2015-09-19 06:00', '-'],
['97.220.3.248', '2015-09-19 09:00', '-'],
['97.220.3.248', '2015-09-19 12:00', '-'],
['97.220.3.248', '2015-09-19 15:00', '-'],
['97.220.3.248', '2015-09-19 18:00', '-'],
['97.220.3.248', '2015-09-19 21:00', '-'],
['97.220.3.248', '2015-09-20 00:00', '-'],
['97.220.3.248', '2015-09-20 03:00', '-'],
['97.220.3.248', '2015-09-20 06:00', '-'],
['97.220.3.248', '2015-09-20 09:00', '-'],
['97.220.3.248', '2015-09-20 12:00', '-'],
['97.220.3.248', '2015-09-20 15:00', '-'],
['97.220.3.248', '2015-09-20 18:00', '-'],
['97.220.3.248', '2015-09-20 21:00', '-'],
['97.220.3.248', '2015-09-21 00:00', '-'],
['97.220.3.248', '2015-09-21 03:00', '-'],
['97.220.3.248', '2015-09-21 06:00', '-'],
['97.220.3.248', '2015-09-21 09:00', '19,755'],
['97.220.3.248', '2015-09-21 12:00', 'null'],
['97.220.3.248', '2015-09-21 15:00', 'null'],
['97.220.3.248', '2015-09-21 12:00', '-'],
['97.220.3.248', '2015-09-21 15:00', '-'],
];

const clickMetric = async (title: string) => {
Expand Down

0 comments on commit 2bb992e

Please sign in to comment.