Skip to content

Commit

Permalink
remove any from IIndexPattern
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkime committed Sep 19, 2020
1 parent 2dfc225 commit 1968b69
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class IndexPatternField implements IFieldType {
getFormatterForField,
}: {
getFormatterForField?: IndexPattern['getFormatterForField'];
} = {}) {
} = {}): FieldSpec {
return {
count: this.count,
script: this.script,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
IIndexPattern,
FieldTypeUnknownError,
FieldFormatNotFoundError,
IFieldType,
} from '../../../common';
import { findByTitle } from '../utils';
import { IndexPatternMissingIndices } from '../lib';
Expand Down Expand Up @@ -485,7 +486,9 @@ export class IndexPattern implements IIndexPattern {
};
}

getFormatterForField(field: IndexPatternField | IndexPatternField['spec']): FieldFormat {
getFormatterForField(
field: IndexPatternField | IndexPatternField['spec'] | IFieldType
): FieldFormat {
return (
this.fieldFormatMap[field.name] ||
this.fieldFormats.getDefaultInstance(
Expand Down
6 changes: 4 additions & 2 deletions src/plugins/data/common/index_patterns/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@ import { ToastInputFields, ErrorToastOptions } from 'src/core/public/notificatio
import type { SavedObject } from 'src/core/server';
import { IFieldType } from './fields';
import { SerializedFieldFormat } from '../../../expressions/common';
import { KBN_FIELD_TYPES } from '..';
import { KBN_FIELD_TYPES, IndexPatternField, FieldFormat } from '..';

export interface IIndexPattern {
[key: string]: any;
fields: IFieldType[];
title: string;
id?: string;
type?: string;
timeFieldName?: string;
getTimeField?(): IFieldType | undefined;
getFormatterForField?: (
field: IndexPatternField | IndexPatternField['spec'] | IFieldType
) => FieldFormat;
fieldFormatMap?: Record<
string,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { IUiSettingsClient, MountPoint } from 'kibana/public';
import { HitsCounter } from './hits_counter';
import { TimechartHeader } from './timechart_header';
import { DiscoverSidebar } from './sidebar';
import { getServices, IIndexPattern } from '../../kibana_services';
import { getServices, IndexPattern } from '../../kibana_services';
// @ts-ignore
import { DiscoverNoResults } from '../angular/directives/no_results';
import { DiscoverUninitialized } from '../angular/directives/uninitialized';
Expand Down Expand Up @@ -58,7 +58,7 @@ export interface DiscoverLegacyProps {
fieldCounts: Record<string, number>;
histogramData: Chart;
hits: number;
indexPattern: IIndexPattern;
indexPattern: IndexPattern;
minimumVisibleRows: number;
onAddFilter: (field: IndexPatternField | string, value: string, type: '+' | '-') => void;
onChangeInterval: (interval: string) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import React from 'react';
import { shallow } from 'enzyme';
import { IndexPatternField, IIndexPattern } from 'src/plugins/data/public';
import { IndexPatternField, IndexPattern } from 'src/plugins/data/public';
import { IndexedFieldsTable } from './indexed_fields_table';

jest.mock('@elastic/eui', () => ({
Expand All @@ -43,7 +43,7 @@ const helpers = {

const indexPattern = ({
getNonScriptedFields: () => fields,
} as unknown) as IIndexPattern;
} as unknown) as IndexPattern;

const mockFieldToIndexPatternField = (spec: Record<string, string | boolean | undefined>) => {
return new IndexPatternField(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,19 @@

import React, { Component } from 'react';
import { createSelector } from 'reselect';
import {
IndexPatternField,
IIndexPattern,
IFieldType,
} from '../../../../../../plugins/data/public';
import { IndexPatternField, IndexPattern, IFieldType } from '../../../../../../plugins/data/public';
import { Table } from './components/table';
import { getFieldFormat } from './lib';
import { IndexedFieldItem } from './types';

interface IndexedFieldsTableProps {
fields: IndexPatternField[];
indexPattern: IIndexPattern;
indexPattern: IndexPattern;
fieldFilter?: string;
indexedFieldTypeFilter?: string;
helpers: {
redirectToRoute: (obj: any) => void;
getFieldInfo: (indexPattern: IIndexPattern, field: IFieldType) => string[];
getFieldInfo: (indexPattern: IndexPattern, field: IFieldType) => string[];
};
fieldWildcardMatcher: (filters: any[]) => (val: any) => boolean;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ import { shallow, ShallowWrapper } from 'enzyme';

import { Table, TableProps, TableState } from './table';
import { EuiTableFieldDataColumnType, keys } from '@elastic/eui';
import { IIndexPattern } from 'src/plugins/data/public';
import { IndexPattern } from 'src/plugins/data/public';
import { SourceFiltersTableFilter } from '../../types';

const indexPattern = {} as IIndexPattern;
const indexPattern = {} as IndexPattern;
const items: SourceFiltersTableFilter[] = [{ value: 'tim*', clientId: '' }];

const getIndexPatternMock = (mockedFields: any = {}) => ({ ...mockedFields } as IIndexPattern);
const getIndexPatternMock = (mockedFields: any = {}) => ({ ...mockedFields } as IndexPattern);

const getTableColumnRender = (
component: ShallowWrapper<TableProps, TableState, Table>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {

import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { IIndexPattern } from 'src/plugins/data/public';
import { IndexPattern } from 'src/plugins/data/public';
import { SourceFiltersTableFilter } from '../../types';

const filterHeader = i18n.translate(
Expand Down Expand Up @@ -80,7 +80,7 @@ const cancelAria = i18n.translate(
);

export interface TableProps {
indexPattern: IIndexPattern;
indexPattern: IndexPattern;
items: SourceFiltersTableFilter[];
deleteFilter: Function;
fieldWildcardMatcher: Function;
Expand Down
32 changes: 21 additions & 11 deletions x-pack/plugins/maps/server/maps_telemetry/maps_telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@

import _ from 'lodash';
import {
SavedObject,
SavedObjectAttribute,
SavedObjectAttributes,
SavedObjectsClientContract,
} from 'kibana/server';
import { IFieldType, IIndexPattern } from 'src/plugins/data/public';
import { IFieldType, IndexPatternAttributes } from 'src/plugins/data/public';
import {
ES_GEO_FIELD_TYPE,
LAYER_TYPE,
Expand Down Expand Up @@ -64,7 +65,9 @@ function getUniqueLayerCounts(layerCountsList: ILayerTypeCount[], mapsCount: num
}, {});
}

function getIndexPatternsWithGeoFieldCount(indexPatterns: IIndexPattern[]) {
function getIndexPatternsWithGeoFieldCount(
indexPatterns: Array<SavedObject<IndexPatternAttributes>>
) {
const fieldLists = indexPatterns.map((indexPattern) =>
indexPattern.attributes && indexPattern.attributes.fields
? JSON.parse(indexPattern.attributes.fields)
Expand Down Expand Up @@ -112,17 +115,19 @@ function getEMSLayerCount(layerLists: LayerDescriptor[][]): ILayerTypeCount[] {
}

function isFieldGeoShape(
indexPatterns: IIndexPattern[],
indexPatterns: Array<SavedObject<IndexPatternAttributes>>,
indexPatternId: string,
geoField: string | undefined
): boolean {
if (!geoField) {
return false;
}

const matchIndexPattern = indexPatterns.find((indexPattern: IIndexPattern) => {
return indexPattern.id === indexPatternId;
});
const matchIndexPattern = indexPatterns.find(
(indexPattern: SavedObject<IndexPatternAttributes>) => {
return indexPattern.id === indexPatternId;
}
);

if (!matchIndexPattern) {
return false;
Expand All @@ -140,7 +145,10 @@ function isFieldGeoShape(
return !!matchField && matchField.type === ES_GEO_FIELD_TYPE.GEO_SHAPE;
}

function isGeoShapeAggLayer(indexPatterns: IIndexPattern[], layer: LayerDescriptor): boolean {
function isGeoShapeAggLayer(
indexPatterns: Array<SavedObject<IndexPatternAttributes>>,
layer: LayerDescriptor
): boolean {
if (layer.sourceDescriptor === null) {
return false;
}
Expand Down Expand Up @@ -176,7 +184,7 @@ function isGeoShapeAggLayer(indexPatterns: IIndexPattern[], layer: LayerDescript

function getGeoShapeAggCount(
layerLists: LayerDescriptor[][],
indexPatterns: IIndexPattern[]
indexPatterns: Array<SavedObject<IndexPatternAttributes>>
): number {
const countsPerMap: number[] = layerLists.map((layerList: LayerDescriptor[]) => {
const geoShapeAggLayers = layerList.filter((layerDescriptor) => {
Expand Down Expand Up @@ -204,7 +212,7 @@ export function buildMapsTelemetry({
settings,
}: {
mapSavedObjects: MapSavedObject[];
indexPatternSavedObjects: IIndexPattern[];
indexPatternSavedObjects: Array<SavedObject<IndexPatternAttributes>>;
settings: SavedObjectAttribute;
}): SavedObjectAttributes {
const layerLists: LayerDescriptor[][] = getLayerLists(mapSavedObjects);
Expand Down Expand Up @@ -283,10 +291,12 @@ export async function getMapsTelemetry(config: MapsConfigType) {
const savedObjectsClient = getInternalRepository();
// @ts-ignore
const mapSavedObjects: MapSavedObject[] = await getMapSavedObjects(savedObjectsClient);
const indexPatternSavedObjects: IIndexPattern[] = (await getIndexPatternSavedObjects(
const indexPatternSavedObjects: Array<SavedObject<
IndexPatternAttributes
>> = (await getIndexPatternSavedObjects(
// @ts-ignore
savedObjectsClient
)) as IIndexPattern[];
)) as Array<SavedObject<IndexPatternAttributes>>;
const settings: SavedObjectAttribute = {
showMapVisualizationTypes: config.showMapVisualizationTypes,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
esFilters,
FilterManager,
UI_SETTINGS,
IndexPattern,
} from '../../../../../../../../src/plugins/data/public';
import { SeverityBadge } from '../severity_badge';

Expand Down Expand Up @@ -140,11 +141,11 @@ describe('helpers', () => {
filterManager: mockFilterManager,
query: mockQueryBarWithFilters.query,
savedId: mockQueryBarWithFilters.saved_id,
indexPatterns: {
indexPatterns: ({
fields: [{ name: 'event.category', type: 'test type' }],
title: 'test title',
getFormatterForField: () => ({ convert: (val: unknown) => val }),
},
} as unknown) as IndexPattern,
});
const wrapper = shallow<React.ReactElement>(result[0].description as React.ReactElement);
const filterLabelComponent = wrapper.find(esFilters.FilterLabel).at(0);
Expand Down

0 comments on commit 1968b69

Please sign in to comment.