mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Fix: Value mappings match against string values (#25929)
* Use standard input for value mappings value * add test and case for matching string values * re add number on rangemap * remove FieldTypeNumber required
This commit is contained in:
parent
275c37503a
commit
20db5680d2
@ -78,4 +78,15 @@ describe('Format value with value mappings', () => {
|
||||
|
||||
expect(getMappedValue(valueMappings, value).text).toEqual('1-20');
|
||||
});
|
||||
|
||||
it('should map value text to mapping', () => {
|
||||
const valueMappings: ValueMapping[] = [
|
||||
{ id: 0, operator: '', text: '1-20', type: MappingType.RangeToText, from: '1', to: '20' },
|
||||
{ id: 1, operator: '', text: 'ELVA', type: MappingType.ValueToText, value: 'elva' },
|
||||
];
|
||||
|
||||
const value = 'elva';
|
||||
|
||||
expect(getMappedValue(valueMappings, value).text).toEqual('ELVA');
|
||||
});
|
||||
});
|
||||
|
@ -19,7 +19,9 @@ const addValueToTextMappingText = (
|
||||
const valueToTextMappingAsNumber = parseFloat(valueToTextMapping.value as string);
|
||||
|
||||
if (isNaN(valueAsNumber) || isNaN(valueToTextMappingAsNumber)) {
|
||||
return allValueMappings;
|
||||
if (value === valueToTextMapping.value) {
|
||||
return allValueMappings.concat(valueToTextMapping);
|
||||
}
|
||||
}
|
||||
|
||||
if (valueAsNumber !== valueToTextMappingAsNumber) {
|
||||
|
@ -83,7 +83,6 @@ export const MappingRow: React.FC<Props> = ({ valueMapping, updateValueMapping,
|
||||
<>
|
||||
<Field label="Value">
|
||||
<Input
|
||||
type="number"
|
||||
defaultValue={(valueMapping as ValueMap).value}
|
||||
onBlur={e => onMappingValueChange(e.currentTarget.value)}
|
||||
onKeyDown={onKeyDown(onMappingValueChange)}
|
||||
|
@ -161,7 +161,7 @@ export const getStandardFieldConfigs = () => {
|
||||
process: valueMappingsOverrideProcessor,
|
||||
settings: {},
|
||||
defaultValue: [],
|
||||
shouldApply: field => field.type === FieldType.number,
|
||||
shouldApply: () => true,
|
||||
category: ['Value mappings'],
|
||||
getItemsCount: (value?) => (value ? value.length : 0),
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user