From e0944d17ece72cdddbdf07b41f5209e9ffda048c Mon Sep 17 00:00:00 2001 From: Nodir Latipov Date: Mon, 23 May 2022 13:27:24 +0500 Subject: [PATCH] [Unified search] Use the DataViews service (#130008) * feat: cleanup deprecated service and type * fix: rollback test * refact: replace deprecated type * refact: changed deprecation type * feat: added comments to deprecated imports that can't be cleaned up in this PR * refact: rollback query_string_input.test file --- .../public/actions/apply_filter_action.ts | 4 +++- .../apply_filters/apply_filter_popover_content.tsx | 2 +- .../public/apply_filters/apply_filters_popover.tsx | 2 +- .../providers/kql_query_suggestion/conjunction.test.ts | 2 +- .../providers/kql_query_suggestion/field.test.ts | 3 ++- .../providers/kql_query_suggestion/field.tsx | 1 + .../providers/kql_query_suggestion/operator.test.ts | 2 +- .../providers/kql_query_suggestion/value.test.ts | 2 +- .../providers/kql_query_suggestion/value.ts | 4 +++- .../providers/query_suggestion_provider.ts | 5 +++-- .../providers/value_suggestion_provider.ts | 10 ++++------ .../public/filter_bar/filter_editor/index.tsx | 8 ++++---- .../filter_editor/lib/filter_editor_utils.test.ts | 2 +- .../filter_editor/lib/filter_editor_utils.ts | 10 +++++----- .../filter_bar/filter_editor/lib/filter_label.tsx | 2 +- .../filter_bar/filter_editor/lib/filter_operators.ts | 8 ++++---- .../filter_bar/filter_editor/phrase_suggestor.tsx | 6 +++--- .../filter_bar/filter_editor/range_value_input.tsx | 4 ++-- .../filter_bar/filter_editor/value_input_type.tsx | 4 ++-- .../create_index_pattern_select.tsx | 4 ++-- .../index_pattern_select/index_pattern_select.tsx | 4 ++-- .../public/search_bar/create_search_bar.tsx | 3 ++- .../public/search_bar/lib/use_filter_manager.ts | 3 ++- .../public/test_helpers/get_stub_filter.ts | 3 ++- .../unified_search/public/utils/helpers.test.ts | 4 ++-- src/plugins/unified_search/public/utils/helpers.ts | 4 ++-- .../server/autocomplete/terms_agg.test.ts | 5 ++++- .../unified_search/server/autocomplete/terms_agg.ts | 9 +++++---- .../server/autocomplete/terms_enum.test.ts | 9 ++++++++- .../unified_search/server/autocomplete/terms_enum.ts | 4 ++-- 30 files changed, 76 insertions(+), 57 deletions(-) diff --git a/src/plugins/unified_search/public/actions/apply_filter_action.ts b/src/plugins/unified_search/public/actions/apply_filter_action.ts index 36524cf3ff826..465d6d33890de 100644 --- a/src/plugins/unified_search/public/actions/apply_filter_action.ts +++ b/src/plugins/unified_search/public/actions/apply_filter_action.ts @@ -10,7 +10,9 @@ import { i18n } from '@kbn/i18n'; import { ThemeServiceSetup } from '@kbn/core/public'; import { toMountPoint } from '@kbn/kibana-react-plugin/public'; import { Action, createAction, IncompatibleActionError } from '@kbn/ui-actions-plugin/public'; -import { Filter, FilterManager, TimefilterContract, esFilters } from '@kbn/data-plugin/public'; +// for cleanup esFilters need to fix the issue https://github.com/elastic/kibana/issues/131292 +import { FilterManager, TimefilterContract, esFilters } from '@kbn/data-plugin/public'; +import type { Filter } from '@kbn/es-query'; import { getOverlays, getIndexPatterns } from '../services'; import { applyFiltersPopover } from '../apply_filters'; diff --git a/src/plugins/unified_search/public/apply_filters/apply_filter_popover_content.tsx b/src/plugins/unified_search/public/apply_filters/apply_filter_popover_content.tsx index 9017fbf40ee2f..8119127e87e2c 100644 --- a/src/plugins/unified_search/public/apply_filters/apply_filter_popover_content.tsx +++ b/src/plugins/unified_search/public/apply_filters/apply_filter_popover_content.tsx @@ -24,7 +24,7 @@ import { mapAndFlattenFilters, getFieldDisplayValueFromFilter, } from '@kbn/data-plugin/public'; -import { Filter } from '@kbn/data-plugin/common'; +import type { Filter } from '@kbn/es-query'; import { DataView } from '@kbn/data-views-plugin/public'; import { FilterLabel } from '../filter_bar'; diff --git a/src/plugins/unified_search/public/apply_filters/apply_filters_popover.tsx b/src/plugins/unified_search/public/apply_filters/apply_filters_popover.tsx index 4cefbd1a202a0..8c515ae4e6d78 100644 --- a/src/plugins/unified_search/public/apply_filters/apply_filters_popover.tsx +++ b/src/plugins/unified_search/public/apply_filters/apply_filters_popover.tsx @@ -7,7 +7,7 @@ */ import React from 'react'; -import { Filter } from '@kbn/data-plugin/common'; +import type { Filter } from '@kbn/es-query'; import { DataView } from '@kbn/data-views-plugin/common'; type CancelFnType = () => void; diff --git a/src/plugins/unified_search/public/autocomplete/providers/kql_query_suggestion/conjunction.test.ts b/src/plugins/unified_search/public/autocomplete/providers/kql_query_suggestion/conjunction.test.ts index 24a27bcb99fbe..d553538329874 100644 --- a/src/plugins/unified_search/public/autocomplete/providers/kql_query_suggestion/conjunction.test.ts +++ b/src/plugins/unified_search/public/autocomplete/providers/kql_query_suggestion/conjunction.test.ts @@ -7,7 +7,7 @@ */ import { coreMock } from '@kbn/core/public/mocks'; -import { KueryNode } from '@kbn/data-plugin/public'; +import type { KueryNode } from '@kbn/es-query'; import { setupGetConjunctionSuggestions } from './conjunction'; import { QuerySuggestionGetFnArgs } from '../query_suggestion_provider'; diff --git a/src/plugins/unified_search/public/autocomplete/providers/kql_query_suggestion/field.test.ts b/src/plugins/unified_search/public/autocomplete/providers/kql_query_suggestion/field.test.ts index 4446fcf685bde..085ba3dc0979f 100644 --- a/src/plugins/unified_search/public/autocomplete/providers/kql_query_suggestion/field.test.ts +++ b/src/plugins/unified_search/public/autocomplete/providers/kql_query_suggestion/field.test.ts @@ -8,7 +8,8 @@ import indexPatternResponse from './__fixtures__/index_pattern_response.json'; -import { indexPatterns as indexPatternsUtils, KueryNode } from '@kbn/data-plugin/public'; +import { indexPatterns as indexPatternsUtils } from '@kbn/data-plugin/public'; +import type { KueryNode } from '@kbn/es-query'; import { setupGetFieldSuggestions } from './field'; import { QuerySuggestionGetFnArgs } from '../query_suggestion_provider'; import { coreMock } from '@kbn/core/public/mocks'; diff --git a/src/plugins/unified_search/public/autocomplete/providers/kql_query_suggestion/field.tsx b/src/plugins/unified_search/public/autocomplete/providers/kql_query_suggestion/field.tsx index 723b7e6896229..37f9c4658b81a 100644 --- a/src/plugins/unified_search/public/autocomplete/providers/kql_query_suggestion/field.tsx +++ b/src/plugins/unified_search/public/autocomplete/providers/kql_query_suggestion/field.tsx @@ -6,6 +6,7 @@ * Side Public License, v 1. */ +// for replace IFieldType => DataViewField need to fix the issue https://github.com/elastic/kibana/issues/131292 import { IFieldType, indexPatterns as indexPatternsUtils } from '@kbn/data-plugin/public'; import { flatten } from 'lodash'; import { sortPrefixFirst } from './sort_prefix_first'; diff --git a/src/plugins/unified_search/public/autocomplete/providers/kql_query_suggestion/operator.test.ts b/src/plugins/unified_search/public/autocomplete/providers/kql_query_suggestion/operator.test.ts index a40678ad4ac16..7e2340fdb043a 100644 --- a/src/plugins/unified_search/public/autocomplete/providers/kql_query_suggestion/operator.test.ts +++ b/src/plugins/unified_search/public/autocomplete/providers/kql_query_suggestion/operator.test.ts @@ -9,7 +9,7 @@ import indexPatternResponse from './__fixtures__/index_pattern_response.json'; import { setupGetOperatorSuggestions } from './operator'; -import { KueryNode } from '@kbn/data-plugin/public'; +import type { KueryNode } from '@kbn/es-query'; import { QuerySuggestionGetFnArgs } from '../query_suggestion_provider'; import { coreMock } from '@kbn/core/public/mocks'; diff --git a/src/plugins/unified_search/public/autocomplete/providers/kql_query_suggestion/value.test.ts b/src/plugins/unified_search/public/autocomplete/providers/kql_query_suggestion/value.test.ts index 3405d26824a26..e852e8e11f347 100644 --- a/src/plugins/unified_search/public/autocomplete/providers/kql_query_suggestion/value.test.ts +++ b/src/plugins/unified_search/public/autocomplete/providers/kql_query_suggestion/value.test.ts @@ -10,7 +10,7 @@ import { setupGetValueSuggestions } from './value'; import indexPatternResponse from './__fixtures__/index_pattern_response.json'; import { coreMock } from '@kbn/core/public/mocks'; -import { KueryNode } from '@kbn/data-plugin/public'; +import type { KueryNode } from '@kbn/es-query'; import { QuerySuggestionGetFnArgs } from '../query_suggestion_provider'; const mockKueryNode = (kueryNode: Partial) => kueryNode as unknown as KueryNode; diff --git a/src/plugins/unified_search/public/autocomplete/providers/kql_query_suggestion/value.ts b/src/plugins/unified_search/public/autocomplete/providers/kql_query_suggestion/value.ts index 06b0fc9639a3c..0bbf416d99a2e 100644 --- a/src/plugins/unified_search/public/autocomplete/providers/kql_query_suggestion/value.ts +++ b/src/plugins/unified_search/public/autocomplete/providers/kql_query_suggestion/value.ts @@ -8,7 +8,9 @@ import { flatten } from 'lodash'; import { CoreSetup } from '@kbn/core/public'; -import { IFieldType, IIndexPattern } from '@kbn/data-plugin/public'; +// for replace IIndexPattern => DataView and IFieldType => DataViewField +// need to fix the issue https://github.com/elastic/kibana/issues/131292 +import type { IIndexPattern, IFieldType } from '@kbn/data-views-plugin/common'; import { escapeQuotes } from './lib/escape_kuery'; import { KqlQuerySuggestionProvider } from './types'; import type { UnifiedSearchPublicPluginStart } from '../../../types'; diff --git a/src/plugins/unified_search/public/autocomplete/providers/query_suggestion_provider.ts b/src/plugins/unified_search/public/autocomplete/providers/query_suggestion_provider.ts index 056fcb716054a..2e0e5c793f82f 100644 --- a/src/plugins/unified_search/public/autocomplete/providers/query_suggestion_provider.ts +++ b/src/plugins/unified_search/public/autocomplete/providers/query_suggestion_provider.ts @@ -7,7 +7,8 @@ */ import { ValueSuggestionsMethod } from '@kbn/data-plugin/common'; -import { IFieldType, IIndexPattern } from '@kbn/data-plugin/common'; +// for replace IIndexPattern => DataView need to fix the issue https://github.com/elastic/kibana/issues/131292 +import type { DataViewField, IIndexPattern } from '@kbn/data-views-plugin/common'; export enum QuerySuggestionTypes { Field = 'field', @@ -47,7 +48,7 @@ export interface QuerySuggestionBasic { /** @public **/ export interface QuerySuggestionField extends QuerySuggestionBasic { type: QuerySuggestionTypes.Field; - field: IFieldType; + field: DataViewField; } /** @public **/ diff --git a/src/plugins/unified_search/public/autocomplete/providers/value_suggestion_provider.ts b/src/plugins/unified_search/public/autocomplete/providers/value_suggestion_provider.ts index 2c25fe0230501..8d08a9de2577d 100644 --- a/src/plugins/unified_search/public/autocomplete/providers/value_suggestion_provider.ts +++ b/src/plugins/unified_search/public/autocomplete/providers/value_suggestion_provider.ts @@ -9,12 +9,10 @@ import { CoreSetup } from '@kbn/core/public'; import dateMath from '@kbn/datemath'; import { memoize } from 'lodash'; -import { - IIndexPattern, - IFieldType, - UI_SETTINGS, - ValueSuggestionsMethod, -} from '@kbn/data-plugin/common'; +import { UI_SETTINGS, ValueSuggestionsMethod } from '@kbn/data-plugin/common'; +// for replace IIndexPattern => DataView and IFieldType => DataViewField +// need to fix the issue https://github.com/elastic/kibana/issues/131292 +import type { IIndexPattern, IFieldType } from '@kbn/data-views-plugin/common'; import type { TimefilterSetup } from '@kbn/data-plugin/public'; import { AutocompleteUsageCollector } from '../collectors'; diff --git a/src/plugins/unified_search/public/filter_bar/filter_editor/index.tsx b/src/plugins/unified_search/public/filter_bar/filter_editor/index.tsx index 490d6480b28c9..6a3d7192ab905 100644 --- a/src/plugins/unified_search/public/filter_bar/filter_editor/index.tsx +++ b/src/plugins/unified_search/public/filter_bar/filter_editor/index.tsx @@ -33,7 +33,7 @@ import { import { get } from 'lodash'; import React, { Component } from 'react'; import { XJsonLang } from '@kbn/monaco'; -import { DataView, IFieldType } from '@kbn/data-views-plugin/common'; +import { DataView, DataViewField } from '@kbn/data-views-plugin/common'; import { getIndexPatternFromFilter } from '@kbn/data-plugin/public'; import { CodeEditor } from '@kbn/kibana-react-plugin/public'; import { GenericComboBox, GenericComboBoxProps } from './generic_combo_box'; @@ -61,7 +61,7 @@ export interface Props { interface State { selectedIndexPattern?: DataView; - selectedField?: IFieldType; + selectedField?: DataViewField; selectedOperator?: Operator; params: any; useCustomLabel: boolean; @@ -447,7 +447,7 @@ class FilterEditorUI extends Component { this.setState({ selectedIndexPattern, selectedField, selectedOperator, params }); }; - private onFieldChange = ([selectedField]: IFieldType[]) => { + private onFieldChange = ([selectedField]: DataViewField[]) => { const selectedOperator = undefined; const params = undefined; this.setState({ selectedField, selectedOperator, params }); @@ -529,7 +529,7 @@ function IndexPatternComboBox(props: GenericComboBoxProps) { return GenericComboBox(props); } -function FieldComboBox(props: GenericComboBoxProps) { +function FieldComboBox(props: GenericComboBoxProps) { return GenericComboBox(props); } diff --git a/src/plugins/unified_search/public/filter_bar/filter_editor/lib/filter_editor_utils.test.ts b/src/plugins/unified_search/public/filter_bar/filter_editor/lib/filter_editor_utils.test.ts index d6c44228eb72f..07ce05d039582 100644 --- a/src/plugins/unified_search/public/filter_bar/filter_editor/lib/filter_editor_utils.test.ts +++ b/src/plugins/unified_search/public/filter_bar/filter_editor/lib/filter_editor_utils.test.ts @@ -14,7 +14,7 @@ import { stubIndexPattern, stubFields, } from '@kbn/data-plugin/common/stubs'; -import { toggleFilterNegated } from '@kbn/data-plugin/common'; +import { toggleFilterNegated } from '@kbn/es-query'; import { getFieldFromFilter, getFilterableFields, 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 f85b9a9e788d8..0863d10fe0c10 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 @@ -10,8 +10,8 @@ import dateMath from '@kbn/datemath'; import { Filter, FieldFilter } from '@kbn/es-query'; import { ES_FIELD_TYPES } from '@kbn/field-types'; import isSemverValid from 'semver/functions/valid'; -import { isFilterable, IFieldType, IpAddress } from '@kbn/data-plugin/common'; -import { DataView } from '@kbn/data-views-plugin/common'; +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'; export function getFieldFromFilter(filter: FieldFilter, indexPattern: DataView) { @@ -28,7 +28,7 @@ export function getFilterableFields(indexPattern: DataView) { return indexPattern.fields.filter(isFilterable); } -export function getOperatorOptions(field: IFieldType) { +export function getOperatorOptions(field: DataViewField) { return FILTER_OPERATORS.filter((operator) => { if (operator.field) return operator.field(field); if (operator.fieldTypes) return operator.fieldTypes.includes(field.type); @@ -36,7 +36,7 @@ export function getOperatorOptions(field: IFieldType) { }); } -export function validateParams(params: any, field: IFieldType) { +export function validateParams(params: any, field: DataViewField) { switch (field.type) { case 'date': const moment = typeof params === 'string' ? dateMath.parse(params) : null; @@ -59,7 +59,7 @@ export function validateParams(params: any, field: IFieldType) { export function isFilterValid( indexPattern?: DataView, - field?: IFieldType, + field?: DataViewField, operator?: Operator, params?: any ) { diff --git a/src/plugins/unified_search/public/filter_bar/filter_editor/lib/filter_label.tsx b/src/plugins/unified_search/public/filter_bar/filter_editor/lib/filter_label.tsx index 601cf68141c49..35c05316465f8 100644 --- a/src/plugins/unified_search/public/filter_bar/filter_editor/lib/filter_label.tsx +++ b/src/plugins/unified_search/public/filter_bar/filter_editor/lib/filter_label.tsx @@ -9,7 +9,7 @@ import React, { Fragment } from 'react'; import { EuiTextColor } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; -import { Filter, FILTERS } from '@kbn/data-plugin/common'; +import { Filter, FILTERS } from '@kbn/es-query'; import { existsOperator, isOneOfOperator } from './filter_operators'; import type { FilterLabelStatus } from '../../filter_item/filter_item'; 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 c1e4d5361e3f8..6143158d69d5c 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 @@ -9,7 +9,7 @@ import { i18n } from '@kbn/i18n'; import { FILTERS } from '@kbn/es-query'; import { ES_FIELD_TYPES } from '@kbn/field-types'; -import { IFieldType } from '@kbn/data-views-plugin/common'; +import { DataViewField } from '@kbn/data-views-plugin/common'; export interface Operator { message: string; @@ -25,7 +25,7 @@ export interface Operator { * A filter predicate for a field, * takes precedence over {@link fieldTypes} */ - field?: (field: IFieldType) => boolean; + field?: (field: DataViewField) => boolean; } export const isOperator = { @@ -68,7 +68,7 @@ export const isBetweenOperator = { }), type: FILTERS.RANGE, negate: false, - field: (field: IFieldType) => { + field: (field: DataViewField) => { if (['number', 'number_range', 'date', 'date_range', 'ip', 'ip_range'].includes(field.type)) return true; @@ -84,7 +84,7 @@ export const isNotBetweenOperator = { }), type: FILTERS.RANGE, negate: true, - field: (field: IFieldType) => { + field: (field: DataViewField) => { if (['number', 'number_range', 'date', 'date_range', 'ip', 'ip_range'].includes(field.type)) return true; diff --git a/src/plugins/unified_search/public/filter_bar/filter_editor/phrase_suggestor.tsx b/src/plugins/unified_search/public/filter_bar/filter_editor/phrase_suggestor.tsx index 50acadea2a990..dc987421e2661 100644 --- a/src/plugins/unified_search/public/filter_bar/filter_editor/phrase_suggestor.tsx +++ b/src/plugins/unified_search/public/filter_bar/filter_editor/phrase_suggestor.tsx @@ -8,8 +8,8 @@ import React from 'react'; import { withKibana, KibanaReactContextValue } from '@kbn/kibana-react-plugin/public'; -import { IFieldType, UI_SETTINGS } from '@kbn/data-plugin/common'; -import { DataView } from '@kbn/data-views-plugin/common'; +import { UI_SETTINGS } from '@kbn/data-plugin/common'; +import { DataView, DataViewField } from '@kbn/data-views-plugin/common'; import { IDataPluginServices } from '@kbn/data-plugin/public'; import { debounce } from 'lodash'; @@ -18,7 +18,7 @@ import { getAutocomplete } from '../../services'; export interface PhraseSuggestorProps { kibana: KibanaReactContextValue; indexPattern: DataView; - field: IFieldType; + field: DataViewField; timeRangeForSuggestionsOverride?: boolean; } diff --git a/src/plugins/unified_search/public/filter_bar/filter_editor/range_value_input.tsx b/src/plugins/unified_search/public/filter_bar/filter_editor/range_value_input.tsx index 3c1046d928981..26a25886ac866 100644 --- a/src/plugins/unified_search/public/filter_bar/filter_editor/range_value_input.tsx +++ b/src/plugins/unified_search/public/filter_bar/filter_editor/range_value_input.tsx @@ -12,7 +12,7 @@ import { InjectedIntl, injectI18n } from '@kbn/i18n-react'; import { get } from 'lodash'; import React from 'react'; import { useKibana } from '@kbn/kibana-react-plugin/public'; -import { IFieldType } from '@kbn/data-plugin/common'; +import type { DataViewField } from '@kbn/data-views-plugin/common'; import { ValueInputType } from './value_input_type'; interface RangeParams { @@ -23,7 +23,7 @@ interface RangeParams { type RangeParamsPartial = Partial; interface Props { - field: IFieldType; + field: DataViewField; value?: RangeParams; onChange: (params: RangeParamsPartial) => void; intl: InjectedIntl; diff --git a/src/plugins/unified_search/public/filter_bar/filter_editor/value_input_type.tsx b/src/plugins/unified_search/public/filter_bar/filter_editor/value_input_type.tsx index 1e50e92cec7bb..a87888ed85c93 100644 --- a/src/plugins/unified_search/public/filter_bar/filter_editor/value_input_type.tsx +++ b/src/plugins/unified_search/public/filter_bar/filter_editor/value_input_type.tsx @@ -10,12 +10,12 @@ import { EuiFieldNumber, EuiFieldText, EuiSelect } from '@elastic/eui'; import { InjectedIntl, injectI18n } from '@kbn/i18n-react'; import { isEmpty } from 'lodash'; import React, { Component } from 'react'; -import { IFieldType } from '@kbn/data-views-plugin/common'; +import type { DataViewField } from '@kbn/data-views-plugin/common'; import { validateParams } from './lib/filter_editor_utils'; interface Props { value?: string | number; - field: IFieldType; + field: DataViewField; onChange: (value: string | number | boolean) => void; onBlur?: (value: string | number | boolean) => void; placeholder: string; diff --git a/src/plugins/unified_search/public/index_pattern_select/create_index_pattern_select.tsx b/src/plugins/unified_search/public/index_pattern_select/create_index_pattern_select.tsx index 04b15aac84778..4dc7dc0f3b57b 100644 --- a/src/plugins/unified_search/public/index_pattern_select/create_index_pattern_select.tsx +++ b/src/plugins/unified_search/public/index_pattern_select/create_index_pattern_select.tsx @@ -8,11 +8,11 @@ import React from 'react'; -import { IndexPatternsContract } from '@kbn/data-plugin/public'; +import type { DataViewsContract } from '@kbn/data-views-plugin/public'; import { IndexPatternSelect, IndexPatternSelectProps } from '.'; // Takes in stateful runtime dependencies and pre-wires them to the component -export function createIndexPatternSelect(indexPatternService: IndexPatternsContract) { +export function createIndexPatternSelect(indexPatternService: DataViewsContract) { return (props: IndexPatternSelectProps) => ( ); diff --git a/src/plugins/unified_search/public/index_pattern_select/index_pattern_select.tsx b/src/plugins/unified_search/public/index_pattern_select/index_pattern_select.tsx index 335787d2ee38a..81534575d10b1 100644 --- a/src/plugins/unified_search/public/index_pattern_select/index_pattern_select.tsx +++ b/src/plugins/unified_search/public/index_pattern_select/index_pattern_select.tsx @@ -11,7 +11,7 @@ import React, { Component } from 'react'; import { Required } from '@kbn/utility-types'; import { EuiComboBox, EuiComboBoxProps } from '@elastic/eui'; -import { IndexPatternsContract } from '@kbn/data-plugin/public'; +import type { DataViewsContract } from '@kbn/data-views-plugin/public'; export type IndexPatternSelectProps = Required< Omit< @@ -26,7 +26,7 @@ export type IndexPatternSelectProps = Required< }; export type IndexPatternSelectInternalProps = IndexPatternSelectProps & { - indexPatternService: IndexPatternsContract; + indexPatternService: DataViewsContract; }; interface IndexPatternSelectState { diff --git a/src/plugins/unified_search/public/search_bar/create_search_bar.tsx b/src/plugins/unified_search/public/search_bar/create_search_bar.tsx index c73aa258863ed..a90098ebcf156 100644 --- a/src/plugins/unified_search/public/search_bar/create_search_bar.tsx +++ b/src/plugins/unified_search/public/search_bar/create_search_bar.tsx @@ -12,7 +12,8 @@ import { CoreStart } from '@kbn/core/public'; import { IStorageWrapper } from '@kbn/kibana-utils-plugin/public'; import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public'; import { QueryStart, SavedQuery, DataPublicPluginStart } from '@kbn/data-plugin/public'; -import { Filter, Query, TimeRange } from '@kbn/data-plugin/common'; +import { Query, TimeRange } from '@kbn/data-plugin/common'; +import type { Filter } from '@kbn/es-query'; import { UsageCollectionSetup } from '@kbn/usage-collection-plugin/public'; import { SearchBar } from '.'; import type { SearchBarOwnProps } from '.'; diff --git a/src/plugins/unified_search/public/search_bar/lib/use_filter_manager.ts b/src/plugins/unified_search/public/search_bar/lib/use_filter_manager.ts index 511e05e043b26..a6d0487cb90c7 100644 --- a/src/plugins/unified_search/public/search_bar/lib/use_filter_manager.ts +++ b/src/plugins/unified_search/public/search_bar/lib/use_filter_manager.ts @@ -8,7 +8,8 @@ import { useState, useEffect } from 'react'; import { Subscription } from 'rxjs'; -import { DataPublicPluginStart, Filter } from '@kbn/data-plugin/public'; +import { DataPublicPluginStart } from '@kbn/data-plugin/public'; +import type { Filter } from '@kbn/es-query'; interface UseFilterManagerProps { filters?: Filter[]; diff --git a/src/plugins/unified_search/public/test_helpers/get_stub_filter.ts b/src/plugins/unified_search/public/test_helpers/get_stub_filter.ts index 2954526d7ede8..10444d1d19055 100644 --- a/src/plugins/unified_search/public/test_helpers/get_stub_filter.ts +++ b/src/plugins/unified_search/public/test_helpers/get_stub_filter.ts @@ -6,7 +6,8 @@ * Side Public License, v 1. */ -import { Filter, FilterStateStore } from '@kbn/data-plugin/public'; +import { FilterStateStore } from '@kbn/data-plugin/public'; +import type { Filter } from '@kbn/es-query'; export function getFilter( store: FilterStateStore, diff --git a/src/plugins/unified_search/public/utils/helpers.test.ts b/src/plugins/unified_search/public/utils/helpers.test.ts index 4659e35602228..803d6c53bb007 100644 --- a/src/plugins/unified_search/public/utils/helpers.test.ts +++ b/src/plugins/unified_search/public/utils/helpers.test.ts @@ -7,11 +7,11 @@ */ import { getFieldValidityAndErrorMessage } from './helpers'; -import { IFieldType } from '@kbn/data-views-plugin/common'; +import { DataViewField } from '@kbn/data-views-plugin/common'; const mockField = { type: 'date', -} as IFieldType; +} as DataViewField; describe('Check field validity and error message', () => { it('should return a message that the entered date is not incorrect', () => { diff --git a/src/plugins/unified_search/public/utils/helpers.ts b/src/plugins/unified_search/public/utils/helpers.ts index 1c056636c67b8..6f0a605fa0e14 100644 --- a/src/plugins/unified_search/public/utils/helpers.ts +++ b/src/plugins/unified_search/public/utils/helpers.ts @@ -6,14 +6,14 @@ * Side Public License, v 1. */ -import type { IFieldType } from '@kbn/data-views-plugin/common'; +import type { DataViewField } from '@kbn/data-views-plugin/common'; import { i18n } from '@kbn/i18n'; import { KBN_FIELD_TYPES } from '@kbn/data-plugin/public'; import { isEmpty } from 'lodash'; import { validateParams } from '../filter_bar/filter_editor/lib/filter_editor_utils'; export const getFieldValidityAndErrorMessage = ( - field: IFieldType, + field: DataViewField, value?: string | undefined ): { isInvalid: boolean; errorMessage?: string } => { const type = field.type; diff --git a/src/plugins/unified_search/server/autocomplete/terms_agg.test.ts b/src/plugins/unified_search/server/autocomplete/terms_agg.test.ts index f27fa9d594f97..03ceffc73b34f 100644 --- a/src/plugins/unified_search/server/autocomplete/terms_agg.test.ts +++ b/src/plugins/unified_search/server/autocomplete/terms_agg.test.ts @@ -10,6 +10,7 @@ import { coreMock } from '@kbn/core/server/mocks'; import { ElasticsearchClient, SavedObjectsClientContract } from '@kbn/core/server'; import { ConfigSchema } from '../../config'; import type { DeeplyMockedKeys } from '@kbn/utility-types/jest'; +import type { DataViewField } from '@kbn/data-views-plugin/common'; import { termsAggSuggestions } from './terms_agg'; import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import { duration } from 'moment'; @@ -22,6 +23,8 @@ const configMock = { }, } as unknown as ConfigSchema; +const dataViewFieldMock = { name: 'field_name', type: 'string' } as DataViewField; + // @ts-expect-error not full interface const mockResponse = { aggregations: { @@ -50,7 +53,7 @@ describe('terms agg suggestions', () => { 'fieldName', 'query', [], - { name: 'field_name', type: 'string' } + dataViewFieldMock ); const [[args]] = esClientMock.search.mock.calls; diff --git a/src/plugins/unified_search/server/autocomplete/terms_agg.ts b/src/plugins/unified_search/server/autocomplete/terms_agg.ts index ffdaca8caad4b..c7d303e526ca8 100644 --- a/src/plugins/unified_search/server/autocomplete/terms_agg.ts +++ b/src/plugins/unified_search/server/autocomplete/terms_agg.ts @@ -9,7 +9,8 @@ import { get, map } from 'lodash'; import { ElasticsearchClient, SavedObjectsClientContract } from '@kbn/core/server'; import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; -import { IFieldType, getFieldSubtypeNested } from '@kbn/data-plugin/common'; +import { getFieldSubtypeNested } from '@kbn/data-plugin/common'; +import type { FieldSpec } from '@kbn/data-views-plugin/common'; import { ConfigSchema } from '../../config'; import { findIndexPatternById, getFieldByName } from '../data_views'; @@ -21,7 +22,7 @@ export async function termsAggSuggestions( fieldName: string, query: string, filters?: estypes.QueryDslQueryContainer[], - field?: IFieldType, + field?: FieldSpec, abortSignal?: AbortSignal ) { const autocompleteSearchOptions = { @@ -54,11 +55,11 @@ export async function termsAggSuggestions( async function getBody( // eslint-disable-next-line @typescript-eslint/naming-convention { timeout, terminate_after }: Record, - field: IFieldType | string, + field: FieldSpec | string, query: string, filters: estypes.QueryDslQueryContainer[] = [] ) { - const isFieldObject = (f: any): f is IFieldType => Boolean(f && f.name); + const isFieldObject = (f: any): f is FieldSpec => Boolean(f && f.name); // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-regexp-query.html#_standard_operators const getEscapedQuery = (q: string = '') => diff --git a/src/plugins/unified_search/server/autocomplete/terms_enum.test.ts b/src/plugins/unified_search/server/autocomplete/terms_enum.test.ts index bc2a4e010a765..f0209e66ee58d 100644 --- a/src/plugins/unified_search/server/autocomplete/terms_enum.test.ts +++ b/src/plugins/unified_search/server/autocomplete/terms_enum.test.ts @@ -12,12 +12,19 @@ import { ElasticsearchClient, SavedObjectsClientContract } from '@kbn/core/serve import { ConfigSchema } from '../../config'; import type { DeeplyMockedKeys } from '@kbn/utility-types/jest'; import { TermsEnumResponse } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type { DataViewField } from '@kbn/data-views-plugin/common'; let savedObjectsClientMock: jest.Mocked; let esClientMock: DeeplyMockedKeys; const configMock = { autocomplete: { valueSuggestions: { tiers: ['data_hot', 'data_warm', 'data_content'] } }, } as ConfigSchema; +const dataViewFieldMock = { + name: 'field_name', + type: 'string', + searchable: true, + aggregatable: true, +} as DataViewField; const mockResponse = { terms: ['whoa', 'amazing'] }; jest.mock('../data_views'); @@ -39,7 +46,7 @@ describe('_terms_enum suggestions', () => { 'fieldName', 'query', [], - { name: 'field_name', type: 'string', searchable: true, aggregatable: true } + dataViewFieldMock ); const [[args]] = esClientMock.termsEnum.mock.calls; diff --git a/src/plugins/unified_search/server/autocomplete/terms_enum.ts b/src/plugins/unified_search/server/autocomplete/terms_enum.ts index 924b5b3a1671e..3e8207eb644e5 100644 --- a/src/plugins/unified_search/server/autocomplete/terms_enum.ts +++ b/src/plugins/unified_search/server/autocomplete/terms_enum.ts @@ -8,7 +8,7 @@ import { ElasticsearchClient, SavedObjectsClientContract } from '@kbn/core/server'; import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; -import { IFieldType } from '@kbn/data-plugin/common'; +import type { FieldSpec } from '@kbn/data-views-plugin/common'; import { findIndexPatternById, getFieldByName } from '../data_views'; import { ConfigSchema } from '../../config'; @@ -20,7 +20,7 @@ export async function termsEnumSuggestions( fieldName: string, query: string, filters?: estypes.QueryDslQueryContainer[], - field?: IFieldType, + field?: FieldSpec, abortSignal?: AbortSignal ) { const { tiers } = config.autocomplete.valueSuggestions;