From 2344db382613d91b1e02d3b6e7bb8b2f167c8ca6 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Mon, 13 Sep 2021 12:55:22 -0600 Subject: [PATCH] tslint --- src/plugins/data/public/mocks.ts | 6 + .../lib/mappers/map_spatial_filter.ts | 12 +- .../filter_editor/filter_editor_service.ts | 4 +- .../filter_editor/filter_operator_registry.ts | 273 ++++++++---------- .../ui/filter_bar/filter_editor/index.tsx | 46 +-- .../lib/filter_editor_utils.test.ts | 12 + .../filter_editor/lib/filter_editor_utils.ts | 19 +- .../filter_editor/lib/filter_operators.ts | 68 ----- .../filter_editor/phrase_suggestor.tsx | 11 +- .../filter_editor/phrase_value_input.tsx | 4 + .../filter_editor/phrases_values_input.tsx | 4 + .../spatial_filter_utils.ts | 3 +- x-pack/plugins/maps/public/plugin.ts | 5 +- .../public/setup/spatial_filter_operator.ts | 24 +- 14 files changed, 207 insertions(+), 284 deletions(-) delete mode 100644 src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_operators.ts diff --git a/src/plugins/data/public/mocks.ts b/src/plugins/data/public/mocks.ts index 40882fa1134e9..ed180fe40cf3d 100644 --- a/src/plugins/data/public/mocks.ts +++ b/src/plugins/data/public/mocks.ts @@ -12,6 +12,7 @@ import { searchServiceMock } from './search/mocks'; import { queryServiceMock } from './query/mocks'; import { AutocompleteStart, AutocompleteSetup } from './autocomplete'; import { createNowProviderMock } from './now_provider/mocks'; +import { FilterEditorSetup } from './ui/filter_bar/filter_editor/filter_editor_service'; export type Setup = jest.Mocked>; export type Start = jest.Mocked>; @@ -27,12 +28,17 @@ const autocompleteStartMock: jest.Mocked = { hasQuerySuggestions: jest.fn(), }; +const filterEditorSetupMock: jest.Mocked = { + registerFilterOperator: jest.fn(), +}; + const createSetupContract = (): Setup => { const querySetupMock = queryServiceMock.createSetupContract(); return { autocomplete: autocompleteSetupMock, search: searchServiceMock.createSetupContract(), query: querySetupMock, + filterEditor: filterEditorSetupMock, }; }; diff --git a/src/plugins/data/public/query/filter_manager/lib/mappers/map_spatial_filter.ts b/src/plugins/data/public/query/filter_manager/lib/mappers/map_spatial_filter.ts index cc9eacf46a266..b66476ad4d467 100644 --- a/src/plugins/data/public/query/filter_manager/lib/mappers/map_spatial_filter.ts +++ b/src/plugins/data/public/query/filter_manager/lib/mappers/map_spatial_filter.ts @@ -10,11 +10,7 @@ import { Filter, FILTERS } from '@kbn/es-query'; // Use mapSpatialFilter mapper to avoid bloated meta with value and params for spatial filters. export const mapSpatialFilter = (filter: Filter) => { - if ( - filter.meta && - filter.meta.key && - filter.meta.type === FILTERS.SPATIAL_FILTER - ) { + if (filter.meta && filter.meta.key && filter.meta.type === FILTERS.SPATIAL_FILTER) { return { key: filter.meta.key, type: filter.meta.type, @@ -22,11 +18,7 @@ export const mapSpatialFilter = (filter: Filter) => { }; } - if ( - filter.meta && - filter.meta.type === FILTERS.SPATIAL_FILTER && - filter.meta.isMultiIndex - ) { + if (filter.meta && filter.meta.type === FILTERS.SPATIAL_FILTER && filter.meta.isMultiIndex) { return { key: 'query', type: filter.meta.type, diff --git a/src/plugins/data/public/ui/filter_bar/filter_editor/filter_editor_service.ts b/src/plugins/data/public/ui/filter_bar/filter_editor/filter_editor_service.ts index da7f1b6088ade..249385bfb557b 100644 --- a/src/plugins/data/public/ui/filter_bar/filter_editor/filter_editor_service.ts +++ b/src/plugins/data/public/ui/filter_bar/filter_editor/filter_editor_service.ts @@ -22,7 +22,7 @@ export class FilterEditorService { * @param {Operator} newOperator - operator definition */ registerFilterOperator: filterOperatorRegistry.add, - } + }; } public start() { @@ -36,4 +36,4 @@ export class FilterEditorService { /** @public types */ export { Operator }; -export type FilterEditorSetup = ReturnType; \ No newline at end of file +export type FilterEditorSetup = ReturnType; diff --git a/src/plugins/data/public/ui/filter_bar/filter_editor/filter_operator_registry.ts b/src/plugins/data/public/ui/filter_bar/filter_editor/filter_operator_registry.ts index 1a3eab746fedb..f331d35ed70a9 100644 --- a/src/plugins/data/public/ui/filter_bar/filter_editor/filter_operator_registry.ts +++ b/src/plugins/data/public/ui/filter_bar/filter_editor/filter_operator_registry.ts @@ -7,34 +7,53 @@ */ import { i18n } from '@kbn/i18n'; -import { buildFilter as esQueryBuildFilter, FILTERS, getFilterParams } from '@kbn/es-query'; -import { ReactElement } from 'react'; +import { + buildFilter as esQueryBuildFilter, + Filter, + FILTERS, + getFilterParams, + IndexPatternBase, + IndexPatternFieldBase, +} from '@kbn/es-query'; +import { ComponentType } from 'react'; +import { FilterStateStore } from '../../../../common'; +import { IIndexPattern, IFieldType } from '../../..'; import { PhraseValueInput } from './phrase_value_input'; import { PhrasesValuesInput } from './phrases_values_input'; import { RangeValueInput } from './range_value_input'; import { EXISTS_LABEL, PHRASES_LABEL } from './lib/filter_label'; -import { isExistsFilterValid, isPhraseFilterValid, isPhrasesFilterValid, isRangeFilterValid } from './lib/filter_editor_utils'; +import { + isExistsFilterValid, + isPhraseFilterValid, + isPhrasesFilterValid, + isRangeFilterValid, +} from './lib/filter_editor_utils'; + +interface EditorProps { + indexPattern?: IIndexPattern; + field?: IFieldType; + value?: any; + onChange: (params: any) => void; + timeRangeForSuggestionsOverride?: boolean; + fullWidth?: boolean; +} export interface Operator { message: string; type: FILTERS; negate: boolean; fieldTypes?: string[]; - editor: ReactElement | null; + editor: ComponentType | null; buildFilter: ( - indexPattern?: IndexPatternBase, - field?: IndexPatternFieldBase, disabled: boolean, - params?: Serializable, alias: string | null, + indexPattern?: IndexPatternBase, + field?: IndexPatternFieldBase, + params?: any, store?: FilterStateStore ) => Filter | undefined; getFilterParams: (filter: Filter) => any; - isFilterValid: ( - indexPattern?: IIndexPattern, - field?: IFieldType, - params?: any, - ) => boolean; + isFilterValid: (indexPattern?: IIndexPattern, field?: IFieldType, params?: any) => boolean; } const registry: Operator[] = [ @@ -45,25 +64,18 @@ const registry: Operator[] = [ type: FILTERS.PHRASE, negate: false, editor: PhraseValueInput, - buildFilter: ( - indexPattern, - field, - disabled, - params, - alias, - store, - ) => { + buildFilter: (disabled, alias, indexPattern, field, params, store) => { return indexPattern && field ? esQueryBuildFilter( - indexPattern, - field, - FILTERS.PHRASE, - false, - disabled, - params, - alias, - store - ) + indexPattern, + field, + FILTERS.PHRASE, + false, + disabled, + params, + alias, + store + ) : undefined; }, getFilterParams, @@ -76,25 +88,18 @@ const registry: Operator[] = [ type: FILTERS.PHRASE, negate: true, editor: PhraseValueInput, - buildFilter: ( - indexPattern, - field, - disabled, - params, - alias, - store, - ) => { + buildFilter: (disabled, alias, indexPattern, field, params, store) => { return indexPattern && field ? esQueryBuildFilter( - indexPattern, - field, - FILTERS.PHRASE, - true, - disabled, - params, - alias, - store - ) + indexPattern, + field, + FILTERS.PHRASE, + true, + disabled, + params, + alias, + store + ) : undefined; }, getFilterParams, @@ -106,25 +111,18 @@ const registry: Operator[] = [ negate: false, fieldTypes: ['string', 'number', 'date', 'ip', 'geo_point', 'geo_shape'], editor: PhrasesValuesInput, - buildFilter: ( - indexPattern, - field, - disabled, - params, - alias, - store, - ) => { + buildFilter: (disabled, alias, indexPattern, field, params, store) => { return indexPattern && field ? esQueryBuildFilter( - indexPattern, - field, - FILTERS.PHRASES, - false, - disabled, - params, - alias, - store - ) + indexPattern, + field, + FILTERS.PHRASES, + false, + disabled, + params, + alias, + store + ) : undefined; }, getFilterParams, @@ -138,25 +136,18 @@ const registry: Operator[] = [ negate: true, fieldTypes: ['string', 'number', 'date', 'ip', 'geo_point', 'geo_shape'], editor: PhrasesValuesInput, - buildFilter: ( - indexPattern, - field, - disabled, - params, - alias, - store, - ) => { + buildFilter: (disabled, alias, indexPattern, field, params, store) => { return indexPattern && field ? esQueryBuildFilter( - indexPattern, - field, - FILTERS.PHRASES, - true, - disabled, - params, - alias, - store - ) + indexPattern, + field, + FILTERS.PHRASES, + true, + disabled, + params, + alias, + store + ) : undefined; }, getFilterParams, @@ -170,25 +161,18 @@ const registry: Operator[] = [ negate: false, fieldTypes: ['number', 'number_range', 'date', 'date_range', 'ip', 'ip_range'], editor: RangeValueInput, - buildFilter: ( - indexPattern, - field, - disabled, - params, - alias, - store, - ) => { + buildFilter: (disabled, alias, indexPattern, field, params, store) => { return indexPattern && field ? esQueryBuildFilter( - indexPattern, - field, - FILTERS.RANGE, - false, - disabled, - params, - alias, - store - ) + indexPattern, + field, + FILTERS.RANGE, + false, + disabled, + params, + alias, + store + ) : undefined; }, getFilterParams, @@ -202,25 +186,18 @@ const registry: Operator[] = [ negate: true, fieldTypes: ['number', 'number_range', 'date', 'date_range', 'ip', 'ip_range'], editor: RangeValueInput, - buildFilter: ( - indexPattern, - field, - disabled, - params, - alias, - store, - ) => { + buildFilter: (disabled, alias, indexPattern, field, params, store) => { return indexPattern && field ? esQueryBuildFilter( - indexPattern, - field, - FILTERS.RANGE, - true, - disabled, - params, - alias, - store - ) + indexPattern, + field, + FILTERS.RANGE, + true, + disabled, + params, + alias, + store + ) : undefined; }, getFilterParams, @@ -231,25 +208,18 @@ const registry: Operator[] = [ type: FILTERS.EXISTS, negate: false, editor: null, - buildFilter: ( - indexPattern, - field, - disabled, - params, - alias, - store, - ) => { + buildFilter: (disabled, alias, indexPattern, field, params, store) => { return indexPattern && field ? esQueryBuildFilter( - indexPattern, - field, - FILTERS.EXISTS, - false, - disabled, - params, - alias, - store - ) + indexPattern, + field, + FILTERS.EXISTS, + false, + disabled, + params, + alias, + store + ) : undefined; }, getFilterParams, @@ -262,30 +232,23 @@ const registry: Operator[] = [ type: FILTERS.EXISTS, negate: true, editor: null, - buildFilter: ( - indexPattern, - field, - disabled, - params, - alias, - store, - ) => { + buildFilter: (disabled, alias, indexPattern, field, params, store) => { return indexPattern && field ? esQueryBuildFilter( - indexPattern, - field, - FILTERS.EXISTS, - true, - disabled, - params, - alias, - store - ) + indexPattern, + field, + FILTERS.EXISTS, + true, + disabled, + params, + alias, + store + ) : undefined; }, getFilterParams, isFilterValid: isExistsFilterValid, - } + }, ]; interface FilterOperatorRegistry { @@ -296,9 +259,15 @@ interface FilterOperatorRegistry { export const filterOperatorRegistry: FilterOperatorRegistry = { get: () => [...registry], add: (newOperator: Operator) => { - if (registry.find((operator) => operator.type === newOperator.type && operator.negate === newOperator.negate)) { - throw new Error(`Filter operator already registered for type: ${newOperator.type}, negate: ${newOperator.negate}`); + if ( + registry.find( + (operator) => operator.type === newOperator.type && operator.negate === newOperator.negate + ) + ) { + throw new Error( + `Filter operator already registered for type: ${newOperator.type}, negate: ${newOperator.negate}` + ); } registry.push(newOperator); }, -}; \ No newline at end of file +}; diff --git a/src/plugins/data/public/ui/filter_bar/filter_editor/index.tsx b/src/plugins/data/public/ui/filter_bar/filter_editor/index.tsx index d1b990e428a2e..2f6ae631a4668 100644 --- a/src/plugins/data/public/ui/filter_bar/filter_editor/index.tsx +++ b/src/plugins/data/public/ui/filter_bar/filter_editor/index.tsx @@ -25,6 +25,7 @@ import { i18n } from '@kbn/i18n'; import { FormattedMessage, InjectedIntl, injectI18n } from '@kbn/i18n/react'; import { Filter, + FILTERS, FieldFilter, buildCustomFilter, cleanFilter, @@ -39,7 +40,6 @@ import { getOperatorFromFilter, getOperatorOptions, getOperatorTypes, - isFilterValid, } from './lib/filter_editor_utils'; import { Operator } from './filter_operator_registry'; import { getIndexPatternFromFilter } from '../../../query'; @@ -73,7 +73,9 @@ class FilterEditorUI extends Component { selectedIndexPattern: this.getIndexPatternFromFilter(), selectedField: this.getFieldFromFilter(), selectedOperator, - params: selectedOperator ? selectedOperator.getFilterParams(props.filter) : getFilterParams(props.filter), + params: selectedOperator + ? selectedOperator.getFilterParams(props.filter) + : getFilterParams(props.filter), useCustomLabel: props.filter.meta.alias !== null, customLabel: props.filter.meta.alias || '', queryDsl: JSON.stringify(cleanFilter(props.filter), null, 2), @@ -328,8 +330,9 @@ class FilterEditorUI extends Component { ); } - const operatorEditor = this.state.selectedOperator && this.state.selectedOperator.editor !== null - ?
+ const operatorEditor = + this.state.selectedOperator && this.state.selectedOperator.editor !== null ? ( +
{ fullWidth />
- : null; + ) : null; - // Do not show operator select for multi-index filters since they operate on many fields + // Do not show operator select for multi-index filters since they operate on many fields // and cannot transition to different operator types - const operatorSelect = !this.props.filter.meta.isMultiIndex - ? <> - - {this.renderFieldInput()} - - {this.renderOperatorInput()} - - - - - : null; - + const operatorSelect = !this.props.filter.meta.isMultiIndex ? ( + <> + + {this.renderFieldInput()} + + {this.renderOperatorInput()} + + + + + ) : null; + return (
{operatorSelect} @@ -370,7 +373,7 @@ class FilterEditorUI extends Component { private isUnknownFilterType() { const { type } = this.props.filter.meta; - return !!type && !getOperatorTypes().includes(type); + return !!type && !getOperatorTypes().includes(type as FILTERS); } private getIndexPatternFromFilter() { @@ -474,12 +477,13 @@ class FilterEditorUI extends Component { const body = JSON.parse(queryDsl); filter = buildCustomFilter(newIndex, body, disabled, negate, alias, $state.store); } else if (operator) { + const disabled = this.props.filter.meta.disabled ?? false; filter = operator.buildFilter( + disabled, + alias, indexPattern, field, - this.props.filter.meta.disabled ?? false, params ?? '', - alias, $state.store ); } diff --git a/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_editor_utils.test.ts b/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_editor_utils.test.ts index a816e93607fb5..f0a522297cea0 100644 --- a/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_editor_utils.test.ts +++ b/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_editor_utils.test.ts @@ -150,6 +150,18 @@ describe('Filter editor utils', () => { }); }); + describe('isPhraseFilterValid', () => { + it('should return false for phrase filter invalid params', () => { + const isValid = isPhraseFilterValid(stubIndexPattern, stubFields[4], 'foo'); + expect(isValid).toBe(false); + }); + + it('should return true for phrases filter valid params', () => { + const isValid = isPhraseFilterValid(stubIndexPattern, stubFields[4], 'now'); + expect(isValid).toBe(true); + }); + }); + describe('isPhrasesFilterValid', () => { it('should return false for phrases filter without phrases', () => { const isValid = isPhrasesFilterValid(stubIndexPattern, stubFields[0], []); diff --git a/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_editor_utils.ts b/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_editor_utils.ts index 664b3a332eb17..798059ace1605 100644 --- a/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_editor_utils.ts +++ b/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_editor_utils.ts @@ -9,7 +9,7 @@ import _ from 'lodash'; import dateMath from '@elastic/datemath'; import { Filter, FieldFilter } from '@kbn/es-query'; -import { filterOperatorRegistry, Operator } from '../filter_operator_registry'; +import { filterOperatorRegistry } from '../filter_operator_registry'; import { isFilterable, IIndexPattern, IFieldType, IpAddress } from '../../../../../common'; export function getFieldFromFilter(filter: FieldFilter, indexPattern: IIndexPattern) { @@ -58,7 +58,7 @@ export function validateParams(params: any, type: string) { export function isPhraseFilterValid( indexPattern?: IIndexPattern, field?: IFieldType, - params?: any, + params?: any ) { if (!indexPattern || !field) { return false; @@ -69,7 +69,7 @@ export function isPhraseFilterValid( export function isPhrasesFilterValid( indexPattern?: IIndexPattern, field?: IFieldType, - params?: any, + params?: any ) { if (!indexPattern || !field) { return false; @@ -80,11 +80,7 @@ export function isPhrasesFilterValid( return params.every((phrase) => validateParams(phrase, field.type)); } -export function isRangeFilterValid( - indexPattern?: IIndexPattern, - field?: IFieldType, - params?: any, -) { +export function isRangeFilterValid(indexPattern?: IIndexPattern, field?: IFieldType, params?: any) { if (!indexPattern || !field) { return false; } @@ -97,9 +93,6 @@ export function isRangeFilterValid( ); } -export function isExistsFilterValid( - indexPattern?: IIndexPattern, - field?: IFieldType, -) { +export function isExistsFilterValid(indexPattern?: IIndexPattern, field?: IFieldType) { return indexPattern !== undefined && field !== undefined; -} \ No newline at end of file +} diff --git a/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_operators.ts b/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_operators.ts deleted file mode 100644 index fd06b719ae7ed..0000000000000 --- a/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_operators.ts +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import { i18n } from '@kbn/i18n'; -import { FILTERS, getFilterParams } from '@kbn/es-query'; -import { ReactElement } from 'react'; -import { PhraseValueInput } from '../phrase_value_input'; -import { PhrasesValuesInput } from '../phrases_values_input'; -import { RangeValueInput } from '../range_value_input'; -import { buildEsQueryFilter, isExistsFilterValid, isPhraseFilterValid, isPhrasesFilterValid, isRangeFilterValid } from './filter_editor_utils'; - -export const spatialFilterOperator = { - message: i18n.translate('data.filter.filterEditor.spatialFilterLabel', { - defaultMessage: 'spatial filter', - }), - type: FILTERS.SPATIAL_FILTER, - negate: false, - fieldTypes: ['geo_point', 'geo_shape'], - editor: null, - buildFilter: ( - indexPattern: IndexPatternBase, - field: IndexPatternFieldBase, - type: FILTERS, - negate: boolean, - disabled: boolean, - params: Serializable, - alias: string | null, - store?: FilterStateStore - ) => { - const filter: Filter = { - meta: { - alias, - negate, - disabled, - isMultiIndex: true, - type, - }, - query: params.query - }; - if (store) { - filter.$state = { store }; - } - return filter; - }, - getFilterParams: (filter: Filter) => { - return { query: filter.query }; - }, - isFilterValid: ( - indexPattern?: IIndexPattern, - field?: IFieldType, - params?: any, - ) => { - if (indexPattern && field) { - return true; - } - - if (params?.query) { - return true; - } - - return false; - }, -}; \ No newline at end of file diff --git a/src/plugins/data/public/ui/filter_bar/filter_editor/phrase_suggestor.tsx b/src/plugins/data/public/ui/filter_bar/filter_editor/phrase_suggestor.tsx index fb3106e6a8f06..d0dfa6060ea97 100644 --- a/src/plugins/data/public/ui/filter_bar/filter_editor/phrase_suggestor.tsx +++ b/src/plugins/data/public/ui/filter_bar/filter_editor/phrase_suggestor.tsx @@ -15,7 +15,7 @@ import { UI_SETTINGS } from '../../../../common'; export interface PhraseSuggestorProps { kibana: KibanaReactContextValue; - indexPattern: IIndexPattern; + indexPattern?: IIndexPattern; field?: IFieldType; timeRangeForSuggestionsOverride?: boolean; } @@ -62,17 +62,20 @@ export class PhraseSuggestorUI extends React.Com }; protected updateSuggestions = debounce(async (query: string = '') => { + if (!this.props.indexPattern) { + return; + } + if (this.abortController) this.abortController.abort(); this.abortController = new AbortController(); - const { indexPattern, field, timeRangeForSuggestionsOverride } = this - .props as PhraseSuggestorProps; + const { field, timeRangeForSuggestionsOverride } = this.props as PhraseSuggestorProps; if (!field || !this.isSuggestingValues()) { return; } this.setState({ isLoading: true }); const suggestions = await this.services.data.autocomplete.getValueSuggestions({ - indexPattern, + indexPattern: this.props.indexPattern!, field, query, signal: this.abortController.signal, diff --git a/src/plugins/data/public/ui/filter_bar/filter_editor/phrase_value_input.tsx b/src/plugins/data/public/ui/filter_bar/filter_editor/phrase_value_input.tsx index c71605b8b7244..145e6e9a405a3 100644 --- a/src/plugins/data/public/ui/filter_bar/filter_editor/phrase_value_input.tsx +++ b/src/plugins/data/public/ui/filter_bar/filter_editor/phrase_value_input.tsx @@ -24,6 +24,10 @@ interface Props extends PhraseSuggestorProps { class PhraseValueInputUI extends PhraseSuggestorUI { public render() { + if (!this.props.indexPattern) { + return null; + } + return ( { public render() { + if (!this.props.indexPattern) { + return null; + } + const { suggestions } = this.state; const { values, intl, onChange, fullWidth } = this.props; const options = values ? uniq([...values, ...suggestions]) : suggestions; diff --git a/x-pack/plugins/maps/common/elasticsearch_util/spatial_filter_utils.ts b/x-pack/plugins/maps/common/elasticsearch_util/spatial_filter_utils.ts index 8e0d76b07e734..1e60247cbfaf1 100644 --- a/x-pack/plugins/maps/common/elasticsearch_util/spatial_filter_utils.ts +++ b/x-pack/plugins/maps/common/elasticsearch_util/spatial_filter_utils.ts @@ -30,7 +30,7 @@ function createMultiGeoFieldFilter( throw new Error('Unable to create filter, geo fields not provided'); } - // Regardless of whether there is a single geo field or multile geo fields, + // Regardless of whether there is a single geo field or multile geo fields, // the filter is considered "isMultiIndex" because the geo field(s) is not couple to a single index pattern const spatialFilterMeta = { ...meta, @@ -203,7 +203,6 @@ export function extractFeaturesFromFilters(filters: GeoFilter[]): Feature[] { return filter.meta.type === SPATIAL_FILTER_TYPE; }) .forEach((filter) => { - let geoFieldName: string | undefined; let spatialClause: GeoFilter | undefined; if (filter?.query?.bool?.must) { diff --git a/x-pack/plugins/maps/public/plugin.ts b/x-pack/plugins/maps/public/plugin.ts index 0a261dcccb675..e9a1ccc9974bd 100644 --- a/x-pack/plugins/maps/public/plugin.ts +++ b/x-pack/plugins/maps/public/plugin.ts @@ -56,7 +56,10 @@ import { } from './api'; import type { SharePluginSetup, SharePluginStart } from '../../../../src/plugins/share/public'; import type { MapsEmsPluginSetup } from '../../../../src/plugins/maps_ems/public'; -import type { DataPublicPluginSetup, DataPublicPluginStart } from '../../../../src/plugins/data/public'; +import type { + DataPublicPluginSetup, + DataPublicPluginStart, +} from '../../../../src/plugins/data/public'; import type { LicensingPluginSetup, LicensingPluginStart } from '../../licensing/public'; import type { FileUploadPluginStart } from '../../file_upload/public'; import type { SavedObjectsStart } from '../../../../src/plugins/saved_objects/public'; diff --git a/x-pack/plugins/maps/public/setup/spatial_filter_operator.ts b/x-pack/plugins/maps/public/setup/spatial_filter_operator.ts index 3f8f7d6414011..0b2dff9bae494 100644 --- a/x-pack/plugins/maps/public/setup/spatial_filter_operator.ts +++ b/x-pack/plugins/maps/public/setup/spatial_filter_operator.ts @@ -6,8 +6,14 @@ */ import { i18n } from '@kbn/i18n'; -import { FILTERS, getFilterParams } from '@kbn/es-query'; -import { ReactElement } from 'react'; +import { + Filter, + FILTERS, + FilterStateStore, + IndexPatternBase, + IndexPatternFieldBase, +} from '@kbn/es-query'; +import type { IFieldType, IIndexPattern } from 'src/plugins/data/public'; export const spatialFilterOperator = { message: i18n.translate('xpack.maps.filterOperator.spatialFilterLabel', { @@ -18,11 +24,11 @@ export const spatialFilterOperator = { fieldTypes: ['geo_point', 'geo_shape'], editor: null, buildFilter: ( - indexPattern: IndexPatternBase, - field: IndexPatternFieldBase, disabled: boolean, - params: Serializable, alias: string | null, + indexPattern?: IndexPatternBase, + field?: IndexPatternFieldBase, + params?: any, store?: FilterStateStore ) => { const filter: Filter = { @@ -33,7 +39,7 @@ export const spatialFilterOperator = { isMultiIndex: true, type: FILTERS.SPATIAL_FILTER, }, - query: params.query + query: params.query, }; if (store) { filter.$state = { store }; @@ -43,11 +49,7 @@ export const spatialFilterOperator = { getFilterParams: (filter: Filter) => { return { query: filter.query }; }, - isFilterValid: ( - indexPattern?: IIndexPattern, - field?: IFieldType, - params?: any, - ) => { + isFilterValid: (indexPattern?: IIndexPattern, field?: IFieldType, params?: any) => { if (indexPattern && field) { return true; }