Skip to content

Commit

Permalink
[Unified search] Use the DataViews service (elastic#130008)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nlatipov authored May 23, 2022
1 parent a3646eb commit e0944d1
Show file tree
Hide file tree
Showing 30 changed files with 76 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>) => kueryNode as unknown as KueryNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -47,7 +48,7 @@ export interface QuerySuggestionBasic {
/** @public **/
export interface QuerySuggestionField extends QuerySuggestionBasic {
type: QuerySuggestionTypes.Field;
field: IFieldType;
field: DataViewField;
}

/** @public **/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -61,7 +61,7 @@ export interface Props {

interface State {
selectedIndexPattern?: DataView;
selectedField?: IFieldType;
selectedField?: DataViewField;
selectedOperator?: Operator;
params: any;
useCustomLabel: boolean;
Expand Down Expand Up @@ -447,7 +447,7 @@ class FilterEditorUI extends Component<Props, State> {
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 });
Expand Down Expand Up @@ -529,7 +529,7 @@ function IndexPatternComboBox(props: GenericComboBoxProps<DataView>) {
return GenericComboBox(props);
}

function FieldComboBox(props: GenericComboBoxProps<IFieldType>) {
function FieldComboBox(props: GenericComboBoxProps<DataViewField>) {
return GenericComboBox(props);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -28,15 +28,15 @@ 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);
return true;
});
}

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;
Expand All @@ -59,7 +59,7 @@ export function validateParams(params: any, field: IFieldType) {

export function isFilterValid(
indexPattern?: DataView,
field?: IFieldType,
field?: DataViewField,
operator?: Operator,
params?: any
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 = {
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -18,7 +18,7 @@ import { getAutocomplete } from '../../services';
export interface PhraseSuggestorProps {
kibana: KibanaReactContextValue<IDataPluginServices>;
indexPattern: DataView;
field: IFieldType;
field: DataViewField;
timeRangeForSuggestionsOverride?: boolean;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -23,7 +23,7 @@ interface RangeParams {
type RangeParamsPartial = Partial<RangeParams>;

interface Props {
field: IFieldType;
field: DataViewField;
value?: RangeParams;
onChange: (params: RangeParamsPartial) => void;
intl: InjectedIntl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => (
<IndexPatternSelect {...props} indexPatternService={indexPatternService} />
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand All @@ -26,7 +26,7 @@ export type IndexPatternSelectProps = Required<
};

export type IndexPatternSelectInternalProps = IndexPatternSelectProps & {
indexPatternService: IndexPatternsContract;
indexPatternService: DataViewsContract;
};

interface IndexPatternSelectState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 '.';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/unified_search/public/utils/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/unified_search/public/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit e0944d1

Please sign in to comment.