Skip to content

Commit

Permalink
Revert "[NP] Move IndexPatterns into the NP (#51199)"
Browse files Browse the repository at this point in the history
This reverts commit 3a0d5f4.
  • Loading branch information
brianseeders committed Nov 30, 2019
1 parent 3a0d5f4 commit ce127d2
Show file tree
Hide file tree
Showing 48 changed files with 158 additions and 211 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ 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 @@ -75,7 +74,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, flattenHitWrapper } from './index_patterns';
export { getFromSavedObject, getRoutes } from './index_patterns';
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,26 @@
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 {
IFieldType,
FieldFormat,
getKbnFieldType,
IFieldType,
IFieldSubType,
FieldFormat,
shortenDottedString,
} from '../../../common';
} from '../../../../../../plugins/data/public';

export type FieldSpec = Record<string, any>;

export class Field implements IFieldType {
/** @deprecated
* Please use IFieldType instead
* */
export type FieldType = IFieldType;

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

import { findIndex } from 'lodash';
import { IndexPattern } from '../index_patterns';
import { IFieldType } from '../../../common';
import { Field, FieldSpec } from './field';
import { Field, FieldType, 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: IFieldType): void;
remove(field: FieldType): void;
}

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

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

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

Expand Down
19 changes: 1 addition & 18 deletions src/legacy/core_plugins/data/public/index_patterns/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,4 @@
* under the License.
*/

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';
export * from './index_patterns_service';
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { IndexPattern } from './index_pattern';

interface PatternCache {
export interface PatternCache {
get: (id: string) => IndexPattern;
set: (id: string, value: IndexPattern) => IndexPattern;
clear: (id: string) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,24 @@
import { defaults, pluck, last, get } from 'lodash';
import { IndexPattern } from './index_pattern';

import { DuplicateField } from '../../../../kibana_utils/public';
import { DuplicateField } from '../../../../../../plugins/kibana_utils/public';
// @ts-ignore
import mockLogStashFields from '../../../../../fixtures/logstash_fields';
import mockLogStashFields from '../../../../../../fixtures/logstash_fields';
// @ts-ignore
import { stubbedSavedObjectIndexPattern } from '../../../../../fixtures/stubbed_saved_object_index_pattern';
import { Field } from '../fields';

import { stubbedSavedObjectIndexPattern } from '../../../../../../fixtures/stubbed_saved_object_index_pattern';
import { Field } from '../index_patterns_service';
import { setNotifications, setFieldFormats } from '../services';

// Temporary disable eslint, will be removed after moving to new platform folder
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { notificationServiceMock } from '../../../../../core/public/notifications/notifications_service.mock';
import { FieldFormatRegisty } from '../../field_formats_provider';
import { notificationServiceMock } from '../../../../../../core/public/notifications/notifications_service.mock';
import { FieldFormatRegisty } from '../../../../../../plugins/data/public';

jest.mock('ui/new_platform');

jest.mock('../../../../kibana_utils/public', () => {
const originalModule = jest.requireActual('../../../../kibana_utils/public');
jest.mock('../../../../../../plugins/kibana_utils/public', () => {
const originalModule = jest.requireActual('../../../../../../plugins/kibana_utils/public');

return {
...originalModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@ import {
expandShorthand,
FieldMappingSpec,
MappingObject,
} from '../../../../kibana_utils/public';
} from '../../../../../../plugins/kibana_utils/public';

import { ES_FIELD_TYPES, KBN_FIELD_TYPES, IIndexPattern, IFieldType } from '../../../common';

import { findByTitle, getRoutes } from '../utils';
import { indexPatterns } from '../';
import { Field, FieldList, FieldListInterface } from '../fields';
import {
ES_FIELD_TYPES,
KBN_FIELD_TYPES,
IIndexPattern,
indexPatterns,
} from '../../../../../../plugins/data/public';

import { findIndexPatternByTitle, getRoutes } from '../utils';
import { Field, FieldList, FieldListInterface, FieldType } from '../fields';
import { createFieldsFetcher } from './_fields_fetcher';
import { formatHitProvider } from './format_hit';
import { flattenHitWrapper } from './flatten_hit';
Expand All @@ -42,6 +46,11 @@ import { getNotifications, getFieldFormats } from '../services';
const MAX_ATTEMPTS_TO_RESOLVE_CONFLICTS = 3;
const type = 'index-pattern';

/** @deprecated
* Please use IIndexPattern instead
* */
export type StaticIndexPattern = IIndexPattern;

export class IndexPattern implements IIndexPattern {
[key: string]: any;

Expand Down Expand Up @@ -287,7 +296,7 @@ export class IndexPattern implements IIndexPattern {
await this.save();
}

removeScriptedField(field: IFieldType) {
removeScriptedField(field: FieldType) {
this.fields.remove(field);
return this.save();
}
Expand Down Expand Up @@ -375,7 +384,10 @@ export class IndexPattern implements IIndexPattern {
return response.id;
};

const potentialDuplicateByTitle = await findByTitle(this.savedObjectsClient, this.title);
const potentialDuplicateByTitle = await findIndexPatternByTitle(
this.savedObjectsClient,
this.title
);
// If there is potentially duplicate title, just create it
if (!potentialDuplicateByTitle) {
return await _create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { setup } from 'test_utils/http_test_setup';
import { setup } from '../../../../../../test_utils/public/http_test_setup';

export const { http } = setup(injectedMetadata => {
injectedMetadata.getBasePath.mockReturnValue('/hola/daro/');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

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

const API_BASE_URL: string = `/api/index_patterns/`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
* under the License.
*/

import { IndexPatternsService } from './index_patterns_service';
import { IndexPatternsService, IndexPatternsSetup } from '.';
import { flattenHitWrapper } from './index_patterns';
import { IndexPatternsSetup } from './types';

type IndexPatternsServiceClientContract = PublicMethodsOf<IndexPatternsService>;

Expand All @@ -34,7 +33,11 @@ const createSetupContractMock = () => {
flattenHitWrapper: jest.fn().mockImplementation(flattenHitWrapper),
formatHitProvider: jest.fn(),
indexPatterns: jest.fn() as any,
IndexPatternSelect: jest.fn(),
__LEGACY: {
// For BWC we must temporarily export the class implementation of Field,
// which is only used externally by the Index Pattern UI.
FieldImpl: jest.fn(),
},
};

return setupContract;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,19 @@ import {
HttpServiceBase,
NotificationsStart,
} from 'src/core/public';
import { FieldFormatsStart } from '../field_formats_provider';
import { FieldFormatsStart } from '../../../../../plugins/data/public';
import { Field, FieldList, FieldListInterface, FieldType } from './fields';
import { setNotifications, setFieldFormats } from './services';
import { IndexPatterns } from './index_patterns';

interface IndexPatternDependencies {
import {
createFlattenHitWrapper,
formatHitProvider,
IndexPattern,
IndexPatterns,
StaticIndexPattern,
} from './index_patterns';

export interface IndexPatternDependencies {
uiSettings: IUiSettingsClient;
savedObjectsClient: SavedObjectsClientContract;
http: HttpServiceBase;
Expand All @@ -44,8 +52,16 @@ export class IndexPatternsService {
private setupApi: any;

public setup() {
this.setupApi = {};

this.setupApi = {
FieldList,
flattenHitWrapper: createFlattenHitWrapper(),
formatHitProvider,
__LEGACY: {
// For BWC we must temporarily export the class implementation of Field,
// which is only used externally by the Index Pattern UI.
FieldImpl: Field,
},
};
return this.setupApi;
}

Expand All @@ -60,6 +76,7 @@ export class IndexPatternsService {
setFieldFormats(fieldFormats);

return {
...this.setupApi,
indexPatterns: new IndexPatterns(uiSettings, savedObjectsClient, http),
};
}
Expand All @@ -68,3 +85,20 @@ export class IndexPatternsService {
// nothing to do here yet
}
}

// static code

/** @public */
export { getFromSavedObject, getRoutes } from './utils';

// types

/** @internal */
export type IndexPatternsSetup = ReturnType<IndexPatternsService['setup']>;
export type IndexPatternsStart = ReturnType<IndexPatternsService['start']>;

/** @public */
export { IndexPattern, IndexPatterns, StaticIndexPattern, Field, FieldType, FieldListInterface };

/** @public */
export { findIndexPatternByTitle } from './utils';
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/

import { NotificationsStart } from 'src/core/public';
import { createGetterSetter } from '../../../kibana_utils/public';
import { FieldFormatsStart } from '../field_formats_provider';
import { createGetterSetter } from '../../../../../plugins/kibana_utils/public';
import { FieldFormatsStart } from '../../../../../plugins/data/public';

export const [getNotifications, setNotifications] = createGetterSetter<NotificationsStart>(
'Notifications'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
*/

import { find, get } from 'lodash';
import { SavedObjectsClientContract, SimpleSavedObject } from 'src/core/public';

import { SavedObjectsClientContract, SimpleSavedObject } from '../../../../../core/public';

/**
* Returns an object matching a given title
Expand All @@ -27,7 +28,7 @@ import { SavedObjectsClientContract, SimpleSavedObject } from 'src/core/public';
* @param title {string}
* @returns {Promise<SimpleSavedObject|undefined>}
*/
export async function findByTitle(
export async function findIndexPatternByTitle(
client: SavedObjectsClientContract,
title: string
): Promise<SimpleSavedObject<any> | void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@
* under the License.
*/

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

/**
* 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.');
function createDataSetupMock() {
return {
indexPatterns: indexPatternsServiceMock.createSetupContract(),
};
}

function createDataStartMock() {
return {};
}

export const dataPluginMock = {
createSetup: createDataSetupMock,
createStart: createDataStartMock,
};
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 '../../../';
import { getFromSavedObject } from '../../../index_patterns';

export async function fetchIndexPatterns(
savedObjectsClient: SavedObjectsClientContract,
Expand Down
Loading

0 comments on commit ce127d2

Please sign in to comment.