mirror of
https://github.com/grafana/grafana.git
synced 2025-01-13 09:32:12 -06:00
ValueMappings: Fixes value 0 not being mapped (#31924)
* ValueMapping: Updated tests (#31877) Checks if value 0 or '0' is considered as a numeric value * ValueMapping: Changed implementation of isNumeric (#31877) isNumeric now works with the 0 value * fixed prettier issue Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
This commit is contained in:
parent
82e9d59121
commit
c764bca58f
@ -123,9 +123,12 @@ describe('isNumeric', () => {
|
||||
it.each`
|
||||
value | expected
|
||||
${123} | ${true}
|
||||
${0} | ${true}
|
||||
${'123'} | ${true}
|
||||
${'0'} | ${true}
|
||||
${' 123'} | ${true}
|
||||
${' 123 '} | ${true}
|
||||
${' 0 '} | ${true}
|
||||
${-123.4} | ${true}
|
||||
${'-123.4'} | ${true}
|
||||
${0.41} | ${true}
|
||||
|
@ -97,11 +97,8 @@ const isNullValueMap = (mapping: ValueMap): boolean => {
|
||||
return mapping.value.toLowerCase() === 'null';
|
||||
};
|
||||
|
||||
// Ref https://stackoverflow.com/a/42356340
|
||||
export function isNumeric(num: any) {
|
||||
if (num === true) {
|
||||
return false;
|
||||
}
|
||||
// Ref https://stackoverflow.com/a/58550111
|
||||
|
||||
return Boolean(Number(num));
|
||||
export function isNumeric(num: any) {
|
||||
return (typeof num === 'number' || (typeof num === 'string' && num.trim() !== '')) && !isNaN(num as number);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user