mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* ValueMappings: Fixes issue with regex value mapping that only sets color
* Fixed test name
(cherry picked from commit c3d0d37bd7
)
Co-authored-by: Torkel Ödegaard <torkel@grafana.org>
This commit is contained in:
parent
66ae92abe9
commit
0ca6910f55
@ -67,6 +67,13 @@ const testSet2: ValueMapping[] = [
|
|||||||
result: { text: 'Hostname $1' },
|
result: { text: 'Hostname $1' },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
type: MappingType.RegexToText,
|
||||||
|
options: {
|
||||||
|
pattern: '/hello/',
|
||||||
|
result: { color: 'red' },
|
||||||
|
},
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
describe('Format value with value mappings', () => {
|
describe('Format value with value mappings', () => {
|
||||||
@ -164,6 +171,10 @@ describe('Format value with regex mappings', () => {
|
|||||||
const value = 'www.baz.com';
|
const value = 'www.baz.com';
|
||||||
expect(getValueMappingResult(testSet2, value)).toBeNull();
|
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', () => {
|
describe('isNumeric', () => {
|
||||||
|
@ -58,9 +58,13 @@ export function getValueMappingResult(valueMappings: ValueMapping[], value: any)
|
|||||||
|
|
||||||
const regex = stringToJsRegex(vm.options.pattern);
|
const regex = stringToJsRegex(vm.options.pattern);
|
||||||
if (value.match(regex)) {
|
if (value.match(regex)) {
|
||||||
const thisResult = Object.create(vm.options.result);
|
const res = { ...vm.options.result };
|
||||||
thisResult.text = value.replace(regex, vm.options.result.text || '');
|
|
||||||
return thisResult;
|
if (res.text != null) {
|
||||||
|
res.text = value.replace(regex, vm.options.result.text || '');
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
case MappingType.SpecialValue:
|
case MappingType.SpecialValue:
|
||||||
|
Loading…
Reference in New Issue
Block a user