Skip to content

Commit

Permalink
[ML] MOAR NP migration.
Browse files Browse the repository at this point in the history
  • Loading branch information
walterra committed Feb 25, 2020
1 parent 1f078cd commit fe32903
Show file tree
Hide file tree
Showing 27 changed files with 104 additions and 254 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/

jest.mock('ui/new_platform');

export function XJsonMode() {}
export function setDependencyCache() {}
export const useRequest = () => ({
Expand Down
48 changes: 27 additions & 21 deletions x-pack/legacy/plugins/transform/public/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
*/

import React, { useContext, FC } from 'react';
import { unmountComponentAtNode } from 'react-dom';
import { render } from 'react-dom';
import { Redirect, Route, Switch } from 'react-router-dom';
import { HashRouter, Redirect, Route, Switch } from 'react-router-dom';

import { FormattedMessage } from '@kbn/i18n/react';

Expand All @@ -22,8 +23,7 @@ import { TransformManagementSection } from './sections/transform_management';

export const App: FC = () => {
const { apiError } = useContext(AuthorizationContext);

if (apiError) {
if (apiError !== null) {
return (
<SectionError
title={
Expand All @@ -39,33 +39,39 @@ export const App: FC = () => {

return (
<div data-test-subj="transformApp">
<Switch>
<Route
path={`${CLIENT_BASE_PATH}/${SECTION_SLUG.CLONE_TRANSFORM}/:transformId`}
component={CloneTransformSection}
/>
<Route
path={`${CLIENT_BASE_PATH}/${SECTION_SLUG.CREATE_TRANSFORM}/:savedObjectId`}
component={CreateTransformSection}
/>
<Route
exact
path={`${CLIENT_BASE_PATH}/${SECTION_SLUG.HOME}`}
component={TransformManagementSection}
/>
<Redirect from={`${CLIENT_BASE_PATH}`} to={`${CLIENT_BASE_PATH}/${SECTION_SLUG.HOME}`} />
</Switch>
<HashRouter>
<Switch>
<Route
path={`${CLIENT_BASE_PATH}${SECTION_SLUG.CLONE_TRANSFORM}/:transformId`}
component={CloneTransformSection}
/>
<Route
path={`${CLIENT_BASE_PATH}${SECTION_SLUG.CREATE_TRANSFORM}/:savedObjectId`}
component={CreateTransformSection}
/>
<Route
exact
path={`${CLIENT_BASE_PATH}${SECTION_SLUG.HOME}`}
component={TransformManagementSection}
/>
<Redirect from={`${CLIENT_BASE_PATH}`} to={`${CLIENT_BASE_PATH}${SECTION_SLUG.HOME}`} />
</Switch>
</HashRouter>
</div>
);
};

export const renderReact = (elem: Element, appDependencies: AppDependencies) => {
export const renderApp = (element: HTMLElement, appDependencies: AppDependencies) => {
const Providers = getAppProviders(appDependencies);

render(
<Providers>
<App />
</Providers>,
elem
element
);

return () => {
unmountComponentAtNode(element);
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ export function getDiscoverUrl(indexPatternId: string, baseUrl: string): string
}

export const RedirectToTransformManagement: FC = () => (
<Redirect from={`${CLIENT_BASE_PATH}`} to={`${CLIENT_BASE_PATH}/${SECTION_SLUG.HOME}`} />
<Redirect from={`${CLIENT_BASE_PATH}`} to={`${CLIENT_BASE_PATH}${SECTION_SLUG.HOME}`} />
);

export const RedirectToCreateTransform: FC<{ savedObjectId: string }> = ({ savedObjectId }) => (
<Redirect to={`${CLIENT_BASE_PATH}/${SECTION_SLUG.CREATE_TRANSFORM}/${savedObjectId}`} />
<Redirect to={`${CLIENT_BASE_PATH}${SECTION_SLUG.CREATE_TRANSFORM}/${savedObjectId}`} />
);
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { EuiCallOut, EuiSpacer } from '@elastic/eui';
import React, { Fragment } from 'react';
import { EuiCallOut } from '@elastic/eui';
import React from 'react';

interface Props {
title: React.ReactNode;
error: {
data: {
error: string;
cause?: string[];
message?: string;
};
};
error: Error | null;
actions?: JSX.Element;
}

Expand All @@ -25,25 +19,12 @@ export const SectionError: React.FunctionComponent<Props> = ({
actions,
...rest
}) => {
const {
error: errorString,
cause, // wrapEsError() on the server adds a "cause" array
message,
} = error.data;
const errorMessage =
error?.message !== undefined ? error.message : JSON.stringify(error, null, 2);

return (
<EuiCallOut title={title} color="danger" iconType="alert" {...rest}>
{cause ? message || errorString : <p>{message || errorString}</p>}
{cause && (
<Fragment>
<EuiSpacer size="s" />
<ul>
{cause.map((causeMsg, i) => (
<li key={i}>{causeMsg}</li>
))}
</ul>
</Fragment>
)}
<pre>{errorMessage}</pre>
{actions ? actions : null}
</EuiCallOut>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { getAppProviders } from '../app_dependencies';
import { ToastNotificationText } from './toast_notification_text';

jest.mock('../../shared_imports');
jest.mock('ui/new_platform');

describe('ToastNotificationText', () => {
test('should render the text as plain text', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

export const CLIENT_BASE_PATH = '/management/elasticsearch/transform';
export const CLIENT_BASE_PATH = '/management/elasticsearch/transform/';

export enum SECTION_SLUG {
HOME = 'transform_management',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,9 @@ import React, { createContext } from 'react';
import { useRequest } from '../../../services/http/use_request';
import { hasPrivilegeFactory, Capabilities, Privileges } from './common';

interface ApiError {
data: {
error: string;
cause?: string[];
message?: string;
};
}

interface Authorization {
isLoading: boolean;
apiError: ApiError | null;
apiError: Error | null;
privileges: Privileges;
capabilities: Capabilities;
}
Expand Down Expand Up @@ -58,7 +50,7 @@ export const AuthorizationProvider = ({ privilegesEndpoint, children }: Props) =
isLoading,
privileges: isLoading ? { ...initialValue.privileges } : privilegesData,
capabilities: { ...initialCapabalities },
apiError: error ? (error as ApiError) : null,
apiError: error ? (error as Error) : null,
};

const hasPrivilege = hasPrivilegeFactory(value.privileges);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import { getPivotQuery } from '../../../../common';

import { SourceIndexPreview } from './source_index_preview';

jest.mock('ui/new_platform');

// workaround to make React.memo() work with enzyme
jest.mock('react', () => {
const r = jest.requireActual('react');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import { KibanaContext } from '../../../../lib/kibana';

import { StepCreateForm } from './step_create_form';

jest.mock('ui/new_platform');

// workaround to make React.memo() work with enzyme
jest.mock('react', () => {
const r = jest.requireActual('react');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import {

import { PivotPreview } from './pivot_preview';

jest.mock('ui/new_platform');

// workaround to make React.memo() work with enzyme
jest.mock('react', () => {
const r = jest.requireActual('react');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import {
} from '../../../../common';
import { StepDefineForm, getAggNameConflictToastMessages } from './step_define_form';

jest.mock('ui/new_platform');

// workaround to make React.memo() work with enzyme
jest.mock('react', () => {
const r = jest.requireActual('react');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import {
import { StepDefineExposedState } from './step_define_form';
import { StepDefineSummary } from './step_define_summary';

jest.mock('ui/new_platform');

// workaround to make React.memo() work with enzyme
jest.mock('react', () => {
const r = jest.requireActual('react');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import React from 'react';

import { CreateTransformButton } from './create_transform_button';

jest.mock('ui/new_platform');

jest.mock('../../../../../shared_imports');

describe('Transform: Transform List <CreateTransformButton />', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const CloneAction: FC<CloneActionProps> = ({ itemId }) => {
});

function clickHandler() {
history.push(`${CLIENT_BASE_PATH}/${SECTION_SLUG.CLONE_TRANSFORM}/${itemId}`);
history.push(`${CLIENT_BASE_PATH}${SECTION_SLUG.CLONE_TRANSFORM}/${itemId}`);
}

const cloneButton = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { DeleteAction } from './action_delete';
import transformListRow from '../../../../common/__mocks__/transform_list_row.json';

jest.mock('ui/new_platform');

jest.mock('../../../../../shared_imports');

describe('Transform: Transform List Actions <DeleteAction />', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { StartAction } from './action_start';
import transformListRow from '../../../../common/__mocks__/transform_list_row.json';

jest.mock('ui/new_platform');

jest.mock('../../../../../shared_imports');

describe('Transform: Transform List Actions <StartAction />', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { StopAction } from './action_stop';
import transformListRow from '../../../../common/__mocks__/transform_list_row.json';

jest.mock('ui/new_platform');

jest.mock('../../../../../shared_imports');

describe('Transform: Transform List Actions <StopAction />', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

import { getActions } from './actions';

jest.mock('ui/new_platform');

jest.mock('../../../../../shared_imports');

describe('Transform: Transform List Actions', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

import { getColumns } from './columns';

jest.mock('ui/new_platform');

jest.mock('../../../../../shared_imports');

describe('Transform: Job List Columns', () => {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
import { shallow } from 'enzyme';
import React from 'react';

import './transform_list.test.mocks';
import { TransformList } from './transform_list';

jest.mock('ui/new_platform');

jest.mock('../../../../../shared_imports');

describe('Transform: Transform List <TransformList />', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import React from 'react';

import { TransformManagementSection } from './transform_management_section';

jest.mock('ui/new_platform');
jest.mock('../../../shared_imports');

describe('Transform: <TransformManagementSection />', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@
* you may not use this file except in compliance with the Elastic License.
*/

import {
SendRequestConfig,
SendRequestResponse,
UseRequestConfig,
sendRequest as _sendRequest,
useRequest as _useRequest,
} from '../../../shared_imports';
import { httpService } from './index';
import { UseRequestConfig, useRequest as _useRequest } from '../../../shared_imports';

export const sendRequest = (config: SendRequestConfig): Promise<Partial<SendRequestResponse>> => {
return _sendRequest(httpService.httpClient, config);
};
import { useAppDependencies } from '../../app_dependencies';

export const useRequest = (config: UseRequestConfig) => {
return _useRequest(httpService.httpClient, config);
const {
core: { http },
} = useAppDependencies();
return _useRequest(http, config);
};
Loading

0 comments on commit fe32903

Please sign in to comment.