[Unified search] Fixes wrong negation label on the filter builder (#154216)

## Summary

Closes https://github.com/elastic/kibana/issues/153608

Fixes the problem mentioned on the issue. When you edit a filter with
negation to add another combined filter, then the negation was inherited
by the first filter, which was not correct.


![2](https://user-images.githubusercontent.com/17003240/229486368-b8cabdee-693f-4c07-bad7-2860125d608a.gif)

### Checklist
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
This commit is contained in:
Stratoula Kalafateli 2023-04-05 14:56:17 +03:00 committed by GitHub
parent 16d8f404d8
commit 5436d6d007
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 4 deletions

View file

@ -510,7 +510,7 @@ class FilterEditorComponent extends Component<FilterEditorProps, State> {
const alias = customLabel || null;
const {
$state,
meta: { disabled = false, negate = false },
meta: { disabled = false },
} = this.props.filter;
if (!$state || !$state.store || !selectedDataView) {
@ -533,12 +533,14 @@ class FilterEditorComponent extends Component<FilterEditorProps, State> {
},
};
} else {
// for the combined filters created on the builder, negate should always be false,
// the global negation changes only from the exclude/inclue results panel item
newFilter = buildCombinedFilter(
BooleanRelation.AND,
updatedFilters,
selectedDataView,
disabled,
negate,
false,
alias,
$state.store
);

View file

@ -22,6 +22,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const browser = getService('browser');
const PageObjects = getPageObjects(['common', 'context']);
const testSubjects = getService('testSubjects');
describe('context filters', function contextSize() {
beforeEach(async function () {
@ -227,5 +228,22 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
expect(await filterBar.getFilterEditorPreview()).to.equal('extension: is one of png, jpeg');
});
it('should display the negated values correctly', async () => {
await filterBar.addFilter({ field: 'extension', operation: 'is not', value: 'png' });
await PageObjects.context.waitUntilContextLoadingHasFinished();
expect(await filterBar.getFilterCount()).to.be(1);
const filterLabel = await filterBar.getFiltersLabel();
expect(filterLabel[0]).to.be('NOT extension: png');
await filterBar.clickEditFilterById('0');
await filterBar.addAndFilter('0');
await filterBar.createFilter({ field: 'extension', operation: 'is', value: 'jpeg' }, '0.1');
await testSubjects.clickWhenNotDisabled('saveFilter');
const filterLabelUpdated = await filterBar.getFiltersLabel();
expect(filterLabelUpdated[0]).to.be('NOT extension: png AND extension: jpeg');
});
});
}

View file

@ -208,7 +208,7 @@ export class FilterBarService extends FtrService {
await addOrBtn.click();
}
private async addAndFilter(path: string) {
public async addAndFilter(path: string) {
const filterForm = await this.testSubjects.find(`filter-${path}`);
const addAndBtn = await filterForm.findByTestSubject('add-and-filter');
await addAndBtn.click();
@ -273,7 +273,7 @@ export class FilterBarService extends FtrService {
return 'filters' in filter && 'condition' in filter;
}
private async createFilter(filter: Filter, path: string = '0'): Promise<unknown> {
public async createFilter(filter: Filter, path: string = '0'): Promise<unknown> {
if (this.isFilterNode(filter)) {
let startedAdding = false;
for (const [index, f] of filter.filters.entries()) {