Skip to content

Commit

Permalink
Edits to filter's custom label are ignored (#59169)
Browse files Browse the repository at this point in the history
* Fix filter alias field

* Test for alias comparison

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
Liza Katz and elasticmachine authored Mar 4, 2020
1 parent faf2bbe commit 45efc11
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,5 +180,21 @@ describe('filter manager utilities', () => {

expect(compareFilters([f1], [f2], COMPARE_ALL_OPTIONS)).toBeTruthy();
});

test('should compare alias with COMPARE_ALL_OPTIONS', () => {
const f1 = {
$state: { store: FilterStateStore.GLOBAL_STATE },
...buildQueryFilter({ _type: { match: { query: 'apache', type: 'phrase' } } }, 'index', ''),
};
const f2 = {
$state: { store: FilterStateStore.GLOBAL_STATE },
...buildQueryFilter({ _type: { match: { query: 'apache', type: 'phrase' } } }, 'index', ''),
};

f2.meta.alias = 'wassup';
f2.meta.alias = 'dog';

expect(compareFilters([f1], [f2], COMPARE_ALL_OPTIONS)).toBeFalsy();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface FilterCompareOptions {
disabled?: boolean;
negate?: boolean;
state?: boolean;
alias?: boolean;
}

/**
Expand All @@ -33,6 +34,7 @@ export const COMPARE_ALL_OPTIONS: FilterCompareOptions = {
disabled: true,
negate: true,
state: true,
alias: true,
};

const mapFilter = (
Expand All @@ -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;
};
Expand Down Expand Up @@ -79,6 +82,7 @@ export const compareFilters = (
state: false,
negate: false,
disabled: false,
alias: false,
});

if (!comparators.state) excludedAttributes.push('$state');
Expand Down

0 comments on commit 45efc11

Please sign in to comment.