parent
884246e421
commit
a4e99754a4
4 changed files with 25 additions and 0 deletions
|
@ -530,6 +530,9 @@ describe('IndexPattern Data Source', () => {
|
|||
"outputColumnId": Array [
|
||||
"col1",
|
||||
],
|
||||
"outputColumnName": Array [
|
||||
"Count of records",
|
||||
],
|
||||
"targetUnit": Array [
|
||||
"h",
|
||||
],
|
||||
|
|
|
@ -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('');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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}`;
|
||||
}
|
||||
|
|
|
@ -121,6 +121,7 @@ function getExpressionForLayer(
|
|||
dateColumnId: [firstDateHistogramColumn![0]],
|
||||
inputColumnId: [id],
|
||||
outputColumnId: [id],
|
||||
outputColumnName: [col.label],
|
||||
targetUnit: [col.timeScale!],
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue