Skip to content

Commit 36a8343

Browse files
authored
fix time scaling bugs (#86444)
1 parent 388b250 commit 36a8343

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

x-pack/plugins/lens/public/indexpattern_datasource/indexpattern.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,9 @@ describe('IndexPattern Data Source', () => {
530530
"outputColumnId": Array [
531531
"col1",
532532
],
533+
"outputColumnName": Array [
534+
"Count of records",
535+
],
533536
"targetUnit": Array [
534537
"h",
535538
],

x-pack/plugins/lens/public/indexpattern_datasource/suffix_formatter.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,20 @@ describe('suffix formatter', () => {
2525
expect(convertMock).toHaveBeenCalledWith(12345);
2626
expect(formatFactory).toHaveBeenCalledWith({ id: 'nestedFormatter', params: nestedParams });
2727
});
28+
29+
it('should not add suffix to empty strings', () => {
30+
const convertMock = jest.fn((x) => '');
31+
const formatFactory = jest.fn(() => ({ convert: convertMock }));
32+
const SuffixFormatter = getSuffixFormatter((formatFactory as unknown) as FormatFactory);
33+
const nestedParams = { abc: 123 };
34+
const formatterInstance = new SuffixFormatter({
35+
unit: 'h',
36+
id: 'nestedFormatter',
37+
params: nestedParams,
38+
});
39+
40+
const result = formatterInstance.convert(12345);
41+
42+
expect(result).toEqual('');
43+
});
2844
});

x-pack/plugins/lens/public/indexpattern_datasource/suffix_formatter.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ export function getSuffixFormatter(formatFactory: FormatFactory) {
4949
val
5050
);
5151

52+
// do not add suffixes to empty strings
53+
if (formattedValue === '') {
54+
return '';
55+
}
56+
5257
if (suffix) {
5358
return `${formattedValue}${suffix}`;
5459
}

x-pack/plugins/lens/public/indexpattern_datasource/to_expression.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ function getExpressionForLayer(
121121
dateColumnId: [firstDateHistogramColumn![0]],
122122
inputColumnId: [id],
123123
outputColumnId: [id],
124+
outputColumnName: [col.label],
124125
targetUnit: [col.timeScale!],
125126
},
126127
};

0 commit comments

Comments
 (0)