From 13e363a65bfa918cf5991dc2b3eb764ddaca6f82 Mon Sep 17 00:00:00 2001 From: nathan Date: Thu, 26 Aug 2021 08:20:40 -0600 Subject: [PATCH] [Maps] replace IFieldType with IndexPatternField --- x-pack/plugins/maps/common/constants.ts | 2 +- .../common/elasticsearch_util/es_agg_utils.ts | 6 ++--- .../public/classes/fields/es_doc_field.ts | 4 +-- .../layer_template.tsx | 8 +++--- .../update_source_editor.tsx | 4 +-- .../es_search_source/es_search_source.tsx | 6 ++--- .../top_hits/create_source_editor.tsx | 8 +++--- .../top_hits/top_hits_form.tsx | 6 ++--- .../top_hits/update_source_editor.tsx | 6 ++--- .../util/get_docvalue_source_fields.test.ts | 6 ++--- .../util/get_docvalue_source_fields.ts | 4 +-- .../classes/sources/es_source/es_source.ts | 4 +-- .../tooltips/es_tooltip_property.test.ts | 8 +++--- .../public/components/geo_field_select.tsx | 4 +-- .../metrics_editor/metric_editor.tsx | 6 ++--- .../metrics_editor/metrics_editor.tsx | 4 +-- .../public/components/single_field_select.tsx | 26 +++++++++---------- .../join_editor/resources/join.tsx | 4 +-- .../join_editor/resources/join_expression.tsx | 4 +-- .../resources/metrics_expression.tsx | 4 +-- .../maps/public/index_pattern_util.test.ts | 21 ++++++++------- .../plugins/maps/public/index_pattern_util.ts | 18 ++++++------- .../server/maps_telemetry/maps_telemetry.ts | 5 ++-- 23 files changed, 84 insertions(+), 84 deletions(-) diff --git a/x-pack/plugins/maps/common/constants.ts b/x-pack/plugins/maps/common/constants.ts index 1a3065cb4518d..73308be2348e2 100644 --- a/x-pack/plugins/maps/common/constants.ts +++ b/x-pack/plugins/maps/common/constants.ts @@ -131,7 +131,7 @@ export enum ES_GEO_FIELD_TYPE { GEO_SHAPE = 'geo_shape', } -// Using strings instead of ES_GEO_FIELD_TYPE enum to avoid typeing errors where IFieldType.type is compared to value +// Using strings instead of ES_GEO_FIELD_TYPE enum to avoid typeing errors where IndexPatternField.type is compared to value export const ES_GEO_FIELD_TYPES = ['geo_point', 'geo_shape']; export enum ES_SPATIAL_RELATIONS { diff --git a/x-pack/plugins/maps/common/elasticsearch_util/es_agg_utils.ts b/x-pack/plugins/maps/common/elasticsearch_util/es_agg_utils.ts index cae5f6ee9f41a..01e20a58c0b2a 100644 --- a/x-pack/plugins/maps/common/elasticsearch_util/es_agg_utils.ts +++ b/x-pack/plugins/maps/common/elasticsearch_util/es_agg_utils.ts @@ -7,13 +7,13 @@ import { i18n } from '@kbn/i18n'; import _ from 'lodash'; -import { IndexPattern, IFieldType } from '../../../../../src/plugins/data/common'; +import { IndexPattern, IndexPatternField } from '../../../../../src/plugins/data/common'; import { AGG_TYPE, JOIN_FIELD_NAME_PREFIX, TOP_TERM_PERCENTAGE_SUFFIX } from '../constants'; export type BucketProperties = Record; export type PropertiesMap = Map; -export function getField(indexPattern: IndexPattern, fieldName: string): IFieldType { +export function getField(indexPattern: IndexPattern, fieldName: string): IndexPatternField { const field = indexPattern.fields.getByName(fieldName); if (!field) { throw new Error( @@ -26,7 +26,7 @@ export function getField(indexPattern: IndexPattern, fieldName: string): IFieldT return field; } -export function addFieldToDSL(dsl: object, field: IFieldType) { +export function addFieldToDSL(dsl: object, field: IndexPatternField) { return !field.scripted ? { ...dsl, field: field.name } : { diff --git a/x-pack/plugins/maps/public/classes/fields/es_doc_field.ts b/x-pack/plugins/maps/public/classes/fields/es_doc_field.ts index abdcf65a4ab1d..19624fa3eb04f 100644 --- a/x-pack/plugins/maps/public/classes/fields/es_doc_field.ts +++ b/x-pack/plugins/maps/public/classes/fields/es_doc_field.ts @@ -9,7 +9,7 @@ import { FIELD_ORIGIN } from '../../../common/constants'; import { ESTooltipProperty } from '../tooltips/es_tooltip_property'; import { ITooltipProperty, TooltipProperty } from '../tooltips/tooltip_property'; import { indexPatterns } from '../../../../../../src/plugins/data/public'; -import { IFieldType } from '../../../../../../src/plugins/data/public'; +import { IndexPatternField } from '../../../../../../src/plugins/data/public'; import { IField, AbstractField } from './field'; import { IESSource } from '../sources/es_source'; import { IVectorSource } from '../sources/vector_source'; @@ -42,7 +42,7 @@ export class ESDocField extends AbstractField implements IField { return this._source; } - async _getIndexPatternField(): Promise { + async _getIndexPatternField(): Promise { const indexPattern = await this._source.getIndexPattern(); const indexPatternField = indexPattern.fields.getByName(this.getName()); return indexPatternField && indexPatterns.isNestedField(indexPatternField) diff --git a/x-pack/plugins/maps/public/classes/layers/choropleth_layer_wizard/layer_template.tsx b/x-pack/plugins/maps/public/classes/layers/choropleth_layer_wizard/layer_template.tsx index 82a741e7ccdab..5bd2b68e61bc4 100644 --- a/x-pack/plugins/maps/public/classes/layers/choropleth_layer_wizard/layer_template.tsx +++ b/x-pack/plugins/maps/public/classes/layers/choropleth_layer_wizard/layer_template.tsx @@ -18,7 +18,7 @@ import { EuiSpacer, EuiTitle, } from '@elastic/eui'; -import { IFieldType, IndexPattern } from 'src/plugins/data/public'; +import { IndexPatternField, IndexPattern } from 'src/plugins/data/public'; import { RenderWizardArguments } from '../layer_wizard_registry'; import { EMSFileSelect } from '../../../components/ems_file_select'; import { GeoIndexPatternSelect } from '../../../components/geo_index_pattern_select'; @@ -56,14 +56,14 @@ interface State { leftEmsFileId: string | null; leftEmsFields: Array>; leftIndexPattern: IndexPattern | null; - leftGeoFields: IFieldType[]; - leftJoinFields: IFieldType[]; + leftGeoFields: IndexPatternField[]; + leftJoinFields: IndexPatternField[]; leftGeoField: string | null; leftEmsJoinField: string | null; leftElasticsearchJoinField: string | null; rightIndexPatternId: string; rightIndexPatternTitle: string | null; - rightTermsFields: IFieldType[]; + rightTermsFields: IndexPatternField[]; rightJoinField: string | null; } diff --git a/x-pack/plugins/maps/public/classes/sources/es_geo_line_source/update_source_editor.tsx b/x-pack/plugins/maps/public/classes/sources/es_geo_line_source/update_source_editor.tsx index 2688ef1d29686..d1d87ef3be7bf 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_geo_line_source/update_source_editor.tsx +++ b/x-pack/plugins/maps/public/classes/sources/es_geo_line_source/update_source_editor.tsx @@ -10,7 +10,7 @@ import React, { Fragment, Component } from 'react'; import { FormattedMessage } from '@kbn/i18n/react'; import { EuiPanel, EuiSpacer, EuiTitle } from '@elastic/eui'; import { - IFieldType, + IndexPatternField, IndexPattern, indexPatterns, } from '../../../../../../../src/plugins/data/public'; @@ -30,7 +30,7 @@ interface Props { interface State { indexPattern: IndexPattern | null; - fields: IFieldType[]; + fields: IndexPatternField[]; } export class UpdateSourceEditor extends Component { diff --git a/x-pack/plugins/maps/public/classes/sources/es_search_source/es_search_source.tsx b/x-pack/plugins/maps/public/classes/sources/es_search_source/es_search_source.tsx index 464ba024663ec..93362a1721ce5 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_search_source/es_search_source.tsx +++ b/x-pack/plugins/maps/public/classes/sources/es_search_source/es_search_source.tsx @@ -9,7 +9,7 @@ import _ from 'lodash'; import React, { ReactElement } from 'react'; import rison from 'rison-node'; import { i18n } from '@kbn/i18n'; -import type { Filter, IFieldType, IndexPattern } from 'src/plugins/data/public'; +import type { Filter, IndexPatternField, IndexPattern } from 'src/plugins/data/public'; import { GeoJsonProperties, Geometry, Position } from 'geojson'; import { esFilters } from '../../../../../../../src/plugins/data/public'; import { AbstractESSource } from '../es_source'; @@ -183,7 +183,7 @@ export class ESSearchSource extends AbstractESSource implements ITiledSingleLaye async getFields(): Promise { try { const indexPattern = await this.getIndexPattern(); - const fields: IFieldType[] = indexPattern.fields.filter((field) => { + const fields: IndexPatternField[] = indexPattern.fields.filter((field) => { // Ensure fielddata is enabled for field. // Search does not request _source return field.aggregatable; @@ -300,7 +300,7 @@ export class ESSearchSource extends AbstractESSource implements ITiledSingleLaye }; } - const topHitsSplitField: IFieldType = getField(indexPattern, topHitsSplitFieldName); + const topHitsSplitField: IndexPatternField = getField(indexPattern, topHitsSplitFieldName); const cardinalityAgg = { precision_threshold: 1 }; const termsAgg = { size: DEFAULT_MAX_BUCKETS_LIMIT, diff --git a/x-pack/plugins/maps/public/classes/sources/es_search_source/top_hits/create_source_editor.tsx b/x-pack/plugins/maps/public/classes/sources/es_search_source/top_hits/create_source_editor.tsx index 41c9076c11436..f1ea1c17e83ec 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_search_source/top_hits/create_source_editor.tsx +++ b/x-pack/plugins/maps/public/classes/sources/es_search_source/top_hits/create_source_editor.tsx @@ -15,7 +15,7 @@ import { getGeoFields, getTermsFields, getSortFields } from '../../../../index_p import { ESSearchSourceDescriptor } from '../../../../../common/descriptor_types'; import { IndexPattern, - IFieldType, + IndexPatternField, SortDirection, } from '../../../../../../../../src/plugins/data/common'; import { TopHitsForm } from './top_hits_form'; @@ -27,12 +27,12 @@ interface Props { interface State { indexPattern: IndexPattern | null; - geoFields: IFieldType[]; + geoFields: IndexPatternField[]; geoFieldName: string | null; sortField: string | null; - sortFields: IFieldType[]; + sortFields: IndexPatternField[]; sortOrder: SortDirection; - termFields: IFieldType[]; + termFields: IndexPatternField[]; topHitsSplitField: string | null; topHitsSize: number; } diff --git a/x-pack/plugins/maps/public/classes/sources/es_search_source/top_hits/top_hits_form.tsx b/x-pack/plugins/maps/public/classes/sources/es_search_source/top_hits/top_hits_form.tsx index 79d6039076f81..edafec979cb93 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_search_source/top_hits/top_hits_form.tsx +++ b/x-pack/plugins/maps/public/classes/sources/es_search_source/top_hits/top_hits_form.tsx @@ -15,16 +15,16 @@ import { ValidatedRange } from '../../../../components/validated_range'; import { DEFAULT_MAX_INNER_RESULT_WINDOW } from '../../../../../common/constants'; import { loadIndexSettings } from '../util/load_index_settings'; import { OnSourceChangeArgs } from '../../source'; -import { IFieldType, SortDirection } from '../../../../../../../../src/plugins/data/public'; +import { IndexPatternField, SortDirection } from '../../../../../../../../src/plugins/data/public'; interface Props { indexPatternId: string; isColumnCompressed?: boolean; onChange: (args: OnSourceChangeArgs) => void; sortField: string; - sortFields: IFieldType[]; + sortFields: IndexPatternField[]; sortOrder: SortDirection; - termFields: IFieldType[]; + termFields: IndexPatternField[]; topHitsSplitField: string | null; topHitsSize: number; } diff --git a/x-pack/plugins/maps/public/classes/sources/es_search_source/top_hits/update_source_editor.tsx b/x-pack/plugins/maps/public/classes/sources/es_search_source/top_hits/update_source_editor.tsx index 6ca38f3be22f4..931830f590d37 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_search_source/top_hits/update_source_editor.tsx +++ b/x-pack/plugins/maps/public/classes/sources/es_search_source/top_hits/update_source_editor.tsx @@ -14,7 +14,7 @@ import { TooltipSelector } from '../../../../components/tooltip_selector'; import { getIndexPatternService } from '../../../../kibana_services'; import { getTermsFields, getSortFields, getSourceFields } from '../../../../index_pattern_util'; -import { SortDirection, IFieldType } from '../../../../../../../../src/plugins/data/public'; +import { SortDirection, IndexPatternField } from '../../../../../../../../src/plugins/data/public'; import { ESDocField } from '../../../fields/es_doc_field'; import { OnSourceChangeArgs } from '../../source'; import { TopHitsForm } from './top_hits_form'; @@ -36,8 +36,8 @@ interface Props { interface State { loadError?: string; sourceFields: IField[]; - termFields: IFieldType[]; - sortFields: IFieldType[]; + termFields: IndexPatternField[]; + sortFields: IndexPatternField[]; } export class TopHitsUpdateSourceEditor extends Component { diff --git a/x-pack/plugins/maps/public/classes/sources/es_search_source/util/get_docvalue_source_fields.test.ts b/x-pack/plugins/maps/public/classes/sources/es_search_source/util/get_docvalue_source_fields.test.ts index 0a24c140d735f..798648cafd794 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_search_source/util/get_docvalue_source_fields.test.ts +++ b/x-pack/plugins/maps/public/classes/sources/es_search_source/util/get_docvalue_source_fields.test.ts @@ -7,9 +7,9 @@ import { getDocValueAndSourceFields } from './get_docvalue_source_fields'; import { IndexPattern } from '../../../../../../../../src/plugins/data/common/index_patterns/index_patterns'; -import { IFieldType } from '../../../../../../../../src/plugins/data/common/index_patterns/fields'; +import { IndexPatternField } from '../../../../../../../../src/plugins/data/common/index_patterns/fields'; -function createMockIndexPattern(fields: IFieldType[]): IndexPattern { +function createMockIndexPattern(fields: IndexPatternField[]): IndexPattern { const indexPattern = { get fields() { return { @@ -29,7 +29,7 @@ describe('getDocValueAndSourceFields', () => { createMockIndexPattern([ { name: 'foobar', - // @ts-expect-error runtimeField not added yet to IFieldType. API tbd + // @ts-expect-error runtimeField not added yet to IndexPatternField. API tbd runtimeField: {}, }, ]), diff --git a/x-pack/plugins/maps/public/classes/sources/es_search_source/util/get_docvalue_source_fields.ts b/x-pack/plugins/maps/public/classes/sources/es_search_source/util/get_docvalue_source_fields.ts index 78823f4631cac..949dc990c44fe 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_search_source/util/get_docvalue_source_fields.ts +++ b/x-pack/plugins/maps/public/classes/sources/es_search_source/util/get_docvalue_source_fields.ts @@ -34,9 +34,7 @@ export function getDocValueAndSourceFields( lang: field.lang || '', }, }; - } - // @ts-expect-error runtimeField has not been added to public API yet. exact shape of type TBD. - else if (field.readFromDocValues || field.runtimeField) { + } else if (field.readFromDocValues || field.runtimeField) { const docValueField = field.type === 'date' ? { diff --git a/x-pack/plugins/maps/public/classes/sources/es_source/es_source.ts b/x-pack/plugins/maps/public/classes/sources/es_source/es_source.ts index 23bcd9baed8c0..ce8991bb63ce6 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_source/es_source.ts +++ b/x-pack/plugins/maps/public/classes/sources/es_source/es_source.ts @@ -7,7 +7,7 @@ import { i18n } from '@kbn/i18n'; import uuid from 'uuid/v4'; -import { Filter, IFieldType, IndexPattern, ISearchSource } from 'src/plugins/data/public'; +import { Filter, IndexPatternField, IndexPattern, ISearchSource } from 'src/plugins/data/public'; import { AbstractVectorSource, BoundsFilters } from '../vector_source'; import { getAutocompleteService, @@ -364,7 +364,7 @@ export class AbstractESSource extends AbstractVectorSource implements IESSource } } - async _getGeoField(): Promise { + async _getGeoField(): Promise { const indexPattern = await this.getIndexPattern(); const geoField = indexPattern.fields.getByName(this.getGeoFieldName()); if (!geoField) { 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 fbb416e7a7619..b5bf7e31eef15 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 @@ -5,7 +5,7 @@ * 2.0. */ -import { IFieldType, IndexPattern } from '../../../../../../src/plugins/data/public'; +import { IndexPatternField, IndexPattern } from '../../../../../../src/plugins/data/public'; import { ESTooltipProperty } from './es_tooltip_property'; import { TooltipProperty } from './tooltip_property'; import { AbstractField } from '../fields/field'; @@ -25,7 +25,7 @@ const indexPatternField = { searchable: true, aggregatable: true, readFromDocValues: false, -} as IFieldType; +} as IndexPatternField; const featurePropertyField = new MockField({ fieldName: 'machine.os', @@ -41,7 +41,7 @@ const nonFilterableIndexPatternField = { searchable: true, aggregatable: true, readFromDocValues: false, -} as IFieldType; +} as IndexPatternField; const nonFilterableFeaturePropertyField = new MockField({ fieldName: 'location', @@ -51,7 +51,7 @@ const nonFilterableFeaturePropertyField = new MockField({ const indexPattern = { id: 'indexPatternId', fields: { - getByName: (name: string): IFieldType | null => { + getByName: (name: string): IndexPatternField | null => { if (name === 'machine.os') { return indexPatternField; } diff --git a/x-pack/plugins/maps/public/components/geo_field_select.tsx b/x-pack/plugins/maps/public/components/geo_field_select.tsx index 0b04ec7146611..d611625bd92e7 100644 --- a/x-pack/plugins/maps/public/components/geo_field_select.tsx +++ b/x-pack/plugins/maps/public/components/geo_field_select.tsx @@ -9,11 +9,11 @@ import React from 'react'; import { i18n } from '@kbn/i18n'; import { EuiFormRow } from '@elastic/eui'; import { SingleFieldSelect } from './single_field_select'; -import { IFieldType } from '../../../../../src/plugins/data/common'; +import { IndexPatternField } from '../../../../../src/plugins/data/common'; interface Props { value: string; - geoFields: IFieldType[]; + geoFields: IndexPatternField[]; onChange: (geoFieldName?: string) => void; } diff --git a/x-pack/plugins/maps/public/components/metrics_editor/metric_editor.tsx b/x-pack/plugins/maps/public/components/metrics_editor/metric_editor.tsx index b72a8d01d4a93..b8722a40fe52c 100644 --- a/x-pack/plugins/maps/public/components/metrics_editor/metric_editor.tsx +++ b/x-pack/plugins/maps/public/components/metrics_editor/metric_editor.tsx @@ -16,10 +16,10 @@ import { SingleFieldSelect } from '../single_field_select'; import { AggDescriptor } from '../../../common/descriptor_types'; import { AGG_TYPE, DEFAULT_PERCENTILE } from '../../../common/constants'; import { getTermsFields } from '../../index_pattern_util'; -import { IFieldType } from '../../../../../../src/plugins/data/public'; +import { IndexPatternField } from '../../../../../../src/plugins/data/public'; import { ValidatedNumberInput } from '../validated_number_input'; -function filterFieldsForAgg(fields: IFieldType[], aggType: AGG_TYPE) { +function filterFieldsForAgg(fields: IndexPatternField[], aggType: AGG_TYPE) { if (!fields) { return []; } @@ -40,7 +40,7 @@ function filterFieldsForAgg(fields: IFieldType[], aggType: AGG_TYPE) { interface Props { metric: AggDescriptor; - fields: IFieldType[]; + fields: IndexPatternField[]; onChange: (metric: AggDescriptor) => void; onRemove: () => void; metricsFilter?: (metricOption: EuiComboBoxOptionOption) => boolean; diff --git a/x-pack/plugins/maps/public/components/metrics_editor/metrics_editor.tsx b/x-pack/plugins/maps/public/components/metrics_editor/metrics_editor.tsx index 2124345e7e03c..e407468c485be 100644 --- a/x-pack/plugins/maps/public/components/metrics_editor/metrics_editor.tsx +++ b/x-pack/plugins/maps/public/components/metrics_editor/metrics_editor.tsx @@ -10,7 +10,7 @@ import { FormattedMessage } from '@kbn/i18n/react'; import { EuiButtonEmpty, EuiComboBoxOptionOption, EuiSpacer, EuiTextAlign } from '@elastic/eui'; import { MetricEditor } from './metric_editor'; import { DEFAULT_METRIC } from '../../classes/sources/es_agg_source'; -import { IFieldType } from '../../../../../../src/plugins/data/public'; +import { IndexPatternField } from '../../../../../../src/plugins/data/public'; import { AggDescriptor, FieldedAggDescriptor } from '../../../common/descriptor_types'; import { AGG_TYPE } from '../../../common/constants'; @@ -23,7 +23,7 @@ export function isMetricValid(aggDescriptor: AggDescriptor) { interface Props { allowMultipleMetrics: boolean; metrics: AggDescriptor[]; - fields: IFieldType[]; + fields: IndexPatternField[]; onChange: (metrics: AggDescriptor[]) => void; metricsFilter?: (metricOption: EuiComboBoxOptionOption) => boolean; } diff --git a/x-pack/plugins/maps/public/components/single_field_select.tsx b/x-pack/plugins/maps/public/components/single_field_select.tsx index 6727de35b1be7..67594db11eb37 100644 --- a/x-pack/plugins/maps/public/components/single_field_select.tsx +++ b/x-pack/plugins/maps/public/components/single_field_select.tsx @@ -17,20 +17,20 @@ import { EuiFlexItem, EuiToolTip, } from '@elastic/eui'; -import { IFieldType } from 'src/plugins/data/public'; +import { IndexPatternField } from 'src/plugins/data/public'; import { FieldIcon } from '../../../../../src/plugins/kibana_react/public'; function fieldsToOptions( - fields?: IFieldType[], - isFieldDisabled?: (field: IFieldType) => boolean -): Array> { + fields?: IndexPatternField[], + isFieldDisabled?: (field: IndexPatternField) => boolean +): Array> { if (!fields) { return []; } return fields .map((field) => { - const option: EuiComboBoxOptionOption = { + const option: EuiComboBoxOptionOption = { value: field, label: field.displayName ? field.displayName : field.name, }; @@ -45,14 +45,14 @@ function fieldsToOptions( } type Props = Omit< - EuiComboBoxProps, + EuiComboBoxProps, 'isDisabled' | 'onChange' | 'options' | 'renderOption' | 'selectedOptions' | 'singleSelection' > & { - fields?: IFieldType[]; + fields?: IndexPatternField[]; onChange: (fieldName?: string) => void; value: string | null; // index pattern field name - isFieldDisabled?: (field: IFieldType) => boolean; - getFieldDisabledReason?: (field: IFieldType) => string | null; + isFieldDisabled?: (field: IndexPatternField) => boolean; + getFieldDisabledReason?: (field: IndexPatternField) => string | null; }; export function SingleFieldSelect({ @@ -64,7 +64,7 @@ export function SingleFieldSelect({ ...rest }: Props) { function renderOption( - option: EuiComboBoxOptionOption, + option: EuiComboBoxOptionOption, searchValue: string, contentClassName: string ) { @@ -91,13 +91,13 @@ export function SingleFieldSelect({ ); } - const onSelection = (selectedOptions: Array>) => { + const onSelection = (selectedOptions: Array>) => { onChange(_.get(selectedOptions, '0.value.name')); }; - const selectedOptions: Array> = []; + const selectedOptions: Array> = []; if (value && fields) { - const selectedField = fields.find((field: IFieldType) => { + const selectedField = fields.find((field: IndexPatternField) => { return field.name === value; }); if (selectedField) { diff --git a/x-pack/plugins/maps/public/connected_components/edit_layer_panel/join_editor/resources/join.tsx b/x-pack/plugins/maps/public/connected_components/edit_layer_panel/join_editor/resources/join.tsx index 6962977627b98..c636047e2be37 100644 --- a/x-pack/plugins/maps/public/connected_components/edit_layer_panel/join_editor/resources/join.tsx +++ b/x-pack/plugins/maps/public/connected_components/edit_layer_panel/join_editor/resources/join.tsx @@ -9,7 +9,7 @@ import _ from 'lodash'; import React, { Component } from 'react'; import { EuiFlexItem, EuiFlexGroup, EuiButtonIcon } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; -import type { IFieldType, IndexPattern, Query } from 'src/plugins/data/public'; +import type { IndexPatternField, IndexPattern, Query } from 'src/plugins/data/public'; import { JoinExpression } from './join_expression'; import { MetricsExpression } from './metrics_expression'; import { WhereExpression } from './where_expression'; @@ -38,7 +38,7 @@ interface Props { } interface State { - rightFields: IFieldType[]; + rightFields: IndexPatternField[]; indexPattern?: IndexPattern; loadError?: string; } diff --git a/x-pack/plugins/maps/public/connected_components/edit_layer_panel/join_editor/resources/join_expression.tsx b/x-pack/plugins/maps/public/connected_components/edit_layer_panel/join_editor/resources/join_expression.tsx index f2073a9f6e650..19a47736b1958 100644 --- a/x-pack/plugins/maps/public/connected_components/edit_layer_panel/join_editor/resources/join_expression.tsx +++ b/x-pack/plugins/maps/public/connected_components/edit_layer_panel/join_editor/resources/join_expression.tsx @@ -18,7 +18,7 @@ import { } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; -import { IFieldType } from 'src/plugins/data/public'; +import { IndexPatternField } from 'src/plugins/data/public'; import { FormattedMessage } from '@kbn/i18n/react'; import { DEFAULT_MAX_BUCKETS_LIMIT } from '../../../../../common/constants'; import { SingleFieldSelect } from '../../../../components/single_field_select'; @@ -54,7 +54,7 @@ interface Props { // Right field props rightValue: string; rightSize?: number; - rightFields: IFieldType[]; + rightFields: IndexPatternField[]; onRightFieldChange: (term?: string) => void; onRightSizeChange: (size: number) => void; } diff --git a/x-pack/plugins/maps/public/connected_components/edit_layer_panel/join_editor/resources/metrics_expression.tsx b/x-pack/plugins/maps/public/connected_components/edit_layer_panel/join_editor/resources/metrics_expression.tsx index 899430f3c2f2d..4c2e96498ee20 100644 --- a/x-pack/plugins/maps/public/connected_components/edit_layer_panel/join_editor/resources/metrics_expression.tsx +++ b/x-pack/plugins/maps/public/connected_components/edit_layer_panel/join_editor/resources/metrics_expression.tsx @@ -15,7 +15,7 @@ import { EuiFormHelpText, } from '@elastic/eui'; -import { IFieldType } from 'src/plugins/data/public'; +import { IndexPatternField } from 'src/plugins/data/public'; import { FormattedMessage } from '@kbn/i18n/react'; import { MetricsEditor } from '../../../../components/metrics_editor'; import { AGG_TYPE } from '../../../../../common/constants'; @@ -23,7 +23,7 @@ import { AggDescriptor, FieldedAggDescriptor } from '../../../../../common/descr interface Props { metrics: AggDescriptor[]; - rightFields: IFieldType[]; + rightFields: IndexPatternField[]; onChange: (metrics: AggDescriptor[]) => void; } diff --git a/x-pack/plugins/maps/public/index_pattern_util.test.ts b/x-pack/plugins/maps/public/index_pattern_util.test.ts index 49ae16415e159..242612fe8d1a3 100644 --- a/x-pack/plugins/maps/public/index_pattern_util.test.ts +++ b/x-pack/plugins/maps/public/index_pattern_util.test.ts @@ -14,15 +14,16 @@ import { supportsGeoTileAgg, } from './index_pattern_util'; import { ES_GEO_FIELD_TYPE } from '../common/constants'; +import { IndexPatternField } from 'src/plugins/data/public'; describe('getSourceFields', () => { test('Should remove multi fields from field list', () => { const fields = [ - { + ({ name: 'agent', type: 'string', - }, - { + } as unknown) as IndexPatternField, + ({ name: 'agent.keyword', subType: { multi: { @@ -30,7 +31,7 @@ describe('getSourceFields', () => { }, }, type: 'string', - }, + } as unknown) as IndexPatternField, ]; const sourceFields = getSourceFields(fields); expect(sourceFields).toEqual([{ name: 'agent', type: 'string' }]); @@ -40,29 +41,29 @@ describe('getSourceFields', () => { describe('Gold+ licensing', () => { const testStubs = [ { - field: { + field: ({ name: 'location', type: 'geo_point', aggregatable: true, - }, + } as unknown) as IndexPatternField, supportedInBasic: true, supportedInGold: true, }, { - field: { + field: ({ name: 'location', type: 'geo_shape', aggregatable: false, - }, + } as unknown) as IndexPatternField, supportedInBasic: false, supportedInGold: false, }, { - field: { + field: ({ name: 'location', type: 'geo_shape', aggregatable: true, - }, + } as unknown) as IndexPatternField, supportedInBasic: false, supportedInGold: true, }, diff --git a/x-pack/plugins/maps/public/index_pattern_util.ts b/x-pack/plugins/maps/public/index_pattern_util.ts index 3b1cb461c8779..dee6f2f359a58 100644 --- a/x-pack/plugins/maps/public/index_pattern_util.ts +++ b/x-pack/plugins/maps/public/index_pattern_util.ts @@ -5,14 +5,14 @@ * 2.0. */ -import { IFieldType, IndexPattern } from 'src/plugins/data/public'; +import { IndexPatternField, IndexPattern } from 'src/plugins/data/public'; import { i18n } from '@kbn/i18n'; import { getIndexPatternService } from './kibana_services'; import { indexPatterns } from '../../../../src/plugins/data/public'; import { ES_GEO_FIELD_TYPE, ES_GEO_FIELD_TYPES } from '../common/constants'; import { getIsGoldPlus } from './licensed_features'; -export function getGeoTileAggNotSupportedReason(field: IFieldType): string | null { +export function getGeoTileAggNotSupportedReason(field: IndexPatternField): string | null { if (!field.aggregatable) { return i18n.translate('xpack.maps.geoTileAgg.disabled.docValues', { defaultMessage: @@ -46,7 +46,7 @@ export async function getIndexPatternsFromIds( return await Promise.all(promises); } -export function getTermsFields(fields: IFieldType[]): IFieldType[] { +export function getTermsFields(fields: IndexPatternField[]): IndexPatternField[] { return fields.filter((field) => { return ( field.aggregatable && @@ -56,7 +56,7 @@ export function getTermsFields(fields: IFieldType[]): IFieldType[] { }); } -export function getSortFields(fields: IFieldType[]): IFieldType[] { +export function getSortFields(fields: IndexPatternField[]): IndexPatternField[] { return fields.filter((field) => { return field.sortable && !indexPatterns.isNestedField(field); }); @@ -70,23 +70,23 @@ export function getAggregatableGeoFieldTypes(): string[] { return aggregatableFieldTypes; } -export function getGeoFields(fields: IFieldType[]): IFieldType[] { +export function getGeoFields(fields: IndexPatternField[]): IndexPatternField[] { return fields.filter((field) => { return !indexPatterns.isNestedField(field) && ES_GEO_FIELD_TYPES.includes(field.type); }); } -export function getGeoPointFields(fields: IFieldType[]): IFieldType[] { +export function getGeoPointFields(fields: IndexPatternField[]): IndexPatternField[] { return fields.filter((field) => { return !indexPatterns.isNestedField(field) && ES_GEO_FIELD_TYPE.GEO_POINT === field.type; }); } -export function getFieldsWithGeoTileAgg(fields: IFieldType[]): IFieldType[] { +export function getFieldsWithGeoTileAgg(fields: IndexPatternField[]): IndexPatternField[] { return fields.filter(supportsGeoTileAgg); } -export function supportsGeoTileAgg(field?: IFieldType): boolean { +export function supportsGeoTileAgg(field?: IndexPatternField): boolean { return ( !!field && !!field.aggregatable && @@ -95,7 +95,7 @@ export function supportsGeoTileAgg(field?: IFieldType): boolean { ); } -export function getSourceFields(fields: IFieldType[]): IFieldType[] { +export function getSourceFields(fields: IndexPatternField[]): IndexPatternField[] { return fields.filter((field) => { // Multi fields are not stored in _source and only exist in index. const isMultiField = field.subType && field.subType.multi; diff --git a/x-pack/plugins/maps/server/maps_telemetry/maps_telemetry.ts b/x-pack/plugins/maps/server/maps_telemetry/maps_telemetry.ts index b345c427b50b9..9da754839fc0b 100644 --- a/x-pack/plugins/maps/server/maps_telemetry/maps_telemetry.ts +++ b/x-pack/plugins/maps/server/maps_telemetry/maps_telemetry.ts @@ -7,7 +7,7 @@ import _ from 'lodash'; import { SavedObject } from 'kibana/server'; -import { IFieldType } from 'src/plugins/data/public'; +import { IndexPatternField } from 'src/plugins/data/public'; import { ES_GEO_FIELD_TYPE, LAYER_TYPE, @@ -136,7 +136,8 @@ async function isFieldGeoShape( return false; } return indexPattern.fields.some( - (fieldDescriptor: IFieldType) => fieldDescriptor.name && fieldDescriptor.name === geoField! + (fieldDescriptor: IndexPatternField) => + fieldDescriptor.name && fieldDescriptor.name === geoField! ); }