[7.6] Edits to filter's custom label are ignored (#59169) (#59301)

* Edits to filter's custom label are ignored (#59169)

* Fix filter alias field

* Test for alias comparison

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

* Fix types

* Clean up fix

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
Liza Katz 2020-03-04 17:13:16 +00:00 committed by GitHub
parent 4f672d5d4f
commit 0522b39706
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 0 deletions

View file

@ -212,5 +212,29 @@ describe('filter manager utilities', () => {
expect(compareFilters([f1], [f2], COMPARE_ALL_OPTIONS)).toBeTruthy();
});
test('should compare alias with COMPARE_ALL_OPTIONS', () => {
const f1 = {
$state: { store: esFilters.FilterStateStore.GLOBAL_STATE },
...esFilters.buildQueryFilter(
{ _type: { match: { query: 'apache', type: 'phrase' } } },
'index',
''
),
};
const f2 = {
$state: { store: esFilters.FilterStateStore.GLOBAL_STATE },
...esFilters.buildQueryFilter(
{ _type: { match: { query: 'apache', type: 'phrase' } } },
'index',
''
),
};
f2.meta.alias = 'wassup';
f2.meta.alias = 'dog';
expect(compareFilters([f1], [f2], COMPARE_ALL_OPTIONS)).toBeFalsy();
});
});
});

View file

@ -24,6 +24,7 @@ export interface FilterCompareOptions {
disabled?: boolean;
negate?: boolean;
state?: boolean;
alias?: boolean;
}
/**
@ -33,6 +34,7 @@ export const COMPARE_ALL_OPTIONS: FilterCompareOptions = {
disabled: true,
negate: true,
state: true,
alias: true,
};
const mapFilter = (
@ -44,6 +46,7 @@ const mapFilter = (
if (comparators.negate) cleaned.negate = filter.meta && Boolean(filter.meta.negate);
if (comparators.disabled) cleaned.disabled = filter.meta && Boolean(filter.meta.disabled);
if (comparators.disabled) cleaned.alias = filter.meta?.alias;
return cleaned;
};
@ -81,6 +84,7 @@ export const compareFilters = (
state: false,
negate: false,
disabled: false,
alias: false,
});
if (!comparators.state) excludedAttributes.push('$state');