Skip to content

Commit

Permalink
#124063 - deprecated IndexPattern imports replaced to DataView (#124660)
Browse files Browse the repository at this point in the history
  • Loading branch information
maksimkovalev authored Feb 4, 2022
1 parent 161c76a commit c1c75a5
Show file tree
Hide file tree
Showing 24 changed files with 82 additions and 84 deletions.
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 type { IndexPattern, IndexPatternField } from 'src/plugins/data/common';
import type { DataView, DataViewField } 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): IndexPatternField {
export function getField(indexPattern: DataView, fieldName: string): DataViewField {
const field = indexPattern.fields.getByName(fieldName);
if (!field) {
throw new Error(
Expand All @@ -26,7 +26,7 @@ export function getField(indexPattern: IndexPattern, fieldName: string): IndexPa
return field;
}

export function addFieldToDSL(dsl: object, field: IndexPatternField) {
export function addFieldToDSL(dsl: object, field: DataViewField) {
return !field.scripted
? { ...dsl, field: field.name }
: {
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/maps/public/classes/fields/agg/agg_field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { IndexPattern } from 'src/plugins/data/public';
import { DataView } from 'src/plugins/data/common';
import { AGG_TYPE } from '../../../../common/constants';
import { TileMetaFeature } from '../../../../common/descriptor_types';
import { CountAggField } from './count_agg_field';
Expand Down Expand Up @@ -61,7 +61,7 @@ export class AggField extends CountAggField {
return this._aggType;
}

getValueAggDsl(indexPattern: IndexPattern): unknown {
getValueAggDsl(indexPattern: DataView): unknown {
const field = getField(indexPattern, this.getRootName());
const aggType = this._getAggType();
const aggBody = aggType === AGG_TYPE.TERMS ? { size: 1, shard_size: TERMS_AGG_SHARD_SIZE } : {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
*/

import { IField } from '../field';
import { IndexPattern } from '../../../../../../../src/plugins/data/common';
import { DataView } from '../../../../../../../src/plugins/data/common';
import { IESAggSource } from '../../sources/es_agg_source';
import { FIELD_ORIGIN } from '../../../../common/constants';

export interface IESAggField extends IField {
getValueAggDsl(indexPattern: IndexPattern): unknown | null;
getValueAggDsl(indexPattern: DataView): unknown | null;
getBucketCount(): number;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { IndexPattern } from 'src/plugins/data/public';
import { DataView } from 'src/plugins/data/common';
import { IESAggSource } from '../../sources/es_agg_source';
import { IVectorSource } from '../../sources/vector_source';
import { AGG_TYPE, FIELD_ORIGIN } from '../../../../common/constants';
Expand Down Expand Up @@ -83,7 +83,7 @@ export class CountAggField implements IESAggField {
);
}

getValueAggDsl(indexPattern: IndexPattern): unknown | null {
getValueAggDsl(indexPattern: DataView): unknown | null {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { IndexPattern } from 'src/plugins/data/common';
import { DataView } from 'src/plugins/data/common';
import { i18n } from '@kbn/i18n';
import { AGG_TYPE } from '../../../../common/constants';
import { IESAggField, CountAggFieldParams } from './agg_field_types';
Expand Down Expand Up @@ -67,7 +67,7 @@ export class PercentileAggField extends AggField implements IESAggField {
return `${super.getName()}_${this._percentile}`;
}

getValueAggDsl(indexPattern: IndexPattern): unknown {
getValueAggDsl(indexPattern: DataView): unknown {
const field = getField(indexPattern, this.getRootName());
const dsl: Record<string, unknown> = addFieldToDSL({}, field);
dsl.percents = [this._percentile];
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 { IndexPatternField, IndexPattern } from 'src/plugins/data/public';
import { DataViewField, DataView } from 'src/plugins/data/common';
import { getDataViewLabel, getDataViewSelectPlaceholder } from '../../../../../common/i18n_getters';
import { RenderWizardArguments } from '../layer_wizard_registry';
import { EMSFileSelect } from '../../../../components/ems_file_select';
Expand Down Expand Up @@ -59,15 +59,15 @@ interface State {
leftSource: BOUNDARIES_SOURCE;
leftEmsFileId: string | null;
leftEmsFields: Array<EuiComboBoxOptionOption<string>>;
leftIndexPattern: IndexPattern | null;
leftGeoFields: IndexPatternField[];
leftJoinFields: IndexPatternField[];
leftIndexPattern: DataView | null;
leftGeoFields: DataViewField[];
leftJoinFields: DataViewField[];
leftGeoField: string | null;
leftEmsJoinField: string | null;
leftElasticsearchJoinField: string | null;
rightIndexPatternId: string;
rightIndexPatternTitle: string | null;
rightTermsFields: IndexPatternField[];
rightTermsFields: DataViewField[];
rightJoinField: string | null;
}

Expand Down Expand Up @@ -157,7 +157,7 @@ export class LayerTemplate extends Component<RenderWizardArguments, State> {
);
};

_onLeftIndexPatternChange = (indexPattern: IndexPattern) => {
_onLeftIndexPatternChange = (indexPattern: DataView) => {
this.setState(
{
leftIndexPattern: indexPattern,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { esAggFieldsFactory, IESAggField } from '../../fields/agg';
import { AGG_TYPE, COUNT_PROP_LABEL, FIELD_ORIGIN } from '../../../../common/constants';
import { getSourceAggKey } from '../../../../common/get_agg_key';
import { AbstractESAggSourceDescriptor, AggDescriptor } from '../../../../common/descriptor_types';
import { IndexPattern } from '../../../../../../../src/plugins/data/public';
import { DataView } from '../../../../../../../src/plugins/data/common';
import { IField } from '../../fields/field';
import { ITooltipProperty } from '../../tooltips/tooltip_property';

Expand All @@ -25,7 +25,7 @@ export interface IESAggSource extends IESSource {
getAggLabel(aggType: AGG_TYPE, fieldLabel: string): string;
getMetricFields(): IESAggField[];
getMetricFieldForName(fieldName: string): IESAggField | null;
getValueAggsDsl(indexPattern: IndexPattern): { [key: string]: unknown };
getValueAggsDsl(indexPattern: DataView): { [key: string]: unknown };
}

export abstract class AbstractESAggSource extends AbstractESSource implements IESAggSource {
Expand Down Expand Up @@ -107,7 +107,7 @@ export abstract class AbstractESAggSource extends AbstractESSource implements IE
return this.getMetricFields();
}

getValueAggsDsl(indexPattern: IndexPattern, metricsFilter?: (metric: IESAggField) => boolean) {
getValueAggsDsl(indexPattern: DataView, metricsFilter?: (metric: IESAggField) => boolean) {
const valueAggsDsl: { [key: string]: unknown } = {};
this.getMetricFields()
.filter((esAggMetric) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import {
} from '../../../../common/descriptor_types';
import { ImmutableSourceProperty, SourceEditorArgs } from '../source';
import { ISearchSource } from '../../../../../../../src/plugins/data/common/search/search_source';
import { IndexPattern } from '../../../../../../../src/plugins/data/common';
import { DataView } from '../../../../../../../src/plugins/data/common';
import { Adapters } from '../../../../../../../src/plugins/inspector/common/adapters';
import { isValidStringConfig } from '../../util/valid_string_config';
import { makePublicExecutionContext } from '../../../util';
Expand Down Expand Up @@ -211,7 +211,7 @@ export class ESGeoGridSource extends AbstractESAggSource implements IMvtVectorSo
}: {
searchSource: ISearchSource;
searchSessionId?: string;
indexPattern: IndexPattern;
indexPattern: DataView;
precision: number;
layerName: string;
registerCancelCallback: (callback: () => void) => void;
Expand Down Expand Up @@ -317,7 +317,7 @@ export class ESGeoGridSource extends AbstractESAggSource implements IMvtVectorSo
}: {
searchSource: ISearchSource;
searchSessionId?: string;
indexPattern: IndexPattern;
indexPattern: DataView;
precision: number;
layerName: string;
registerCancelCallback: (callback: () => void) => void;
Expand Down Expand Up @@ -385,7 +385,7 @@ export class ESGeoGridSource extends AbstractESAggSource implements IMvtVectorSo
throw new Error('Cannot get GeoJson without searchFilter.buffer');
}

const indexPattern: IndexPattern = await this.getIndexPattern();
const indexPattern: DataView = await this.getIndexPattern();
const searchSource: ISearchSource = await this.makeSearchSource(searchFilters, 0);
searchSource.setField('trackTotalHits', false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import React, { Component } from 'react';

import { IndexPattern } from 'src/plugins/data/public';
import { DataView } from 'src/plugins/data/common';
import { i18n } from '@kbn/i18n';
import { EuiFormRow, EuiPanel } from '@elastic/eui';
import { SingleFieldSelect } from '../../../components/single_field_select';
Expand All @@ -28,7 +28,7 @@ interface Props {
}

interface State {
indexPattern: IndexPattern | null;
indexPattern: DataView | null;
geoField: string;
splitField: string;
sortField: string;
Expand All @@ -42,7 +42,7 @@ export class CreateSourceEditor extends Component<Props, State> {
sortField: '',
};

_onIndexPatternSelect = (indexPattern: IndexPattern) => {
_onIndexPatternSelect = (indexPattern: DataView) => {
const pointFields = getGeoPointFields(indexPattern.fields);
this.setState(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

import React from 'react';

import { IndexPattern } from 'src/plugins/data/public';
import { DataView } from 'src/plugins/data/common';
import { EuiFormRow } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { SingleFieldSelect } from '../../../components/single_field_select';
import { getTermsFields } from '../../../index_pattern_util';
import { indexPatterns } from '../../../../../../../src/plugins/data/public';

interface Props {
indexPattern: IndexPattern;
indexPattern: DataView;
onSortFieldChange: (fieldName: string) => void;
onSplitFieldChange: (fieldName: string) => void;
sortField: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React, { Fragment, Component } from 'react';

import { FormattedMessage } from '@kbn/i18n-react';
import { EuiPanel, EuiSpacer, EuiTitle } from '@elastic/eui';
import type { IndexPatternField, IndexPattern } from 'src/plugins/data/public';
import type { DataViewField, DataView } from 'src/plugins/data/common';
import { indexPatterns } from '../../../../../../../src/plugins/data/public';
import { MetricsEditor } from '../../../components/metrics_editor';
import { getIndexPatternService } from '../../../kibana_services';
Expand All @@ -26,8 +26,8 @@ interface Props {
}

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

export class UpdateSourceEditor extends Component<Props, State> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import rison from 'rison-node';
import { i18n } from '@kbn/i18n';
import { GeoJsonProperties, Geometry, Position } from 'geojson';
import { type Filter, buildPhraseFilter } from '@kbn/es-query';
import type { IndexPatternField, IndexPattern } from 'src/plugins/data/public';
import type { DataViewField, DataView } from 'src/plugins/data/common';
import { AbstractESSource } from '../es_source';
import {
getHttp,
Expand Down Expand Up @@ -193,7 +193,7 @@ export class ESSearchSource extends AbstractESSource implements IMvtVectorSource
async getFields(): Promise<IField[]> {
try {
const indexPattern = await this.getIndexPattern();
const fields: IndexPatternField[] = indexPattern.fields.filter((field) => {
const fields: DataViewField[] = indexPattern.fields.filter((field) => {
// Ensure fielddata is enabled for field.
// Search does not request _source
return field.aggregatable;
Expand Down Expand Up @@ -279,7 +279,7 @@ export class ESSearchSource extends AbstractESSource implements IMvtVectorSource
throw new Error('Cannot _getTopHits without topHitsSplitField');
}

const indexPattern: IndexPattern = await this.getIndexPattern();
const indexPattern: DataView = await this.getIndexPattern();

const fieldNames = searchFilters.fieldNames.filter(
(fieldName) => fieldName !== this._descriptor.geoField
Expand Down Expand Up @@ -315,7 +315,7 @@ export class ESSearchSource extends AbstractESSource implements IMvtVectorSource
};
}

const topHitsSplitField: IndexPatternField = getField(indexPattern, topHitsSplitFieldName);
const topHitsSplitField: DataViewField = getField(indexPattern, topHitsSplitFieldName);
const cardinalityAgg = { precision_threshold: 1 };
const termsAgg = {
size: DEFAULT_MAX_BUCKETS_LIMIT,
Expand Down Expand Up @@ -570,7 +570,7 @@ export class ESSearchSource extends AbstractESSource implements IMvtVectorSource
return this._tooltipFields.length > 0;
}

async _loadTooltipProperties(docId: string | number, index: string, indexPattern: IndexPattern) {
async _loadTooltipProperties(docId: string | number, index: string, indexPattern: DataView) {
if (this._tooltipFields.length === 0) {
return {};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import React, { Component } from 'react';
import { EuiPanel } from '@elastic/eui';

import type { IndexPattern, IndexPatternField } from 'src/plugins/data/public';
import type { DataView, DataViewField } from 'src/plugins/data/common';
import { SCALING_TYPES } from '../../../../../common/constants';
import { GeoFieldSelect } from '../../../../components/geo_field_select';
import { GeoIndexPatternSelect } from '../../../../components/geo_index_pattern_select';
Expand All @@ -23,13 +23,13 @@ interface Props {
}

interface State {
indexPattern: IndexPattern | null;
geoFields: IndexPatternField[];
indexPattern: DataView | null;
geoFields: DataViewField[];
geoFieldName: string | null;
sortField: string | null;
sortFields: IndexPatternField[];
sortFields: DataViewField[];
sortOrder: SortDirection;
termFields: IndexPatternField[];
termFields: DataViewField[];
topHitsSplitField: string | null;
topHitsSize: number;
}
Expand All @@ -47,7 +47,7 @@ export class CreateSourceEditor extends Component<Props, State> {
topHitsSize: 1,
};

_onIndexPatternSelect = (indexPattern: IndexPattern) => {
_onIndexPatternSelect = (indexPattern: DataView) => {
const geoFields = getGeoFields(indexPattern.fields);

this.setState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { IndexPattern } from '../../../../../../../../src/plugins/data/common';
import { DataView } from '../../../../../../../../src/plugins/data/common';
import { getField } from '../../../../../common/elasticsearch_util';

export interface ScriptField {
Expand All @@ -14,7 +14,7 @@ export interface ScriptField {
}

export function getDocValueAndSourceFields(
indexPattern: IndexPattern,
indexPattern: DataView,
fieldNames: string[],
dateFormat: string
): {
Expand Down
Loading

0 comments on commit c1c75a5

Please sign in to comment.