diff --git a/src/plugins/data/public/query/filter_manager/lib/mappers/map_range.test.ts b/src/plugins/data/public/query/filter_manager/lib/mappers/map_range.test.ts index 82c701a510dfa6f..5e902487d923d73 100644 --- a/src/plugins/data/public/query/filter_manager/lib/mappers/map_range.test.ts +++ b/src/plugins/data/public/query/filter_manager/lib/mappers/map_range.test.ts @@ -69,28 +69,28 @@ describe('filter manager utilities', () => { const params = { gt: 50 }; const filter = { meta: { params } } as RangeFilter; const result = getRangeDisplayValue(filter); - expect(result).toMatchInlineSnapshot(`"50 to Infinity"`); + expect(result).toMatchInlineSnapshot(`"≥ 50"`); }); test('gte', () => { const params = { gte: 60 }; const filter = { meta: { params } } as RangeFilter; const result = getRangeDisplayValue(filter); - expect(result).toMatchInlineSnapshot(`"60 to Infinity"`); + expect(result).toMatchInlineSnapshot(`"≥ 60"`); }); test('lt', () => { const params = { lt: 70 }; const filter = { meta: { params } } as RangeFilter; const result = getRangeDisplayValue(filter); - expect(result).toMatchInlineSnapshot(`"-Infinity to 70"`); + expect(result).toMatchInlineSnapshot(`"< 70"`); }); test('lte', () => { const params = { lte: 80 }; const filter = { meta: { params } } as RangeFilter; const result = getRangeDisplayValue(filter); - expect(result).toMatchInlineSnapshot(`"-Infinity to 80"`); + expect(result).toMatchInlineSnapshot(`"< 80"`); }); }); }); diff --git a/src/plugins/unified_search/public/filter_badge/filter_content/filter_content.tsx b/src/plugins/unified_search/public/filter_badge/filter_content/filter_content.tsx index 22aab2a85e6116b..21309647c67ce82 100644 --- a/src/plugins/unified_search/public/filter_badge/filter_content/filter_content.tsx +++ b/src/plugins/unified_search/public/filter_badge/filter_content/filter_content.tsx @@ -81,12 +81,6 @@ export function FilterContent({ filter, valueLabel, fieldLabel, hideAlias }: Fil ); case FILTERS.PHRASE: - return ( - <> - - - - ); case FILTERS.RANGE: return ( <> diff --git a/src/plugins/unified_search/public/filter_bar/filter_editor/lib/filter_editor_utils.ts b/src/plugins/unified_search/public/filter_bar/filter_editor/lib/filter_editor_utils.ts index 1866e7b281e5591..7adfa36abf3e42d 100644 --- a/src/plugins/unified_search/public/filter_bar/filter_editor/lib/filter_editor_utils.ts +++ b/src/plugins/unified_search/public/filter_bar/filter_editor/lib/filter_editor_utils.ts @@ -12,30 +12,33 @@ import { ES_FIELD_TYPES } from '@kbn/field-types'; import isSemverValid from 'semver/functions/valid'; import { isFilterable, IpAddress } from '@kbn/data-plugin/common'; import type { DataView, DataViewField } from '@kbn/data-views-plugin/common'; -import { FILTER_OPERATORS, Operator } from './filter_operators'; +import { FILTER_OPERATORS, OPERATORS, Operator } from './filter_operators'; export function getFieldFromFilter(filter: Filter, indexPattern?: DataView) { return indexPattern?.fields.find((field) => field.name === filter.meta.key); } -function getRangeOperatorFromFilter({ meta: { params } }: RangeFilter | ScriptedRangeFilter) { - const { gte, gt, lte, lt } = params || {}; - if (gte === undefined && lt === undefined && lte === undefined && gt === undefined) { - return 'between'; +function getRangeOperatorFromFilter({ + meta: { params = {}, negate }, +}: RangeFilter | ScriptedRangeFilter) { + if (negate) { + // if filter is negated, always use 'is not between' operator + return OPERATORS.NOT_BETWEEN; } + const { gte, gt, lte, lt } = params; const left = gte ?? gt; const right = lte ?? lt; if (left !== undefined && right !== undefined) { - return 'between'; + return OPERATORS.BETWEEN; } if (left !== undefined) { - return 'greater_or_equal'; + return OPERATORS.GREATER_OR_EQUAL; } if (right !== undefined) { - return 'less'; + return OPERATORS.LESS; } - return 'between'; + return OPERATORS.BETWEEN; } export function getOperatorFromFilter(filter: Filter) { diff --git a/src/plugins/unified_search/public/filter_bar/filter_editor/lib/filter_operators.ts b/src/plugins/unified_search/public/filter_bar/filter_editor/lib/filter_operators.ts index 8e5fd9b010d5cd6..3d686f6ea13f07b 100644 --- a/src/plugins/unified_search/public/filter_bar/filter_editor/lib/filter_operators.ts +++ b/src/plugins/unified_search/public/filter_bar/filter_editor/lib/filter_operators.ts @@ -54,11 +54,24 @@ export const strings = { }), }; +export enum OPERATORS { + LESS = 'less', + GREATER_OR_EQUAL = 'greater_or_equal', + BETWEEN = 'between', + IS = 'is', + NOT_BETWEEN = 'not_between', + IS_NOT = 'is_not', + IS_ONE_OF = 'is_one_of', + IS_NOT_ONE_OF = 'is_not_one_of', + EXISTS = 'exists', + DOES_NOT_EXIST = 'does_not_exist', +} + export interface Operator { message: string; type: FILTERS; negate: boolean; - id?: 'less' | 'greater_or_equal' | 'between'; + id: OPERATORS; /** * KbnFieldTypes applicable for operator @@ -76,12 +89,14 @@ export const isOperator = { message: strings.getIsOperatorOptionLabel(), type: FILTERS.PHRASE, negate: false, + id: OPERATORS.IS, }; export const isNotOperator = { message: strings.getIsNotOperatorOptionLabel(), type: FILTERS.PHRASE, negate: true, + id: OPERATORS.IS_NOT, }; export const isOneOfOperator = { @@ -89,6 +104,7 @@ export const isOneOfOperator = { type: FILTERS.PHRASES, negate: false, fieldTypes: ['string', 'number', 'date', 'ip', 'geo_point', 'geo_shape'], + id: OPERATORS.IS_ONE_OF, }; export const isNotOneOfOperator = { @@ -96,6 +112,7 @@ export const isNotOneOfOperator = { type: FILTERS.PHRASES, negate: true, fieldTypes: ['string', 'number', 'date', 'ip', 'geo_point', 'geo_shape'], + id: OPERATORS.IS_NOT_ONE_OF, }; const rangeOperatorsSharedProps = { @@ -113,21 +130,21 @@ const rangeOperatorsSharedProps = { export const isBetweenOperator = { ...rangeOperatorsSharedProps, message: strings.getIsBetweenOperatorOptionLabel(), - id: 'between', + id: OPERATORS.BETWEEN, negate: false, }; export const isLessThanOperator = { ...rangeOperatorsSharedProps, message: strings.getLessThanOperatorOptionLabel(), - id: 'less', + id: OPERATORS.LESS, negate: false, }; export const isGreaterOrEqualOperator = { ...rangeOperatorsSharedProps, message: strings.getIsGreaterOrEqualOperatorOptionLabel(), - id: 'greater_or_equal', + id: OPERATORS.GREATER_OR_EQUAL, negate: false, }; @@ -135,19 +152,21 @@ export const isNotBetweenOperator = { ...rangeOperatorsSharedProps, message: strings.getIsNotBetweenOperatorOptionLabel(), negate: true, - id: 'between', + id: OPERATORS.NOT_BETWEEN, }; export const existsOperator = { message: strings.getExistsOperatorOptionLabel(), type: FILTERS.EXISTS, negate: false, + id: OPERATORS.EXISTS, }; export const doesNotExistOperator = { message: strings.getDoesNotExistOperatorOptionLabel(), type: FILTERS.EXISTS, negate: true, + id: OPERATORS.DOES_NOT_EXIST, }; export const FILTER_OPERATORS: Operator[] = [ diff --git a/src/plugins/unified_search/public/filters_builder/filter_item/params_editor_input.tsx b/src/plugins/unified_search/public/filters_builder/filter_item/params_editor_input.tsx index b613d232854f852..56be3e33af40dd9 100644 --- a/src/plugins/unified_search/public/filters_builder/filter_item/params_editor_input.tsx +++ b/src/plugins/unified_search/public/filters_builder/filter_item/params_editor_input.tsx @@ -19,6 +19,7 @@ import { } from '../../filter_bar/filter_editor'; import type { Operator } from '../../filter_bar/filter_editor'; import { SuggestionsAbstraction } from '../../typeahead/suggestions_component'; +import { OPERATORS } from '../../filter_bar/filter_editor/lib/filter_operators'; export const strings = { getSelectFieldPlaceholderLabel: () => @@ -106,19 +107,8 @@ export function ParamsEditorInput({ /> ); case 'range': - switch (operator?.id) { - case 'between': - return ( - - ); - case 'greater_or_equal': + switch (operator.id) { + case OPERATORS.GREATER_OR_EQUAL: return ( ); - case 'less': + case OPERATORS.LESS: return ( ); + default: + return ( + + ); } default: const placeholderText = getPlaceholderText(Boolean(field), Boolean(operator?.type));