From 45efc11a0ad20c541145fb13623db26b13cea762 Mon Sep 17 00:00:00 2001 From: Liza Katz Date: Wed, 4 Mar 2020 08:48:35 +0000 Subject: [PATCH] Edits to filter's custom label are ignored (#59169) * Fix filter alias field * Test for alias comparison Co-authored-by: Elastic Machine --- .../filter_manager/lib/compare_filters.test.ts | 16 ++++++++++++++++ .../query/filter_manager/lib/compare_filters.ts | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/src/plugins/data/public/query/filter_manager/lib/compare_filters.test.ts b/src/plugins/data/public/query/filter_manager/lib/compare_filters.test.ts index e7e947c49d0e..5d6c25b0d96c 100644 --- a/src/plugins/data/public/query/filter_manager/lib/compare_filters.test.ts +++ b/src/plugins/data/public/query/filter_manager/lib/compare_filters.test.ts @@ -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(); + }); }); }); diff --git a/src/plugins/data/public/query/filter_manager/lib/compare_filters.ts b/src/plugins/data/public/query/filter_manager/lib/compare_filters.ts index cd4a966184f8..b4402885bc0b 100644 --- a/src/plugins/data/public/query/filter_manager/lib/compare_filters.ts +++ b/src/plugins/data/public/query/filter_manager/lib/compare_filters.ts @@ -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; }; @@ -79,6 +82,7 @@ export const compareFilters = ( state: false, negate: false, disabled: false, + alias: false, }); if (!comparators.state) excludedAttributes.push('$state');