Skip to content

Commit

Permalink
fix time scaling bugs (#86444)
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 committed Dec 21, 2020
1 parent 388b250 commit 36a8343
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,9 @@ describe('IndexPattern Data Source', () => {
"outputColumnId": Array [
"col1",
],
"outputColumnName": Array [
"Count of records",
],
"targetUnit": Array [
"h",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,20 @@ describe('suffix formatter', () => {
expect(convertMock).toHaveBeenCalledWith(12345);
expect(formatFactory).toHaveBeenCalledWith({ id: 'nestedFormatter', params: nestedParams });
});

it('should not add suffix to empty strings', () => {
const convertMock = jest.fn((x) => '');
const formatFactory = jest.fn(() => ({ convert: convertMock }));
const SuffixFormatter = getSuffixFormatter((formatFactory as unknown) as FormatFactory);
const nestedParams = { abc: 123 };
const formatterInstance = new SuffixFormatter({
unit: 'h',
id: 'nestedFormatter',
params: nestedParams,
});

const result = formatterInstance.convert(12345);

expect(result).toEqual('');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ export function getSuffixFormatter(formatFactory: FormatFactory) {
val
);

// do not add suffixes to empty strings
if (formattedValue === '') {
return '';
}

if (suffix) {
return `${formattedValue}${suffix}`;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ function getExpressionForLayer(
dateColumnId: [firstDateHistogramColumn![0]],
inputColumnId: [id],
outputColumnId: [id],
outputColumnName: [col.label],
targetUnit: [col.timeScale!],
},
};
Expand Down

0 comments on commit 36a8343

Please sign in to comment.