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

[ML] [NP] Removing ui imports #56358

Merged
merged 30 commits into from
Feb 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
5c6e77c
[ML] [NP] Removing ui imports
jgowdyelastic Jan 30, 2020
c8ab315
replacing timefilter and ui context
jgowdyelastic Jan 30, 2020
0fc0cb0
replacing ui/i18n and ui/metadata
jgowdyelastic Jan 31, 2020
1c2f55e
removing ui/system_api
jgowdyelastic Jan 31, 2020
a77c900
removing ui/notify
jgowdyelastic Jan 31, 2020
2e1e62a
removing most ui/new_platform
jgowdyelastic Feb 1, 2020
0b59bd7
fix explorer date format loading
jgowdyelastic Feb 1, 2020
d755475
removing ui/chrome
jgowdyelastic Feb 3, 2020
e7ff021
fixing timebuckets test
jgowdyelastic Feb 3, 2020
a130312
fixing jest tests
jgowdyelastic Feb 3, 2020
20a1fbc
adding http
jgowdyelastic Feb 3, 2020
6243432
testing odd CI type failure
jgowdyelastic Feb 4, 2020
dd332f5
revrting type test changes
jgowdyelastic Feb 4, 2020
424b35d
fixing odd test type error
jgowdyelastic Feb 4, 2020
88fca3a
refactoring dependencies
jgowdyelastic Feb 4, 2020
3f8a4d6
removing injectI18n and using withKibana for context
jgowdyelastic Feb 6, 2020
6f76501
updating components to use kibana context
jgowdyelastic Feb 6, 2020
d0a56e4
re-enabling some tests
jgowdyelastic Feb 6, 2020
d150430
fixing translation strings
jgowdyelastic Feb 6, 2020
ed51a2f
adding comments
jgowdyelastic Feb 6, 2020
3244480
removing commented out code
jgowdyelastic Feb 6, 2020
f0f2786
missing i18n
jgowdyelastic Feb 6, 2020
87af784
fixing rebase conflicts
jgowdyelastic Feb 6, 2020
0689e3f
removing unused ui contexts
jgowdyelastic Feb 7, 2020
e301751
changes based on review
jgowdyelastic Feb 7, 2020
2c76e01
adding text to errors
jgowdyelastic Feb 9, 2020
eed8c87
fixing management plugin
jgowdyelastic Feb 10, 2020
8464f2a
changes based on review
jgowdyelastic Feb 11, 2020
864d199
refeactor after rebase
jgowdyelastic Feb 11, 2020
7f0ae9e
fixing test
jgowdyelastic Feb 11, 2020
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
13 changes: 0 additions & 13 deletions x-pack/legacy/plugins/ml/common/constants/feature_flags.ts

This file was deleted.

1 change: 0 additions & 1 deletion x-pack/legacy/plugins/ml/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export const ml = (kibana: any) => {
category: DEFAULT_APP_CATEGORIES.analyze,
},
styleSheetPaths: resolve(__dirname, 'public/application/index.scss'),
hacks: ['plugins/ml/application/hacks/toggle_app_link_in_nav'],
savedObjectSchemas: {
'ml-telemetry': {
isNamespaceAgnostic: true,
Expand Down
80 changes: 54 additions & 26 deletions x-pack/legacy/plugins/ml/public/application/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,78 @@
import React, { FC } from 'react';
import ReactDOM from 'react-dom';

import 'uiExports/savedObjectTypes';

import 'ui/autoload/all';

// needed to make syntax highlighting work in ace editors
import 'ace';
import { AppMountParameters, CoreStart } from 'kibana/public';
import {
IndexPatternsContract,
Plugin as DataPlugin,
} from '../../../../../../src/plugins/data/public';

import { KibanaConfigTypeFix } from './contexts/kibana';
import { DataPublicPluginStart } from 'src/plugins/data/public';

import { KibanaContextProvider } from '../../../../../../src/plugins/kibana_react/public';
import { setDependencyCache, clearCache } from './util/dependency_cache';

import { MlRouter } from './routing';

export interface MlDependencies extends AppMountParameters {
npData: ReturnType<DataPlugin['start']>;
indexPatterns: IndexPatternsContract;
data: DataPublicPluginStart;
__LEGACY: {
XSRF: string;
APP_URL: string;
};
}

interface AppProps {
coreStart: CoreStart;
indexPatterns: IndexPatternsContract;
deps: MlDependencies;
}

const App: FC<AppProps> = ({ coreStart, indexPatterns }) => {
const config = (coreStart.uiSettings as never) as KibanaConfigTypeFix; // TODO - make this UiSettingsClientContract, get rid of KibanaConfigTypeFix
const App: FC<AppProps> = ({ coreStart, deps }) => {
setDependencyCache({
indexPatterns: deps.data.indexPatterns,
timefilter: deps.data.query.timefilter,
config: coreStart.uiSettings!,
chrome: coreStart.chrome!,
docLinks: coreStart.docLinks!,
toastNotifications: coreStart.notifications.toasts,
overlays: coreStart.overlays,
recentlyAccessed: coreStart.chrome!.recentlyAccessed,
fieldFormats: deps.data.fieldFormats,
autocomplete: deps.data.autocomplete,
basePath: coreStart.http.basePath,
savedObjectsClient: coreStart.savedObjects.client,
XSRF: deps.__LEGACY.XSRF,
APP_URL: deps.__LEGACY.APP_URL,
application: coreStart.application,
http: coreStart.http,
});
deps.onAppLeave(actions => {
clearCache();
return actions.default();
});

const pageDeps = {
indexPatterns: deps.data.indexPatterns,
config: coreStart.uiSettings!,
setBreadcrumbs: coreStart.chrome!.setBreadcrumbs,
};

const services = {
appName: 'ML',
data: deps.data,
...coreStart,
};

const I18nContext = coreStart.i18n.Context;
return (
<MlRouter
config={config}
setBreadcrumbs={coreStart.chrome.setBreadcrumbs}
indexPatterns={indexPatterns}
/>
<I18nContext>
<KibanaContextProvider services={services}>
<MlRouter pageDeps={pageDeps} />
</KibanaContextProvider>
</I18nContext>
);
};

export const renderApp = (
coreStart: CoreStart,
depsStart: object,
{ element, indexPatterns }: MlDependencies
) => {
ReactDOM.render(<App coreStart={coreStart} indexPatterns={indexPatterns} />, element);
export const renderApp = (coreStart: CoreStart, depsStart: object, deps: MlDependencies) => {
ReactDOM.render(<App coreStart={coreStart} deps={deps} />, deps.element);

return () => ReactDOM.unmountComponentAtNode(element);
return () => ReactDOM.unmountComponentAtNode(deps.element);
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@ describe('AnnotationDescriptionList', () => {
});

test('Initialization with annotation.', () => {
const wrapper = shallowWithIntl(
<AnnotationDescriptionList.WrappedComponent
annotation={mockAnnotations[0]}
intl={null as any}
/>
);
const wrapper = shallowWithIntl(<AnnotationDescriptionList annotation={mockAnnotations[0]} />);
expect(wrapper).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,24 @@ import React from 'react';

import { EuiDescriptionList } from '@elastic/eui';

import { InjectedIntl, injectI18n } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
import { Annotation } from '../../../../../common/types/annotations';
import { formatHumanReadableDateTimeSeconds } from '../../../util/date_utils';

interface Props {
annotation: Annotation;
intl: InjectedIntl;
}

export const AnnotationDescriptionList = injectI18n(({ annotation, intl }: Props) => {
export const AnnotationDescriptionList = ({ annotation }: Props) => {
const listItems = [
{
title: intl.formatMessage({
id: 'xpack.ml.timeSeriesExplorer.annotationDescriptionList.jobIdTitle',
title: i18n.translate('xpack.ml.timeSeriesExplorer.annotationDescriptionList.jobIdTitle', {
defaultMessage: 'Job ID',
}),
description: annotation.job_id,
},
{
title: intl.formatMessage({
id: 'xpack.ml.timeSeriesExplorer.annotationDescriptionList.startTitle',
title: i18n.translate('xpack.ml.timeSeriesExplorer.annotationDescriptionList.startTitle', {
defaultMessage: 'Start',
}),
description: formatHumanReadableDateTimeSeconds(annotation.timestamp),
Expand All @@ -42,8 +39,7 @@ export const AnnotationDescriptionList = injectI18n(({ annotation, intl }: Props

if (annotation.end_timestamp !== undefined) {
listItems.push({
title: intl.formatMessage({
id: 'xpack.ml.timeSeriesExplorer.annotationDescriptionList.endTitle',
title: i18n.translate('xpack.ml.timeSeriesExplorer.annotationDescriptionList.endTitle', {
defaultMessage: 'End',
}),
description: formatHumanReadableDateTimeSeconds(annotation.end_timestamp),
Expand All @@ -52,31 +48,36 @@ export const AnnotationDescriptionList = injectI18n(({ annotation, intl }: Props

if (annotation.create_time !== undefined && annotation.modified_time !== undefined) {
listItems.push({
title: intl.formatMessage({
id: 'xpack.ml.timeSeriesExplorer.annotationDescriptionList.createdTitle',
title: i18n.translate('xpack.ml.timeSeriesExplorer.annotationDescriptionList.createdTitle', {
defaultMessage: 'Created',
}),
description: formatHumanReadableDateTimeSeconds(annotation.create_time),
});
listItems.push({
title: intl.formatMessage({
id: 'xpack.ml.timeSeriesExplorer.annotationDescriptionList.createdByTitle',
defaultMessage: 'Created by',
}),
title: i18n.translate(
'xpack.ml.timeSeriesExplorer.annotationDescriptionList.createdByTitle',
{
defaultMessage: 'Created by',
}
),
description: annotation.create_username,
});
listItems.push({
title: intl.formatMessage({
id: 'xpack.ml.timeSeriesExplorer.annotationDescriptionList.lastModifiedTitle',
defaultMessage: 'Last modified',
}),
title: i18n.translate(
'xpack.ml.timeSeriesExplorer.annotationDescriptionList.lastModifiedTitle',
{
defaultMessage: 'Last modified',
}
),
description: formatHumanReadableDateTimeSeconds(annotation.modified_time),
});
listItems.push({
title: intl.formatMessage({
id: 'xpack.ml.timeSeriesExplorer.annotationDescriptionList.modifiedByTitle',
defaultMessage: 'Modified by',
}),
title: i18n.translate(
'xpack.ml.timeSeriesExplorer.annotationDescriptionList.modifiedByTitle',
{
defaultMessage: 'Modified by',
}
),
description: annotation.modified_username,
});
}
Expand All @@ -88,4 +89,4 @@ export const AnnotationDescriptionList = injectI18n(({ annotation, intl }: Props
listItems={listItems}
/>
);
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { CommonProps } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';

import { toastNotifications } from 'ui/notify';
import { ANNOTATION_MAX_LENGTH_CHARS } from '../../../../../common/constants/annotations';
import {
annotation$,
Expand All @@ -38,6 +37,7 @@ import { AnnotationDescriptionList } from '../annotation_description_list';
import { DeleteAnnotationModal } from '../delete_annotation_modal';

import { ml } from '../../../services/ml_api_service';
import { getToastNotifications } from '../../../util/dependency_cache';

interface Props {
annotation: AnnotationState;
Expand All @@ -47,7 +47,7 @@ interface State {
isDeleteModalVisible: boolean;
}

class AnnotationFlyoutIntl extends Component<CommonProps & Props> {
class AnnotationFlyoutUI extends Component<CommonProps & Props> {
public state: State = {
isDeleteModalVisible: false,
};
Expand Down Expand Up @@ -75,6 +75,7 @@ class AnnotationFlyoutIntl extends Component<CommonProps & Props> {

public deleteHandler = async () => {
const { annotation } = this.props;
const toastNotifications = getToastNotifications();

if (annotation === null) {
return;
Expand Down Expand Up @@ -161,6 +162,7 @@ class AnnotationFlyoutIntl extends Component<CommonProps & Props> {
.indexAnnotation(annotation)
.then(() => {
annotationsRefreshed();
const toastNotifications = getToastNotifications();
if (typeof annotation._id === 'undefined') {
toastNotifications.addSuccess(
i18n.translate(
Expand All @@ -184,6 +186,7 @@ class AnnotationFlyoutIntl extends Component<CommonProps & Props> {
}
})
.catch(resp => {
const toastNotifications = getToastNotifications();
if (typeof annotation._id === 'undefined') {
toastNotifications.addDanger(
i18n.translate(
Expand Down Expand Up @@ -343,5 +346,5 @@ export const AnnotationFlyout: FC<any> = props => {
return null;
}

return <AnnotationFlyoutIntl annotation={annotationProp} {...props} />;
return <AnnotationFlyoutUI annotation={annotationProp} {...props} />;
};
Loading