mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
DisplayProcessor: Interpret empty strings as NaN instead of 0 to support empty value map texts in Singlestat (#20952)
This commit is contained in:
parent
a7f4e4c56a
commit
caa3c6c9a5
@ -46,6 +46,10 @@ describe('Process simple display values', () => {
|
||||
assertSame('3', processors, { text: '3', numeric: 3 });
|
||||
});
|
||||
|
||||
it('Empty string is NaN', () => {
|
||||
assertSame('', processors, { text: '', numeric: NaN });
|
||||
});
|
||||
|
||||
it('Simple String', () => {
|
||||
assertSame('hello', processors, { text: 'hello', numeric: NaN });
|
||||
});
|
||||
@ -167,8 +171,19 @@ describe('Format value', () => {
|
||||
expect(instance(value).text).toEqual('1-20');
|
||||
});
|
||||
|
||||
it('should return mapped value and leave numeric value in tact if value mapping maps to empty string', () => {
|
||||
const valueMappings: ValueMapping[] = [
|
||||
{ id: 1, operator: '', text: '', type: MappingType.ValueToText, value: '1' },
|
||||
];
|
||||
const value = '1';
|
||||
const instance = getDisplayProcessor({ config: { decimals: 1, mappings: valueMappings } });
|
||||
|
||||
expect(instance(value).text).toEqual('');
|
||||
expect(instance(value).numeric).toEqual(1);
|
||||
});
|
||||
|
||||
//
|
||||
// Below is current behavior but I it's clearly not working great
|
||||
// Below is current behavior but it's clearly not working great
|
||||
//
|
||||
|
||||
it('with value 1000 and unit short', () => {
|
||||
|
@ -112,7 +112,7 @@ function toNumber(value: any): number {
|
||||
if (typeof value === 'number') {
|
||||
return value;
|
||||
}
|
||||
if (value === null || value === undefined || Array.isArray(value)) {
|
||||
if (value === '' || value === null || value === undefined || Array.isArray(value)) {
|
||||
return NaN; // lodash calls them 0
|
||||
}
|
||||
if (typeof value === 'boolean') {
|
||||
|
Loading…
Reference in New Issue
Block a user