Skip to content

Commit

Permalink
Fixing conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-buttner committed Apr 7, 2020
2 parents b69c2ad + eacdbcd commit 7c7eaee
Show file tree
Hide file tree
Showing 10 changed files with 455 additions and 59 deletions.
38 changes: 38 additions & 0 deletions x-pack/plugins/endpoint/common/generate_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
import uuid from 'uuid';
import seedrandom from 'seedrandom';
import { AlertEvent, EndpointEvent, HostMetadata, OSFields, HostFields } from './types';
// FIXME: move types/model to top-level
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { PolicyData } from '../public/applications/endpoint/types';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { generatePolicy } from '../public/applications/endpoint/models/policy';

export type Event = AlertEvent | EndpointEvent;

Expand Down Expand Up @@ -452,6 +457,39 @@ export class EndpointDocGenerator {
}
}

/**
* Generates an Ingest `datasource` that includes the Endpoint Policy data
*/
public generatePolicyDatasource(): PolicyData {
return {
id: this.seededUUIDv4(),
name: 'Endpoint Policy',
description: 'Policy to protect the worlds data',
config_id: this.seededUUIDv4(),
enabled: true,
output_id: '',
inputs: [
{
type: 'endpoint',
enabled: true,
streams: [],
config: {
policy: {
value: generatePolicy(),
},
},
},
],
namespace: 'default',
package: {
name: 'endpoint',
title: 'Elastic Endpoint',
version: '1.0.0',
},
revision: 1,
};
}

private randomN(n: number): number {
return Math.floor(this.random() * n);
}
Expand Down
83 changes: 28 additions & 55 deletions x-pack/plugins/endpoint/public/applications/endpoint/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,17 @@
import * as React from 'react';
import ReactDOM from 'react-dom';
import { CoreStart, AppMountParameters, ScopedHistory } from 'kibana/public';
import { I18nProvider, FormattedMessage } from '@kbn/i18n/react';
import { Route, Switch, Router } from 'react-router-dom';
import { Provider } from 'react-redux';
import { FormattedMessage } from '@kbn/i18n/react';
import { Route, Switch } from 'react-router-dom';
import { Store } from 'redux';
import { useObservable } from 'react-use';
import { KibanaContextProvider } from '../../../../../../src/plugins/kibana_react/public';
import { RouteCapture } from './view/route_capture';
import { EndpointPluginStartDependencies } from '../../plugin';
import { appStoreFactory } from './store';
import { AlertIndex } from './view/alerts';
import { HostList } from './view/hosts';
import { PolicyList } from './view/policy';
import { PolicyDetails } from './view/policy';
import { HeaderNavigation } from './components/header_nav';
import { EuiThemeProvider } from '../../../../../legacy/common/eui_styled_components';
import { AppRootProvider } from './view/app_root_provider';
import { Setup } from './view/setup';

/**
Expand Down Expand Up @@ -50,55 +46,32 @@ interface RouterProps {
}

const AppRoot: React.FunctionComponent<RouterProps> = React.memo(
({
history,
store,
coreStart: { http, notifications, uiSettings, application },
depsStart: { data, ingestManager },
}) => {
const isDarkMode = useObservable<boolean>(uiSettings.get$('theme:darkMode'));

({ history, store, coreStart, depsStart }) => {
return (
<Provider store={store}>
<I18nProvider>
<KibanaContextProvider services={{ http, notifications, application, data }}>
<Setup ingestManager={ingestManager} notifications={notifications} />
<EuiThemeProvider darkMode={isDarkMode}>
<Router history={history}>
<RouteCapture>
<HeaderNavigation />
<Switch>
<Route
exact
path="/"
render={() => (
<h1 data-test-subj="welcomeTitle">
<FormattedMessage
id="xpack.endpoint.welcomeTitle"
defaultMessage="Hello World"
/>
</h1>
)}
/>
<Route path="/hosts" component={HostList} />
<Route path="/alerts" component={AlertIndex} />
<Route path="/policy" exact component={PolicyList} />
<Route path="/policy/:id" exact component={PolicyDetails} />
<Route
render={() => (
<FormattedMessage
id="xpack.endpoint.notFound"
defaultMessage="Page Not Found"
/>
)}
/>
</Switch>
</RouteCapture>
</Router>
</EuiThemeProvider>
</KibanaContextProvider>
</I18nProvider>
</Provider>
<AppRootProvider store={store} history={history} coreStart={coreStart} depsStart={depsStart}>
<Setup ingestManager={depsStart.ingestManager} notifications={coreStart.notifications} />
<HeaderNavigation />
<Switch>
<Route
exact
path="/"
render={() => (
<h1 data-test-subj="welcomeTitle">
<FormattedMessage id="xpack.endpoint.welcomeTitle" defaultMessage="Hello World" />
</h1>
)}
/>
<Route path="/hosts" component={HostList} />
<Route path="/alerts" component={AlertIndex} />
<Route path="/policy" exact component={PolicyList} />
<Route path="/policy/:id" exact component={PolicyDetails} />
<Route
render={() => (
<FormattedMessage id="xpack.endpoint.notFound" defaultMessage="Page Not Found" />
)}
/>
</Switch>
</AppRootProvider>
);
}
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React from 'react';
import { createMemoryHistory } from 'history';
import { render as reactRender, RenderOptions, RenderResult } from '@testing-library/react';
import { appStoreFactory } from '../store';
import { coreMock } from '../../../../../../../src/core/public/mocks';
import { EndpointPluginStartDependencies } from '../../../plugin';
import { depsStartMock } from './dependencies_start_mock';
import { AppRootProvider } from '../view/app_root_provider';

type UiRender = (ui: React.ReactElement, options?: RenderOptions) => RenderResult;

/**
* Mocked app root context renderer
*/
interface AppContextTestRender {
store: ReturnType<typeof appStoreFactory>;
history: ReturnType<typeof createMemoryHistory>;
coreStart: ReturnType<typeof coreMock.createStart>;
depsStart: EndpointPluginStartDependencies;
/**
* A wrapper around `AppRootContext` component. Uses the mocked modules as input to the
* `AppRootContext`
*/
AppWrapper: React.FC<any>;
/**
* Renders the given UI within the created `AppWrapper` providing the given UI a mocked
* endpoint runtime context environment
*/
render: UiRender;
}

/**
* Creates a mocked endpoint app context custom renderer that can be used to render
* component that depend upon the application's surrounding context providers.
* Factory also returns the content that was used to create the custom renderer, allowing
* for further customization.
*/
export const createAppRootMockRenderer = (): AppContextTestRender => {
const history = createMemoryHistory<never>();
const coreStart = coreMock.createStart({ basePath: '/mock' });
const depsStart = depsStartMock();
const store = appStoreFactory({ coreStart, depsStart });
const AppWrapper: React.FunctionComponent<{ children: React.ReactElement }> = ({ children }) => (
<AppRootProvider store={store} history={history} coreStart={coreStart} depsStart={depsStart}>
{children}
</AppRootProvider>
);
const render: UiRender = (ui, options) => {
// @ts-ignore
return reactRender(ui, {
wrapper: AppWrapper,
...options,
});
};

return {
store,
history,
coreStart,
depsStart,
AppWrapper,
render,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { IngestManagerStart } from '../../../../ingest_manager/public';
import {
dataPluginMock,
Start as DataPublicStartMock,
} from '../../../../../../src/plugins/data/public/mocks';
} from '../../../../../../../src/plugins/data/public/mocks';

type DataMock = Omit<DataPublicStartMock, 'indexPatterns' | 'query'> & {
indexPatterns: Omit<DataPublicStartMock['indexPatterns'], 'getFieldsForWildcard'> & {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export * from './dependencies_start_mock';
export * from './app_context_render';
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,12 @@ export const policyDetailsReducer: Reducer<PolicyDetailsState, AppAction> = (
...state,
location: action.payload,
};
const isCurrentlyOnDetailsPage = isOnPolicyDetailsPage(newState);
const wasPreviouslyOnDetailsPage = isOnPolicyDetailsPage(state);

if (isOnPolicyDetailsPage(newState)) {
// Did user just enter the Detail page? if so, then set the loading indicator and return new state
if (isCurrentlyOnDetailsPage && !wasPreviouslyOnDetailsPage) {
newState.isLoading = true;
return newState;
}
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React, { memo, ReactNode, useMemo } from 'react';
import { Provider } from 'react-redux';
import { I18nProvider } from '@kbn/i18n/react';
import { Router } from 'react-router-dom';
import { History } from 'history';
import { CoreStart } from 'kibana/public';
import { useObservable } from 'react-use';
import { EuiThemeProvider } from '../../../../../../legacy/common/eui_styled_components';
import { KibanaContextProvider } from '../../../../../../../src/plugins/kibana_react/public';
import { appStoreFactory } from '../store';
import { RouteCapture } from './route_capture';
import { EndpointPluginStartDependencies } from '../../../plugin';

/**
* Provides the context for rendering the endpoint app
*/
export const AppRootProvider = memo<{
store: ReturnType<typeof appStoreFactory>;
history: History;
coreStart: CoreStart;
depsStart: EndpointPluginStartDependencies;
children: ReactNode | ReactNode[];
}>(
({
store,
history,
coreStart: { http, notifications, uiSettings, application },
depsStart: { data },
children,
}) => {
const isDarkMode = useObservable<boolean>(uiSettings.get$('theme:darkMode'));
const services = useMemo(() => ({ http, notifications, application, data }), [
application,
data,
http,
notifications,
]);
return (
<Provider store={store}>
<I18nProvider>
<KibanaContextProvider services={services}>
<EuiThemeProvider darkMode={isDarkMode}>
<Router history={history}>
<RouteCapture>{children}</RouteCapture>
</Router>
</EuiThemeProvider>
</KibanaContextProvider>
</I18nProvider>
</Provider>
);
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const AgentsSummary = memo<AgentsSummaryProps>(props => {
}, []);

return (
<EuiFlexGroup gutterSize="xl">
<EuiFlexGroup gutterSize="xl" data-test-subj="policyAgentsSummary">
{stats.map(({ key, title, health }) => {
return (
<EuiFlexItem grow={false} key={key}>
Expand Down
Loading

0 comments on commit 7c7eaee

Please sign in to comment.