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

[NP] Move IndexPatterns into the NP #51199

Merged
merged 35 commits into from
Nov 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
4886bdd
Make a copy of index_patterns module inside NP
Nov 14, 2019
10f3d6f
Sync changes of index patterns
Nov 20, 2019
c226101
Merge remote-tracking branch 'upstream/master' into move-index-patter…
Nov 21, 2019
ba60d78
Merge remote-tracking branch 'upstream/master' into move-index-patter…
Nov 21, 2019
1e87986
Merge remote-tracking branch 'upstream/master' into move-index-patter…
Nov 22, 2019
4bd2e3f
Merge remote-tracking branch 'upstream/master' into move-index-patter…
Nov 25, 2019
09a0e6a
Remove UI component from service
Nov 25, 2019
4bfbf23
Merge remote-tracking branch 'upstream/master' into move-index-patter…
Nov 25, 2019
cd283bb
Remove redundant exports from index_patterns
Nov 25, 2019
da1978f
Sync old index_patters changes
Nov 25, 2019
3c0f5cf
Merge remote-tracking branch 'upstream/master' into move-index-patter…
Nov 26, 2019
ff1ad34
Make common namespace of IndexPattern
Nov 26, 2019
30243de
Make re-exports of old IndexPatter dependencies
Nov 26, 2019
d6e7d96
Remove utils and error of the old indexPattern
Nov 26, 2019
0311279
Merge remote-tracking branch 'upstream/master' into move-index-patter…
Nov 26, 2019
0fc81de
Merge remote-tracking branch 'upstream/master' into move-index-patter…
Nov 27, 2019
22ab71b
Plug InterPatternService in data plugin
Nov 27, 2019
8dde808
Make shortenDotString in new data plugin
Nov 27, 2019
794ebf3
Remove field folder
Nov 27, 2019
b9ba7f9
Merge remote-tracking branch 'upstream/master' into move-index-patter…
Nov 27, 2019
4596b06
Fix wrong merge
Nov 27, 2019
f247430
Remove index_pattern folder
Nov 27, 2019
66b306c
Merge remote-tracking branch 'upstream/master' into move-index-patter…
Nov 28, 2019
6683303
Merge remote-tracking branch 'upstream/master' into move-index-patter…
Nov 28, 2019
6213412
Remove _LEGACY from service
Nov 28, 2019
483eb75
Remove static code from service
Nov 28, 2019
1d121f6
Fix start contract
Nov 28, 2019
8fda8dd
Remove services from the old plugin
Nov 28, 2019
928ae7a
Remove index_patterns_service
Nov 28, 2019
befffec
Fix filter.meta.index type
Nov 28, 2019
2ba9d92
Fix reviews
Nov 28, 2019
676f2be
Fix type error
Nov 28, 2019
5b70c21
Merge branch 'master' into move-index-patterns-to-new-plugins-2
elasticmachine Nov 28, 2019
f71ee5f
Merge remote-tracking branch 'upstream/master' into move-index-patter…
Nov 29, 2019
a3df345
Merge branch 'move-index-patterns-to-new-plugins-2' of github.com:Avi…
Nov 29, 2019
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
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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that shortenDottedString is still going to be leaked into the public contract since data/public/index.ts does an export * from '../common';

I'm going to open a follow-up PR to address this more widely, so we can ensure nothing is being exported out of common that doesn't belong in our public API

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