From 36a47f1b4774020c89bc02d1d17ea5c6f43e0eb9 Mon Sep 17 00:00:00 2001 From: nreese Date: Tue, 23 Nov 2021 14:23:45 -0700 Subject: [PATCH 1/3] [Maps] fix creating filter from array fields --- .../tooltips/es_tooltip_property.test.ts | 35 +++++++++++++++++++ .../classes/tooltips/es_tooltip_property.ts | 9 +++-- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/maps/public/classes/tooltips/es_tooltip_property.test.ts b/x-pack/plugins/maps/public/classes/tooltips/es_tooltip_property.test.ts index 8ee9d30ecbf8..5111a58a4f9e 100644 --- a/x-pack/plugins/maps/public/classes/tooltips/es_tooltip_property.test.ts +++ b/x-pack/plugins/maps/public/classes/tooltips/es_tooltip_property.test.ts @@ -108,6 +108,41 @@ describe('getESFilters', () => { ]); }); + test('Should return phrase filters when field value is an array', async () => { + const esTooltipProperty = new ESTooltipProperty( + new TooltipProperty( + featurePropertyField.getName(), + await featurePropertyField.getLabel(), + ['my value', 'my other value'] + ), + indexPattern, + featurePropertyField, + APPLY_GLOBAL_QUERY + ); + expect(await esTooltipProperty.getESFilters()).toEqual([ + { + meta: { + index: 'indexPatternId', + }, + query: { + match_phrase: { + ['machine.os']: 'my value', + }, + }, + }, + { + meta: { + index: 'indexPatternId', + }, + query: { + match_phrase: { + ['machine.os']: 'my other value', + }, + }, + }, + ]); + }); + test('Should return NOT exists filter for null values', async () => { const esTooltipProperty = new ESTooltipProperty( new TooltipProperty( diff --git a/x-pack/plugins/maps/public/classes/tooltips/es_tooltip_property.ts b/x-pack/plugins/maps/public/classes/tooltips/es_tooltip_property.ts index 8b08d3a195a3..63d27c09c2eb 100644 --- a/x-pack/plugins/maps/public/classes/tooltips/es_tooltip_property.ts +++ b/x-pack/plugins/maps/public/classes/tooltips/es_tooltip_property.ts @@ -96,13 +96,16 @@ export class ESTooltipProperty implements ITooltipProperty { return []; } - const value = this.getRawValue(); - if (value == null) { + const rawValue = this.getRawValue(); + if (rawValue == null) { const existsFilter = esFilters.buildExistsFilter(indexPatternField, this._indexPattern); existsFilter.meta.negate = true; return [existsFilter]; } else { - return [esFilters.buildPhraseFilter(indexPatternField, value as string, this._indexPattern)]; + const values = Array.isArray(rawValue) ? rawValue as string[] : [rawValue as string]; + return values.map(value => { + return esFilters.buildPhraseFilter(indexPatternField, value as string, this._indexPattern); + }); } } } From f7747b0e3cf12d6eca9883f00791cf39038c6dab Mon Sep 17 00:00:00 2001 From: nreese Date: Tue, 23 Nov 2021 14:24:31 -0700 Subject: [PATCH 2/3] eslint --- .../public/classes/tooltips/es_tooltip_property.test.ts | 9 ++++----- .../maps/public/classes/tooltips/es_tooltip_property.ts | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/x-pack/plugins/maps/public/classes/tooltips/es_tooltip_property.test.ts b/x-pack/plugins/maps/public/classes/tooltips/es_tooltip_property.test.ts index 5111a58a4f9e..e2d93a693767 100644 --- a/x-pack/plugins/maps/public/classes/tooltips/es_tooltip_property.test.ts +++ b/x-pack/plugins/maps/public/classes/tooltips/es_tooltip_property.test.ts @@ -110,11 +110,10 @@ describe('getESFilters', () => { test('Should return phrase filters when field value is an array', async () => { const esTooltipProperty = new ESTooltipProperty( - new TooltipProperty( - featurePropertyField.getName(), - await featurePropertyField.getLabel(), - ['my value', 'my other value'] - ), + new TooltipProperty(featurePropertyField.getName(), await featurePropertyField.getLabel(), [ + 'my value', + 'my other value', + ]), indexPattern, featurePropertyField, APPLY_GLOBAL_QUERY diff --git a/x-pack/plugins/maps/public/classes/tooltips/es_tooltip_property.ts b/x-pack/plugins/maps/public/classes/tooltips/es_tooltip_property.ts index 63d27c09c2eb..c0d7d604d1d8 100644 --- a/x-pack/plugins/maps/public/classes/tooltips/es_tooltip_property.ts +++ b/x-pack/plugins/maps/public/classes/tooltips/es_tooltip_property.ts @@ -102,8 +102,8 @@ export class ESTooltipProperty implements ITooltipProperty { existsFilter.meta.negate = true; return [existsFilter]; } else { - const values = Array.isArray(rawValue) ? rawValue as string[] : [rawValue as string]; - return values.map(value => { + const values = Array.isArray(rawValue) ? (rawValue as string[]) : [rawValue as string]; + return values.map((value) => { return esFilters.buildPhraseFilter(indexPatternField, value as string, this._indexPattern); }); } From 2113b83eb3110d9a2b88e954e47d25f62c4c545a Mon Sep 17 00:00:00 2001 From: nreese Date: Tue, 23 Nov 2021 14:27:19 -0700 Subject: [PATCH 3/3] remove unneeded cast --- .../plugins/maps/public/classes/tooltips/es_tooltip_property.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/maps/public/classes/tooltips/es_tooltip_property.ts b/x-pack/plugins/maps/public/classes/tooltips/es_tooltip_property.ts index c0d7d604d1d8..1b677b196c99 100644 --- a/x-pack/plugins/maps/public/classes/tooltips/es_tooltip_property.ts +++ b/x-pack/plugins/maps/public/classes/tooltips/es_tooltip_property.ts @@ -104,7 +104,7 @@ export class ESTooltipProperty implements ITooltipProperty { } else { const values = Array.isArray(rawValue) ? (rawValue as string[]) : [rawValue as string]; return values.map((value) => { - return esFilters.buildPhraseFilter(indexPatternField, value as string, this._indexPattern); + return esFilters.buildPhraseFilter(indexPatternField, value, this._indexPattern); }); } }