Skip to content

Commit

Permalink
Merge branch 'np-migration-followups' into vis-type-timeseries-np-mig…
Browse files Browse the repository at this point in the history
…ration
  • Loading branch information
Kerry350 committed Dec 9, 2019
2 parents 54d785f + 4bd6fc5 commit d310ec2
Show file tree
Hide file tree
Showing 88 changed files with 261 additions and 527 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ core: {
i18n: I18nStart;
notifications: NotificationsStart;
overlays: OverlayStart;
savedObjects: SavedObjectsStart;
uiSettings: IUiSettingsClient;
injectedMetadata: {
getInjectedVar: (name: string, defaultValue?: any) => unknown;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ export interface AppMountContext

| Property | Type | Description |
| --- | --- | --- |
| [core](./kibana-plugin-public.appmountcontext.core.md) | <code>{</code><br/><code> application: Pick&lt;ApplicationStart, 'capabilities' &#124; 'navigateToApp'&gt;;</code><br/><code> chrome: ChromeStart;</code><br/><code> docLinks: DocLinksStart;</code><br/><code> http: HttpStart;</code><br/><code> i18n: I18nStart;</code><br/><code> notifications: NotificationsStart;</code><br/><code> overlays: OverlayStart;</code><br/><code> uiSettings: IUiSettingsClient;</code><br/><code> injectedMetadata: {</code><br/><code> getInjectedVar: (name: string, defaultValue?: any) =&gt; unknown;</code><br/><code> };</code><br/><code> }</code> | Core service APIs available to mounted applications. |
| [core](./kibana-plugin-public.appmountcontext.core.md) | <code>{</code><br/><code> application: Pick&lt;ApplicationStart, 'capabilities' &#124; 'navigateToApp'&gt;;</code><br/><code> chrome: ChromeStart;</code><br/><code> docLinks: DocLinksStart;</code><br/><code> http: HttpStart;</code><br/><code> i18n: I18nStart;</code><br/><code> notifications: NotificationsStart;</code><br/><code> overlays: OverlayStart;</code><br/><code> savedObjects: SavedObjectsStart;</code><br/><code> uiSettings: IUiSettingsClient;</code><br/><code> injectedMetadata: {</code><br/><code> getInjectedVar: (name: string, defaultValue?: any) =&gt; unknown;</code><br/><code> };</code><br/><code> }</code> | Core service APIs available to mounted applications. |

3 changes: 3 additions & 0 deletions src/core/public/application/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { OverlayStart } from '../overlays';
import { PluginOpaqueId } from '../plugins';
import { IUiSettingsClient } from '../ui_settings';
import { RecursiveReadonly } from '../../utils';
import { SavedObjectsStart } from '../saved_objects';

/** @public */
export interface AppBase {
Expand Down Expand Up @@ -118,6 +119,8 @@ export interface AppMountContext {
notifications: NotificationsStart;
/** {@link OverlayStart} */
overlays: OverlayStart;
/** {@link SavedObjectsStart} */
savedObjects: SavedObjectsStart;
/** {@link IUiSettingsClient} */
uiSettings: IUiSettingsClient;
/**
Expand Down
1 change: 1 addition & 0 deletions src/core/public/core_system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ export class CoreSystem {
i18n,
notifications,
overlays,
savedObjects,
uiSettings,
injectedMetadata: pick(injectedMetadata, ['getInjectedVar']),
}));
Expand Down
1 change: 1 addition & 0 deletions src/core/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export interface AppMountContext {
i18n: I18nStart;
notifications: NotificationsStart;
overlays: OverlayStart;
savedObjects: SavedObjectsStart;
uiSettings: IUiSettingsClient;
injectedMetadata: {
getInjectedVar: (name: string, defaultValue?: any) => unknown;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
applyFiltersPopover,
changeTimeFilter,
extractTimeFilter,
IndexPatternsStart,
IndexPatternsContract,
} from '../../../../../../plugins/data/public';

export const GLOBAL_APPLY_FILTER_ACTION = 'GLOBAL_APPLY_FILTER_ACTION';
Expand All @@ -50,7 +50,7 @@ export function createFilterAction(
overlays: CoreStart['overlays'],
filterManager: FilterManager,
timeFilter: TimefilterContract,
indexPatternsService: IndexPatternsStart
indexPatternsService: IndexPatternsContract
): IAction<ActionContext> {
return createAction<ActionContext>({
type: GLOBAL_APPLY_FILTER_ACTION,
Expand All @@ -75,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.get(filter.meta.index!);
})
);

Expand Down
12 changes: 3 additions & 9 deletions src/legacy/core_plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

// /// Define plugin function
import { DataPlugin as Plugin, DataSetup, DataStart } from './plugin';
import { DataPlugin as Plugin, DataStart } from './plugin';

export function plugin() {
return new Plugin();
Expand All @@ -27,15 +27,9 @@ export function plugin() {
// /// Export types & static code

/** @public types */
export { DataSetup, DataStart };
export { DataStart };

export {
Field,
FieldType,
FieldListInterface,
IndexPattern,
IndexPatterns,
} from './index_patterns';
export { Field, FieldType, IFieldList, IndexPattern } from './index_patterns';
export { SearchBar, SearchBarProps } from './search';
export {
SavedQueryAttributes,
Expand Down
10 changes: 3 additions & 7 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,17 @@
* under the License.
*/

import { IFieldType, IIndexPattern, indexPatterns } from '../../../../../plugins/data/public';
import { IFieldType, 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,
IFieldList,
IndexPattern,
IndexPatterns,
IndexPatternsStart,
IndexPatternsSetup,
IndexPatternsService,
IndexPatternsContract,
} from '../../../../../plugins/data/public';
49 changes: 10 additions & 39 deletions src/legacy/core_plugins/data/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import { CoreSetup, CoreStart, Plugin } from 'kibana/public';
import { createSearchBar, StatetfulSearchBarProps } from './search';
import { IndexPatternsService, IndexPatternsSetup, IndexPatternsStart } from './index_patterns';
import { Storage, IStorageWrapper } from '../../../../../src/plugins/kibana_utils/public';
import { DataPublicPluginStart } from '../../../../plugins/data/public';
import { initLegacyModule } from './shim/legacy_module';
Expand All @@ -30,27 +29,20 @@ import {
} from './filter/action/apply_filter_action';
import { APPLY_FILTER_TRIGGER } from '../../../../plugins/embeddable/public';

// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { setFieldFormats } from '../../../../plugins/data/public/services';

export interface DataPluginStartDependencies {
data: DataPublicPluginStart;
uiActions: IUiActionsSetup;
}

/**
* Interface for this plugin's returned `setup` contract.
*
* @public
*/
export interface DataSetup {
indexPatterns: IndexPatternsSetup;
}

/**
* Interface for this plugin's returned `start` contract.
*
* @public
*/
export interface DataStart {
indexPatterns: IndexPatternsStart;
ui: {
SearchBar: React.ComponentType<StatetfulSearchBarProps>;
};
Expand All @@ -68,34 +60,17 @@ export interface DataStart {
* or static code.
*/

export class DataPlugin implements Plugin<DataSetup, DataStart, {}, DataPluginStartDependencies> {
private readonly indexPatterns: IndexPatternsService = new IndexPatternsService();

private setupApi!: DataSetup;
export class DataPlugin implements Plugin<void, DataStart, {}, DataPluginStartDependencies> {
private storage!: IStorageWrapper;

public setup(core: CoreSetup): DataSetup {
public setup(core: CoreSetup) {
this.storage = new Storage(window.localStorage);

this.setupApi = {
indexPatterns: this.indexPatterns.setup(),
};

return this.setupApi;
}

public start(core: CoreStart, { data, uiActions }: DataPluginStartDependencies): DataStart {
const { uiSettings, http, notifications, savedObjects } = core;

const indexPatternsService = this.indexPatterns.start({
uiSettings,
savedObjectsClient: savedObjects.client,
http,
notifications,
fieldFormats: data.fieldFormats,
});

initLegacyModule(indexPatternsService.indexPatterns);
// This is required for when Angular code uses Field and FieldList.
setFieldFormats(data.fieldFormats);
initLegacyModule(data.indexPatterns);

const SearchBar = createSearchBar({
core,
Expand All @@ -108,22 +83,18 @@ export class DataPlugin implements Plugin<DataSetup, DataStart, {}, DataPluginSt
core.overlays,
data.query.filterManager,
data.query.timefilter.timefilter,
indexPatternsService
data.indexPatterns
)
);

uiActions.attachAction(APPLY_FILTER_TRIGGER, GLOBAL_APPLY_FILTER_ACTION);

return {
...this.setupApi!,
indexPatterns: indexPatternsService,
ui: {
SearchBar,
},
};
}

public stop() {
this.indexPatterns.stop();
}
public stop() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
ExpressionFunction,
KibanaDatatableColumn,
} from 'src/plugins/expressions/public';
import { npStart } from 'ui/new_platform';
import {
SearchSource,
SearchSourceContract,
Expand All @@ -46,7 +47,6 @@ import { calculateObjectHash } from '../../../../visualizations/public';
import { getTime } from '../../../../../ui/public/timefilter';
// @ts-ignore
import { tabifyAggResponse } from '../../../../../ui/public/agg_response/tabify/tabify';
import { start as data } from '../../../../data/public/legacy';
import { PersistedState } from '../../../../../ui/public/persisted_state';
import { Adapters } from '../../../../../../plugins/inspector/public';

Expand Down Expand Up @@ -261,7 +261,7 @@ export const esaggs = (): ExpressionFunction<typeof name, Context, Arguments, Re
async fn(context, args, { inspectorAdapters, abortSignal }) {
const $injector = await chrome.dangerouslyGetActiveInjector();
const Private: Function = $injector.get('Private');
const { indexPatterns } = data.indexPatterns;
const { indexPatterns } = npStart.plugins.data;
const queryFilter = Private(FilterBarQueryFilterProvider);

const aggConfigsState = JSON.parse(args.aggConfigs);
Expand Down
4 changes: 2 additions & 2 deletions src/legacy/core_plugins/data/public/shim/legacy_module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import { once } from 'lodash';

// @ts-ignore
import { uiModules } from 'ui/modules';
import { IndexPatterns } from '../';
import { IndexPatternsContract } from 'src/plugins/data/public';

/** @internal */
export const initLegacyModule = once((indexPatterns: IndexPatterns): void => {
export const initLegacyModule = once((indexPatterns: IndexPatternsContract): void => {
uiModules.get('kibana/index_patterns').value('indexPatterns', indexPatterns);
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { ControlEditor } from './control_editor';
import { addControl, moveControl, newControl, removeControl, setControl } from '../../editor_utils';
import { getLineageMap, getParentCandidates } from '../../lineage';
import { injectI18n, FormattedMessage } from '@kbn/i18n/react';
import { start as data } from '../../../../../core_plugins/data/public/legacy';
import { npStart } from 'ui/new_platform';

import {
EuiButton,
Expand All @@ -41,7 +41,7 @@ class ControlsTabUi extends Component {
}

getIndexPattern = async (indexPatternId) => {
return await data.indexPatterns.indexPatterns.get(indexPatternId);
return await npStart.plugins.data.indexPatterns.get(indexPatternId);
}

onChange = value => this.props.setValue('controls', value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import { createSearchSource } from './create_search_source';
import { i18n } from '@kbn/i18n';
import { npStart } from 'ui/new_platform';
import chrome from 'ui/chrome';
import { start as data } from '../../../../core_plugins/data/public/legacy';

function getEscapedQuery(query = '') {
// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-regexp-query.html#_standard_operators
Expand Down Expand Up @@ -173,7 +172,7 @@ class ListControl extends Control {
export async function listControlFactory(controlParams, useTimeFilter, SearchSource) {
let indexPattern;
try {
indexPattern = await data.indexPatterns.indexPatterns.get(controlParams.indexPattern);
indexPattern = await npStart.plugins.data.indexPatterns.get(controlParams.indexPattern);

// dynamic options are only allowed on String fields but the setting defaults to true so it could
// be enabled for non-string fields (since UI input is hidden for non-string fields).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,20 @@ jest.mock('ui/new_platform', () => ({
getAppFilters: jest.fn().mockImplementation(() => ([])),
getGlobalFilters: jest.fn().mockImplementation(() => ([])),
}
},
indexPatterns: {
get: () => ({
fields: { getByName: name => {
const fields = { myField: { name: 'myField' } };
return fields[name];
} }
}),
}
}
},
},
}));

jest.mock('../../../../core_plugins/data/public/legacy', () => ({
start: {
indexPatterns: {
indexPatterns: {
get: () => ({
fields: { getByName: name => {
const fields = { myField: { name: 'myField' } };
return fields[name];
} }
}),
}
},
}
}));

chrome.getInjected.mockImplementation((key) => {
switch(key) {
case 'autocompleteTimeout': return 1000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
import { RangeFilterManager } from './filter_manager/range_filter_manager';
import { createSearchSource } from './create_search_source';
import { i18n } from '@kbn/i18n';
import { start as data } from '../../../../core_plugins/data/public/legacy';
import { npStart } from 'ui/new_platform';

const minMaxAgg = (field) => {
Expand Down Expand Up @@ -103,7 +102,7 @@ class RangeControl extends Control {
export async function rangeControlFactory(controlParams, useTimeFilter, SearchSource) {
let indexPattern;
try {
indexPattern = await data.indexPatterns.indexPatterns.get(controlParams.indexPattern);
indexPattern = await npStart.plugins.data.indexPatterns.get(controlParams.indexPattern);
} catch (err) {
// ignore not found error and return control so it can be displayed in disabled state.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,20 @@ jest.mock('ui/new_platform', () => ({
getAppFilters: jest.fn().mockImplementation(() => ([])),
getGlobalFilters: jest.fn().mockImplementation(() => ([])),
}
},
indexPatterns: {
get: () => ({
fields: { getByName: name => {
const fields = { myNumberField: { name: 'myNumberField' } };
return fields[name];
}
} }),
}
}
},
},
}));

jest.mock('../../../../core_plugins/data/public/legacy', () => ({
start: {
indexPatterns: {
indexPatterns: {
get: () => ({
fields: { getByName: name => {
const fields = { myNumberField: { name: 'myNumberField' } };
return fields[name];
}
} }),
}
},
}
}));

describe('fetch', () => {
const controlParams = {
id: '1',
Expand Down
Loading

0 comments on commit d310ec2

Please sign in to comment.