Fixes #81465: Exclude-null now it's getting initialized properly by default (#85613)

* fix #81465 (FilterByValueTransformerEditor.tsx): Exclude-null now it's getting initialised properly by default

The default matcher of a new filter by value condition has been changed from greater to isNull. Added a file FilterByValueTransformerEditor.test.tsx with a test to confirm this change

* update tests and run linter

* filter-by-values-exclude-null/ update test definition

---------

Co-authored-by: jev forsberg <jev.forsberg@grafana.com>
This commit is contained in:
Eduardo Franscisco Pedrosa 2024-04-05 18:24:57 +01:00 committed by GitHub
parent cd05568459
commit d23918fd95
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 71 additions and 1 deletions

View File

@ -0,0 +1,70 @@
import { render, fireEvent } from '@testing-library/react';
import React from 'react';
import { DataFrame, FieldType, ValueMatcherID, valueMatchers } from '@grafana/data';
import { FilterByValueMatch, FilterByValueType } from '@grafana/data/src/transformations/transformers/filterByValue';
import { FilterByValueTransformerEditor } from './FilterByValueTransformerEditor';
describe('FilterByValueTransformerEditor', () => {
it('correctly applies the default isNull option when onAddFilter is first called', () => {
// Mock onChange function
const onChangeMock = jest.fn();
// Mock options
const options = {
type: FilterByValueType.include,
match: FilterByValueMatch.all,
filters: [],
};
// Mock input
const input: DataFrame[] = [
{
fields: [
{
name: 'person',
type: FieldType.string,
config: { displayName: 'Person' },
values: ['john', 'jill', 'jeremy', ''],
},
{
name: 'city',
type: FieldType.string,
config: { displayName: 'City' },
values: ['london', 'budapest', '', 'lisbon'],
},
],
length: 4,
},
];
// Render the component
const { getByText } = render(
<FilterByValueTransformerEditor input={input} options={options} onChange={onChangeMock} />
);
// Find and click the "Add condition" button
fireEvent.click(getByText('Add condition'));
// Check if onChange was called with the correct filter
expect(onChangeMock).toHaveBeenCalledWith({
filters: [
{
fieldName: 'Person',
config: {
id: ValueMatcherID.isNull,
options: valueMatchers.get(ValueMatcherID.isNull).getDefaultOptions({
name: 'person',
type: FieldType.string,
config: { displayName: 'Person' },
values: ['john', 'jill', 'jeremy', ''],
}),
},
},
],
match: FilterByValueMatch.all,
type: FilterByValueType.include,
});
});
});

View File

@ -49,7 +49,7 @@ export const FilterByValueTransformerEditor = (props: TransformerUIProps<FilterB
} }
const filters = cloneDeep(options.filters); const filters = cloneDeep(options.filters);
const matcher = valueMatchers.get(ValueMatcherID.greater); const matcher = valueMatchers.get(ValueMatcherID.isNull);
filters.push({ filters.push({
fieldName: getFieldDisplayName(field, frame, input), fieldName: getFieldDisplayName(field, frame, input),