Skip to content

Commit

Permalink
[NP] Move IndexPatterns into the NP (#51199)
Browse files Browse the repository at this point in the history
* Make a copy of index_patterns module inside NP

* Sync changes of index patterns

* Remove UI component from service

* Remove redundant exports from index_patterns

* Sync old index_patters changes

* Make common namespace of IndexPattern

* Make re-exports of old IndexPatter dependencies

* Remove utils and error of the old indexPattern

* Plug InterPatternService in data plugin

* Make shortenDotString in new data plugin

* Remove field folder

* Fix wrong merge

* Remove index_pattern folder

* Remove _LEGACY from service

* Remove static code from service

* Fix start contract

* Remove services from the old plugin

* Remove index_patterns_service

* Fix filter.meta.index type

* Fix reviews

* Fix type error
  • Loading branch information
Artyom Gospodarsky authored and Liza Katz committed Nov 30, 2019
1 parent bb7c9ed commit 3a0d5f4
Show file tree
Hide file tree
Showing 48 changed files with 211 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ import {
applyFiltersPopover,
changeTimeFilter,
extractTimeFilter,
IndexPatternsStart,
} from '../../../../../../plugins/data/public';
import { IndexPatternsStart } from '../../index_patterns';

export const GLOBAL_APPLY_FILTER_ACTION = 'GLOBAL_APPLY_FILTER_ACTION';

interface ActionContext {
Expand Down Expand Up @@ -74,7 +75,7 @@ export function createFilterAction(
if (selectedFilters.length > 1) {
const indexPatterns = await Promise.all(
filters.map(filter => {
return indexPatternsService.indexPatterns.get(filter.meta.index);
return indexPatternsService.indexPatterns.get(filter.meta.index!);
})
);

Expand Down
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ export {
/** @public static code */
export * from '../common';
export { FilterStateManager } from './filter/filter_manager';
export { getFromSavedObject, getRoutes } from './index_patterns';
export { getFromSavedObject, getRoutes, flattenHitWrapper } from './index_patterns';
19 changes: 18 additions & 1 deletion src/legacy/core_plugins/data/public/index_patterns/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,21 @@
* under the License.
*/

export * from './index_patterns_service';
import { IFieldType, IIndexPattern, indexPatterns } from '../../../../../plugins/data/public';

const getFromSavedObject = indexPatterns.getFromSavedObject;
const getRoutes = indexPatterns.getRoutes;
const flattenHitWrapper = indexPatterns.flattenHitWrapper;

export { getFromSavedObject, getRoutes, flattenHitWrapper };
export { IFieldType as FieldType };
export { IIndexPattern as StaticIndexPattern };
export {
Field,
FieldListInterface,
IndexPattern,
IndexPatterns,
IndexPatternsStart,
IndexPatternsSetup,
IndexPatternsService,
} from '../../../../../plugins/data/public';
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
import { isEmpty } from 'lodash';
import { IUiSettingsClient, SavedObjectsClientContract } from 'src/core/public';
import { getFromSavedObject } from '../../../index_patterns';
import { getFromSavedObject } from '../../../';

export async function fetchIndexPatterns(
savedObjectsClient: SavedObjectsClientContract,
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/data/public/shim/legacy_module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { once } from 'lodash';

// @ts-ignore
import { uiModules } from 'ui/modules';
import { IndexPatterns } from '../index_patterns/index_patterns';
import { IndexPatterns } from '../';

/** @internal */
export const initLegacyModule = once((indexPatterns: IndexPatterns): void => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { mount } from 'enzyme';
import { IndexPattern } from 'ui/index_patterns';
// @ts-ignore
import { findTestSubject } from '@elastic/eui/lib/test';
import { flattenHitWrapper } from '../../../../data/public/index_patterns/index_patterns/flatten_hit';
import { flattenHitWrapper } from '../../../../data/public/';
import { DocViewTable } from './table';

// @ts-ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ import {

// @ts-ignore
import { initDashboardApp } from './legacy_app';
import { DataStart } from '../../../data/public';
import { DataStart, IndexPatterns } from '../../../data/public';
import { IEmbeddableStart } from '../../../../../plugins/embeddable/public';
import { NavigationStart } from '../../../navigation/public';
import { DataPublicPluginStart as NpDataStart } from '../../../../../plugins/data/public';
import { SharePluginStart } from '../../../../../plugins/share/public';

export interface RenderDeps {
core: LegacyCoreStart;
indexPatterns: DataStart['indexPatterns']['indexPatterns'];
indexPatterns: IndexPatterns;
dataStart: DataStart;
npDataStart: NpDataStart;
navigation: NavigationStart;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
unhashUrl,
} from './legacy_imports';
import { FilterStateManager, IndexPattern } from '../../../data/public';
import { Query, SavedQuery } from '../../../../../plugins/data/public';
import { Query, SavedQuery, IndexPatterns } from '../../../../../plugins/data/public';

import './dashboard_empty_screen_directive';

Expand Down Expand Up @@ -78,9 +78,7 @@ export interface DashboardAppControllerDependencies extends RenderDeps {
$routeParams: any;
getAppState: any;
globalState: State;
indexPatterns: {
getDefault: () => Promise<IndexPattern>;
};
indexPatterns: IndexPatterns;
dashboardConfig: any;
kbnUrl: KbnUrl;
AppStateClass: TAppStateClass<DashboardAppState>;
Expand Down Expand Up @@ -171,7 +169,7 @@ export class DashboardAppController {
} else {
indexPatterns.getDefault().then(defaultIndexPattern => {
$scope.$evalAsync(() => {
$scope.indexPatterns = [defaultIndexPattern];
$scope.indexPatterns = [defaultIndexPattern as IndexPattern];
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
* under the License.
*/

import { setup as data } from '../../../../../../../data/public/legacy';
const { FieldImpl: Field } = data.indexPatterns.__LEGACY;

import { Field } from '../../../../../../../../../plugins/data/public';
import { RegistryFieldFormatEditorsProvider } from 'ui/registry/field_format_editors';
import { docTitle } from 'ui/doc_title';
import { KbnUrlProvider } from 'ui/url';
Expand Down
18 changes: 9 additions & 9 deletions src/legacy/ui/public/index_patterns/__mocks__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
* under the License.
*/

import { dataPluginMock } from '../../../../core_plugins/data/public/mocks';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { dataPluginMock } from '../../../../../plugins/data/public/mocks';
import { indexPatterns as npIndexPatterns } from '../../../../../plugins/data/public';

const dataSetup = dataPluginMock.createSetup();
const dataSetup = dataPluginMock.createSetupContract();

// mocks for stateful code
export const { FieldImpl } = dataSetup.indexPatterns!.__LEGACY;
export const {
FieldList,
flattenHitWrapper,
formatHitProvider,
indexPatterns,
} = dataSetup.indexPatterns!;
export const { indexPatterns } = dataSetup.indexPatterns!;

export const flattenHitWrapper = npIndexPatterns.flattenHitWrapper;
export const formatHitProvider = npIndexPatterns.formatHitProvider;

// static code
export { getFromSavedObject, getRoutes } from '../../../../core_plugins/data/public';
export { FieldList } from '../../../../../plugins/data/public';
12 changes: 4 additions & 8 deletions src/legacy/ui/public/index_patterns/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@
* from ui/index_patterns for backwards compatibility.
*/

import { start as data } from '../../../core_plugins/data/public/legacy';

export const {
FieldList, // only used in Discover and StubIndexPattern
flattenHitWrapper,
formatHitProvider,
} = data.indexPatterns;

import { indexPatterns } from '../../../../plugins/data/public';

// static code
Expand All @@ -42,6 +34,8 @@ export const INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE = indexPatterns.ILLEGAL_CH
export const ILLEGAL_CHARACTERS = indexPatterns.ILLEGAL_CHARACTERS_KEY;
export const CONTAINS_SPACES = indexPatterns.CONTAINS_SPACES_KEY;
export const validateIndexPattern = indexPatterns.validate;
export const flattenHitWrapper = indexPatterns.flattenHitWrapper;
export const formatHitProvider = indexPatterns.formatHitProvider;

// types
export {
Expand All @@ -52,3 +46,5 @@ export {
IndexPatterns,
StaticIndexPattern,
} from '../../../core_plugins/data/public';

export { FieldList } from '../../../../plugins/data/public';
3 changes: 1 addition & 2 deletions src/plugins/data/common/field_formats/converters/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
import { template, escape, keys } from 'lodash';
// @ts-ignore
import { noWhiteSpace } from '../../../../../legacy/core_plugins/kibana/common/utils/no_white_space';
// @ts-ignore
import { shortenDottedString } from '../../../../../legacy/core_plugins/kibana/common/utils/shorten_dotted_string';
import { shortenDottedString } from '../../utils';
import { KBN_FIELD_TYPES } from '../../kbn_field_types/types';
import { FieldFormat } from '../field_format';
import { TextContextTypeConvert, HtmlContextTypeConvert, FIELD_FORMAT_IDS } from '../types';
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/data/common/field_formats/converters/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import { asPrettyString } from '../index';
import { KBN_FIELD_TYPES } from '../../kbn_field_types/types';
import { FieldFormat } from '../field_format';
import { TextContextTypeConvert, FIELD_FORMAT_IDS } from '../types';
// @ts-ignore
import { shortenDottedString } from '../../../../../legacy/core_plugins/kibana/common/utils/shorten_dotted_string';
import { shortenDottedString } from '../../utils';

const TRANSFORM_OPTIONS = [
{
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ export * from './field_formats';
export * from './kbn_field_types';
export * from './index_patterns';
export * from './es_query';

export * from './utils';
export * from './types';
20 changes: 20 additions & 0 deletions src/plugins/data/common/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export { shortenDottedString } from './shorten_dotted_string';
34 changes: 34 additions & 0 deletions src/plugins/data/common/utils/shorten_dotted_string.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { shortenDottedString } from './shorten_dotted_string';

describe('shortenDottedString', () => {
test('should convert a dot.notated.string into a short string', () => {
expect(shortenDottedString('dot.notated.string')).toBe('d.n.string');
});

test('should ignore non-string values', () => {
const obj = { key: 'val' };

expect(shortenDottedString(true)).toBe(true);
expect(shortenDottedString(123)).toBe(123);
expect(shortenDottedString(obj)).toBe(obj);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,14 @@
* under the License.
*/

import { indexPatternsServiceMock } from './index_patterns/index_patterns_service.mock';
const DOT_PREFIX_RE = /(.).+?\./g;

function createDataSetupMock() {
return {
indexPatterns: indexPatternsServiceMock.createSetupContract(),
};
}

function createDataStartMock() {
return {};
/**
* Convert a dot.notated.string into a short
* version (d.n.string)
*
* @return {any}
*/
export function shortenDottedString(input: any) {
return typeof input !== 'string' ? input : input.replace(DOT_PREFIX_RE, '$1.');
}

export const dataPluginMock = {
createSetup: createDataSetupMock,
createStart: createDataStartMock,
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,19 @@
import { i18n } from '@kbn/i18n';
// @ts-ignore
import { ObjDefine } from './obj_define';
// @ts-ignore
import { shortenDottedString } from '../../../../../core_plugins/kibana/common/utils/shorten_dotted_string';
import { IndexPattern } from '../index_patterns';
import { getNotifications, getFieldFormats } from '../services';

import {
FieldFormat,
getKbnFieldType,
IFieldType,
getKbnFieldType,
IFieldSubType,
} from '../../../../../../plugins/data/public';
FieldFormat,
shortenDottedString,
} from '../../../common';

export type FieldSpec = Record<string, any>;

/** @deprecated
* Please use IFieldType instead
* */
export type FieldType = IFieldType;

export class Field implements FieldType {
export class Field implements IFieldType {
name: string;
type: string;
script?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@

import { findIndex } from 'lodash';
import { IndexPattern } from '../index_patterns';
import { Field, FieldType, FieldSpec } from './field';
import { IFieldType } from '../../../common';
import { Field, FieldSpec } from './field';

type FieldMap = Map<Field['name'], Field>;

export interface FieldListInterface extends Array<Field> {
getByName(name: Field['name']): Field | undefined;
getByType(type: Field['type']): Field[];
add(field: FieldSpec): void;
remove(field: FieldType): void;
remove(field: IFieldType): void;
}

export class FieldList extends Array<Field> implements FieldListInterface {
Expand All @@ -42,7 +43,7 @@ export class FieldList extends Array<Field> implements FieldListInterface {
}
this.groups.get(field.type)!.set(field.name, field);
};
private removeByGroup = (field: FieldType) => this.groups.get(field.type)!.delete(field.name);
private removeByGroup = (field: IFieldType) => this.groups.get(field.type)!.delete(field.name);

constructor(indexPattern: IndexPattern, specs: FieldSpec[] = [], shortDotsEnable = false) {
super();
Expand All @@ -61,7 +62,7 @@ export class FieldList extends Array<Field> implements FieldListInterface {
this.setByGroup(newField);
};

remove = (field: FieldType) => {
remove = (field: IFieldType) => {
this.removeByGroup(field);
this.byName.delete(field.name);

Expand Down
11 changes: 11 additions & 0 deletions src/plugins/data/public/index_patterns/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
ILLEGAL_CHARACTERS,
validateIndexPattern,
} from './lib';
import { getRoutes, getFromSavedObject } from './utils';
import { flattenHitWrapper, formatHitProvider } from './index_patterns';

export const indexPatterns = {
ILLEGAL_CHARACTERS_KEY,
Expand All @@ -33,4 +35,13 @@ export const indexPatterns = {
ILLEGAL_CHARACTERS,
IndexPatternMissingIndices,
validate: validateIndexPattern,
getRoutes,
getFromSavedObject,
flattenHitWrapper,
formatHitProvider,
};

export { IndexPatternsService } from './index_patterns_service';
export { Field, FieldList, FieldListInterface } from './fields';
export { IndexPattern, IndexPatterns } from './index_patterns';
export { IndexPatternsStart, IndexPatternsSetup } from './types';
Loading

0 comments on commit 3a0d5f4

Please sign in to comment.