ValueMappings: Fixes issue with regex value mapping that only sets color (#42311)
* ValueMappings: Fixes issue with regex value mapping that only sets color * Fixed test name
This commit is contained in:
@@ -67,6 +67,13 @@ const testSet2: ValueMapping[] = [
|
||||
result: { text: 'Hostname $1' },
|
||||
},
|
||||
},
|
||||
{
|
||||
type: MappingType.RegexToText,
|
||||
options: {
|
||||
pattern: '/hello/',
|
||||
result: { color: 'red' },
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
describe('Format value with value mappings', () => {
|
||||
@@ -164,6 +171,10 @@ describe('Format value with regex mappings', () => {
|
||||
const value = 'www.baz.com';
|
||||
expect(getValueMappingResult(testSet2, value)).toBeNull();
|
||||
});
|
||||
|
||||
it('should not replace match when replace text is null', () => {
|
||||
expect(getValueMappingResult(testSet2, 'hello my name is')).toEqual({ color: 'red' });
|
||||
});
|
||||
});
|
||||
|
||||
describe('isNumeric', () => {
|
||||
|
||||
@@ -58,9 +58,13 @@ export function getValueMappingResult(valueMappings: ValueMapping[], value: any)
|
||||
|
||||
const regex = stringToJsRegex(vm.options.pattern);
|
||||
if (value.match(regex)) {
|
||||
const thisResult = Object.create(vm.options.result);
|
||||
thisResult.text = value.replace(regex, vm.options.result.text || '');
|
||||
return thisResult;
|
||||
const res = { ...vm.options.result };
|
||||
|
||||
if (res.text != null) {
|
||||
res.text = value.replace(regex, vm.options.result.text || '');
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
case MappingType.SpecialValue:
|
||||
|
||||
Reference in New Issue
Block a user