Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Maps] replace IFieldType with IndexPatternField #110245

Merged
merged 4 commits into from
Aug 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion x-pack/plugins/maps/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/maps/common/elasticsearch_util/es_agg_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

import { i18n } from '@kbn/i18n';
import _ from 'lodash';
import { IndexPattern, IFieldType } from '../../../../../src/plugins/data/common';
import type { IndexPattern, IndexPatternField } from 'src/plugins/data/common';
import { AGG_TYPE, JOIN_FIELD_NAME_PREFIX, TOP_TERM_PERCENTAGE_SUFFIX } from '../constants';

export type BucketProperties = Record<string | number, unknown>;
export type PropertiesMap = Map<string, BucketProperties>;

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(
Expand All @@ -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 }
: {
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/maps/public/classes/fields/es_doc_field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
* 2.0.
*/

import type { IndexPatternField } from 'src/plugins/data/public';
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 { IField, AbstractField } from './field';
import { IESSource } from '../sources/es_source';
import { IVectorSource } from '../sources/vector_source';
Expand Down Expand Up @@ -42,7 +42,7 @@ export class ESDocField extends AbstractField implements IField {
return this._source;
}

async _getIndexPatternField(): Promise<IFieldType | undefined> {
async _getIndexPatternField(): Promise<IndexPatternField | undefined> {
const indexPattern = await this._source.getIndexPattern();
const indexPatternField = indexPattern.fields.getByName(this.getName());
return indexPatternField && indexPatterns.isNestedField(indexPatternField)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -56,14 +56,14 @@ interface State {
leftEmsFileId: string | null;
leftEmsFields: Array<EuiComboBoxOptionOption<string>>;
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ import React, { Fragment, Component } from 'react';

import { FormattedMessage } from '@kbn/i18n/react';
import { EuiPanel, EuiSpacer, EuiTitle } from '@elastic/eui';
import {
IFieldType,
IndexPattern,
indexPatterns,
} from '../../../../../../../src/plugins/data/public';
import type { IndexPatternField, IndexPattern } from 'src/plugins/data/public';
import { indexPatterns } from '../../../../../../../src/plugins/data/public';
import { MetricsEditor } from '../../../components/metrics_editor';
import { getIndexPatternService } from '../../../kibana_services';
import { GeoLineForm } from './geo_line_form';
Expand All @@ -30,7 +27,7 @@ interface Props {

interface State {
indexPattern: IndexPattern | null;
fields: IFieldType[];
fields: IndexPatternField[];
}

export class UpdateSourceEditor extends Component<Props, State> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -183,7 +183,7 @@ export class ESSearchSource extends AbstractESSource implements ITiledSingleLaye
async getFields(): Promise<IField[]> {
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;
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@
import React, { Component } from 'react';
import { EuiPanel } from '@elastic/eui';

import type { IndexPattern, IndexPatternField } from 'src/plugins/data/public';
import { SCALING_TYPES } from '../../../../../common/constants';
import { GeoFieldSelect } from '../../../../components/geo_field_select';
import { GeoIndexPatternSelect } from '../../../../components/geo_index_pattern_select';
import { getGeoFields, getTermsFields, getSortFields } from '../../../../index_pattern_util';
import { ESSearchSourceDescriptor } from '../../../../../common/descriptor_types';
import {
IndexPattern,
IFieldType,
SortDirection,
} from '../../../../../../../../src/plugins/data/common';
import { SortDirection } from '../../../../../../../../src/plugins/data/public';
import { TopHitsForm } from './top_hits_form';
import { OnSourceChangeArgs } from '../../source';

Expand All @@ -27,12 +24,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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,24 @@
import React, { ChangeEvent, Component, Fragment } from 'react';
import { EuiFormRow, EuiSelect } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import type { IndexPatternField } from 'src/plugins/data/public';
import { SingleFieldSelect } from '../../../../components/single_field_select';
import { getIndexPatternService } from '../../../../kibana_services';
// @ts-expect-error
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 { 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import React, { Component, Fragment } from 'react';
import { EuiFormRow, EuiTitle, EuiPanel, EuiSpacer, EuiSwitch, EuiSwitchEvent } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import type { IndexPatternField } from 'src/plugins/data/public';
import { FIELD_ORIGIN } from '../../../../../common/constants';
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 } from '../../../../../../../../src/plugins/data/public';
import { ESDocField } from '../../../fields/es_doc_field';
import { OnSourceChangeArgs } from '../../source';
import { TopHitsForm } from './top_hits_form';
Expand All @@ -36,8 +37,8 @@ interface Props {
interface State {
loadError?: string;
sourceFields: IField[];
termFields: IFieldType[];
sortFields: IFieldType[];
termFields: IndexPatternField[];
sortFields: IndexPatternField[];
}

export class TopHitsUpdateSourceEditor extends Component<Props, State> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,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 type { IndexPatternField, IndexPattern } from 'src/plugins/data/public';

function createMockIndexPattern(fields: IFieldType[]): IndexPattern {
function createMockIndexPattern(fields: IndexPatternField[]): IndexPattern {
const indexPattern = {
get fields() {
return {
Expand All @@ -29,9 +28,8 @@ describe('getDocValueAndSourceFields', () => {
createMockIndexPattern([
{
name: 'foobar',
// @ts-expect-error runtimeField not added yet to IFieldType. API tbd
runtimeField: {},
},
runtimeField: { type: 'keyword' },
} as IndexPatternField,
]),
['foobar'],
'epoch_millis'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -364,7 +364,7 @@ export class AbstractESSource extends AbstractVectorSource implements IESSource
}
}

async _getGeoField(): Promise<IFieldType> {
async _getGeoField(): Promise<IndexPatternField> {
const indexPattern = await this.getIndexPattern();
const geoField = indexPattern.fields.getByName(this.getGeoFieldName());
if (!geoField) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { IFieldType, IndexPattern } from '../../../../../../src/plugins/data/public';
import type { IndexPatternField, IndexPattern } from 'src/plugins/data/public';
import { ESTooltipProperty } from './es_tooltip_property';
import { TooltipProperty } from './tooltip_property';
import { AbstractField } from '../fields/field';
Expand All @@ -25,7 +25,7 @@ const indexPatternField = {
searchable: true,
aggregatable: true,
readFromDocValues: false,
} as IFieldType;
} as IndexPatternField;

const featurePropertyField = new MockField({
fieldName: 'machine.os',
Expand All @@ -41,7 +41,7 @@ const nonFilterableIndexPatternField = {
searchable: true,
aggregatable: true,
readFromDocValues: false,
} as IFieldType;
} as IndexPatternField;

const nonFilterableFeaturePropertyField = new MockField({
fieldName: 'location',
Expand All @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/maps/public/components/geo_field_select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import React from 'react';
import { i18n } from '@kbn/i18n';
import { EuiFormRow } from '@elastic/eui';
import type { IndexPatternField } from 'src/plugins/data/public';
import { SingleFieldSelect } from './single_field_select';
import { IFieldType } from '../../../../../src/plugins/data/common';

interface Props {
value: string;
geoFields: IFieldType[];
geoFields: IndexPatternField[];
onChange: (geoFieldName?: string) => void;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import { i18n } from '@kbn/i18n';
import { EuiButtonEmpty, EuiComboBoxOptionOption, EuiFieldText, EuiFormRow } from '@elastic/eui';

import { FormattedMessage } from '@kbn/i18n/react';
import type { IndexPatternField } from 'src/plugins/data/public';
import { MetricSelect } from './metric_select';
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 { ValidatedNumberInput } from '../validated_number_input';

function filterFieldsForAgg(fields: IFieldType[], aggType: AGG_TYPE) {
function filterFieldsForAgg(fields: IndexPatternField[], aggType: AGG_TYPE) {
if (!fields) {
return [];
}
Expand All @@ -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<AGG_TYPE>) => boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import React, { Component, Fragment } from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiButtonEmpty, EuiComboBoxOptionOption, EuiSpacer, EuiTextAlign } from '@elastic/eui';
import type { IndexPatternField } from 'src/plugins/data/public';
import { MetricEditor } from './metric_editor';
import { DEFAULT_METRIC } from '../../classes/sources/es_agg_source';
import { IFieldType } from '../../../../../../src/plugins/data/public';
import { AggDescriptor, FieldedAggDescriptor } from '../../../common/descriptor_types';
import { AGG_TYPE } from '../../../common/constants';

Expand All @@ -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<AGG_TYPE>) => boolean;
}
Expand Down
Loading