Skip to content

Commit

Permalink
[ML] Rename shared imports.
Browse files Browse the repository at this point in the history
  • Loading branch information
walterra committed Sep 28, 2020
1 parent f503dd4 commit 98223eb
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 24 deletions.
17 changes: 10 additions & 7 deletions x-pack/plugins/ml/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
* you may not use this file except in compliance with the Elastic License.
*/

// Be careful adding exports to this file, it may increase the bundle size of
// the ML plugin's page load bundle. You should either just export types or
// use `getMlSharedImports()` to export static code.

import { PluginInitializer, PluginInitializerContext } from 'kibana/public';
import {
MlPlugin,
Expand Down Expand Up @@ -34,16 +38,15 @@ export type {
RenderCellValue,
} from './shared';

// static exports
// Static exports
export { getSeverityColor, getSeverityType } from '../common/util/anomaly_utils';
export { ANOMALY_SEVERITY } from '../common';

// bundled shared exports
// exported this way so the code doesn't end up in ML's page load bundle
export const getShared = async () => {
// Bundled shared exports
// Exported this way so the code doesn't end up in ML's page load bundle
export const getMlSharedImports = async () => {
return await import('./shared');
};

// Helper to get Type returned by getShared.
// Helper to get Type returned by getMlSharedImports.
type AwaitReturnType<T> = T extends PromiseLike<infer U> ? U : T;
export type GetSharedReturnType = AwaitReturnType<ReturnType<typeof getShared>>;
export type GetMlSharedImportsReturnType = AwaitReturnType<ReturnType<typeof getMlSharedImports>>;
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ export const useRequest = jest.fn(() => ({
}));

// just passing through the reimports
export { getShared } from '../../../ml/public';
export { getMlSharedImports } from '../../../ml/public';
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { renderHook } from '@testing-library/react-hooks';

import { CoreSetup } from 'src/core/public';

import { getShared, UseIndexDataReturnType } from '../../shared_imports';
import { getMlSharedImports, UseIndexDataReturnType } from '../../shared_imports';

import { SimpleQuery } from '../common';

Expand All @@ -34,7 +34,7 @@ const query: SimpleQuery = {

describe('Transform: useIndexData()', () => {
test('indexPattern set triggers loading', async (done) => {
const mlShared = await getShared();
const mlShared = await getMlSharedImports();
const wrapper: FC = ({ children }) => (
<MlSharedContext.Provider value={mlShared}>{children}</MlSharedContext.Provider>
);
Expand Down Expand Up @@ -71,7 +71,7 @@ describe('Transform: <DataGrid /> with useIndexData()', () => {
fields: [] as any[],
} as SearchItems['indexPattern'];

const mlShared = await getShared();
const mlSharedImports = await getMlSharedImports();

const Wrapper = () => {
const {
Expand All @@ -89,7 +89,7 @@ describe('Transform: <DataGrid /> with useIndexData()', () => {
return <DataGrid {...props} />;
};
const { getByText } = render(
<MlSharedContext.Provider value={mlShared}>
<MlSharedContext.Provider value={mlSharedImports}>
<Wrapper />
</MlSharedContext.Provider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ManagementAppMountParams } from '../../../../../src/plugins/management/
import { Storage } from '../../../../../src/plugins/kibana_utils/public';

import { PluginsDependencies } from '../plugin';
import { getShared } from '../shared_imports';
import { getMlSharedImports } from '../shared_imports';

import { AppDependencies } from './app_dependencies';
import { breadcrumbService } from './services/navigation';
Expand Down Expand Up @@ -48,7 +48,7 @@ export async function mountManagementSection(
storage: localStorage,
uiSettings,
history,
ml: await getShared(),
ml: await getMlSharedImports(),
};

const unmountAppCallback = renderApp(element, appDependencies);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jest.mock('../../../../../shared_imports');
jest.mock('../../../../../app/app_dependencies');

import { MlSharedContext } from '../../../../../app/__mocks__/shared_context';
import { getShared } from '../../../../../shared_imports';
import { getMlSharedImports } from '../../../../../shared_imports';

const createMockWebStorage = () => ({
clear: jest.fn(),
Expand All @@ -54,7 +54,7 @@ describe('Transform: <DefinePivotForm />', () => {
// Using the async/await wait()/done() pattern to avoid act() errors.
test('Minimal initialization', async (done) => {
// Arrange
const mlShared = await getShared();
const mlSharedImports = await getMlSharedImports();

const searchItems = {
indexPattern: {
Expand All @@ -74,7 +74,7 @@ describe('Transform: <DefinePivotForm />', () => {
const { getByText } = render(
<I18nProvider>
<KibanaContextProvider services={services}>
<MlSharedContext.Provider value={mlShared}>
<MlSharedContext.Provider value={mlSharedImports}>
<StepDefineForm onChange={jest.fn()} searchItems={searchItems as SearchItems} />
</MlSharedContext.Provider>
</KibanaContextProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ jest.mock('../../../../../shared_imports');
jest.mock('../../../../../app/app_dependencies');

import { MlSharedContext } from '../../../../../app/__mocks__/shared_context';
import { getShared } from '../../../../../shared_imports';
import { getMlSharedImports } from '../../../../../shared_imports';

describe('Transform: <DefinePivotSummary />', () => {
// Using the async/await wait()/done() pattern to avoid act() errors.
test('Minimal initialization', async (done) => {
// Arrange
const mlShared = await getShared();
const mlSharedImports = await getMlSharedImports();

const searchItems = {
indexPattern: {
Expand Down Expand Up @@ -62,7 +62,7 @@ describe('Transform: <DefinePivotSummary />', () => {
};

const { getByText } = render(
<MlSharedContext.Provider value={mlShared}>
<MlSharedContext.Provider value={mlSharedImports}>
<StepDefineSummary formState={formState} searchItems={searchItems as SearchItems} />
</MlSharedContext.Provider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jest.mock('../../../../../shared_imports');
jest.mock('../../../../../app/app_dependencies');

import { MlSharedContext } from '../../../../../app/__mocks__/shared_context';
import { getShared } from '../../../../../shared_imports';
import { getMlSharedImports } from '../../../../../shared_imports';

describe('Transform: Transform List <ExpandedRow />', () => {
// Set timezone to US/Eastern for consistent test results.
Expand All @@ -30,7 +30,7 @@ describe('Transform: Transform List <ExpandedRow />', () => {
});

test('Minimal initialization', async () => {
const mlShared = await getShared();
const mlShared = await getMlSharedImports();
const item: TransformListRow = transformListRow;

const { getByText, getByTestId } = render(
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/transform/public/shared_imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export { XJsonMode } from '@kbn/ace';
export { UseRequestConfig, useRequest } from '../../../../src/plugins/es_ui_shared/public';

export {
getShared,
GetSharedReturnType,
getMlSharedImports,
GetMlSharedImportsReturnType,
UseIndexDataReturnType,
EsSorting,
RenderCellValue,
Expand Down

0 comments on commit 98223eb

Please sign in to comment.