mirror of
https://github.com/grafana/grafana.git
synced 2025-07-31 11:02:49 +08:00
Transformations - make substring and not substring transformer case insensitive. (#84699)
* make substring and not substring transformer case insensitive * timlevett/case-insensitive/ run linter --------- Co-authored-by: jev forsberg <jev.forsberg@grafana.com>
This commit is contained in:
@ -9,7 +9,7 @@ describe('value substring to matcher', () => {
|
||||
fields: [
|
||||
{
|
||||
name: 'temp',
|
||||
values: ['24', null, '10', 'asd', '42'],
|
||||
values: ['24', null, '10', 'asd', '42', 'ASD'],
|
||||
},
|
||||
],
|
||||
}),
|
||||
@ -30,6 +30,20 @@ describe('value substring to matcher', () => {
|
||||
expect(matcher(valueIndex, field, frame, data)).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should match case insensitive', () => {
|
||||
const frame = data[0];
|
||||
const field = frame.fields[0];
|
||||
const valueIndex = 5;
|
||||
const caseInsensitiveMatcher = getValueMatcher({
|
||||
id: ValueMatcherID.substring,
|
||||
options: {
|
||||
value: 'asd',
|
||||
},
|
||||
});
|
||||
|
||||
expect(caseInsensitiveMatcher(valueIndex, field, frame, data)).toBeTruthy();
|
||||
});
|
||||
|
||||
// Added for https://github.com/grafana/grafana/pull/83548#pullrequestreview-1904931540 where the matcher was not handling null values
|
||||
it('should be a mismatch if the option is null and should not cause errors', () => {
|
||||
const frame = data[0];
|
||||
|
@ -11,7 +11,9 @@ const isSubstringMatcher: ValueMatcherInfo<BasicValueMatcherOptions> = {
|
||||
get: (options) => {
|
||||
return (valueIndex: number, field: Field) => {
|
||||
const value = field.values[valueIndex];
|
||||
return (value && value.includes(options.value)) || options.value === '';
|
||||
return (
|
||||
(value && options.value && value.toLowerCase().includes(options.value.toLowerCase())) || options.value === ''
|
||||
);
|
||||
};
|
||||
},
|
||||
getOptionsDisplayText: () => {
|
||||
@ -28,7 +30,13 @@ const isNotSubstringValueMatcher: ValueMatcherInfo<BasicValueMatcherOptions> = {
|
||||
get: (options) => {
|
||||
return (valueIndex: number, field: Field) => {
|
||||
const value = field.values[valueIndex];
|
||||
return typeof value === 'string' && options.value !== '' && !value.includes(options.value);
|
||||
return (
|
||||
typeof value === 'string' &&
|
||||
options.value &&
|
||||
value &&
|
||||
options.value !== '' &&
|
||||
!value.toLowerCase().includes(options.value.toLowerCase())
|
||||
);
|
||||
};
|
||||
},
|
||||
getOptionsDisplayText: () => {
|
||||
|
Reference in New Issue
Block a user