mirror of
https://github.com/grafana/grafana.git
synced 2024-12-29 10:21:41 -06:00
Transformations: Add string type check to field value in substring value matcher (#87782)
This commit is contained in:
parent
012ee1d557
commit
d92ec98ecc
@ -9,7 +9,7 @@ describe('value substring to matcher', () => {
|
||||
fields: [
|
||||
{
|
||||
name: 'temp',
|
||||
values: ['24', null, '10', 'asd', '42', 'ASD'],
|
||||
values: ['24', null, '10', 'asd', '42', 'ASD', [1, 2, 3]],
|
||||
},
|
||||
],
|
||||
}),
|
||||
@ -53,6 +53,14 @@ describe('value substring to matcher', () => {
|
||||
expect(matcher(valueIndex, field, frame, data)).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should be a mismatch if the option is an array / non-string and should not cause errors', () => {
|
||||
const frame = data[0];
|
||||
const field = frame.fields[0];
|
||||
const valueIndex = 6;
|
||||
|
||||
expect(matcher(valueIndex, field, frame, data)).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should not match when option value is different', () => {
|
||||
const frame = data[0];
|
||||
const field = frame.fields[0];
|
||||
|
@ -12,7 +12,11 @@ const isSubstringMatcher: ValueMatcherInfo<BasicValueMatcherOptions> = {
|
||||
return (valueIndex: number, field: Field) => {
|
||||
const value = field.values[valueIndex];
|
||||
return (
|
||||
(value && options.value && value.toLowerCase().includes(options.value.toLowerCase())) || options.value === ''
|
||||
(value &&
|
||||
options.value &&
|
||||
typeof value === 'string' &&
|
||||
value.toLowerCase().includes(options.value.toLowerCase())) ||
|
||||
options.value === ''
|
||||
);
|
||||
};
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user