-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract app rendering to a renderApp method. Use start core and plugins in context to be ready for getStartServices API.
- Loading branch information
Showing
3 changed files
with
112 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
x-pack/legacy/plugins/apm/public/new-platform/application/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* 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 { AppMountParameters } from 'kibana/public'; | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { Route, Router, Switch } from 'react-router-dom'; | ||
import styled from 'styled-components'; | ||
import { routes } from '../../components/app/Main/route_config'; | ||
import { ScrollToTopOnPathChange } from '../../components/app/Main/ScrollToTopOnPathChange'; | ||
import { UpdateBreadcrumbs } from '../../components/app/Main/UpdateBreadcrumbs'; | ||
import { | ||
ApmPluginContext, | ||
ApmPluginContextValue | ||
} from '../../context/ApmPluginContext'; | ||
import { LicenseProvider } from '../../context/LicenseContext'; | ||
import { LoadingIndicatorProvider } from '../../context/LoadingIndicatorContext'; | ||
import { LocationProvider } from '../../context/LocationContext'; | ||
import { MatchedRouteProvider } from '../../context/MatchedRouteContext'; | ||
import { UrlParamsProvider } from '../../context/UrlParamsContext'; | ||
import { px, unit, units } from '../../style/variables'; | ||
import { history } from '../../utils/history'; | ||
|
||
const MainContainer = styled.main` | ||
min-width: ${px(unit * 50)}; | ||
padding: ${px(units.plus)}; | ||
height: 100%; | ||
`; | ||
|
||
const App = ({ | ||
apmPluginContextValue | ||
}: { | ||
apmPluginContextValue: ApmPluginContextValue; | ||
}) => { | ||
const i18nCore = apmPluginContextValue.core.i18n; | ||
|
||
return ( | ||
<ApmPluginContext.Provider value={apmPluginContextValue}> | ||
<i18nCore.Context> | ||
<Router history={history}> | ||
<LocationProvider> | ||
<MatchedRouteProvider routes={routes}> | ||
<UrlParamsProvider> | ||
<LoadingIndicatorProvider> | ||
<LicenseProvider> | ||
<MainContainer data-test-subj="apmMainContainer"> | ||
<UpdateBreadcrumbs routes={routes} /> | ||
<Route component={ScrollToTopOnPathChange} /> | ||
<Switch> | ||
{routes.map((route, i) => ( | ||
<Route key={i} {...route} /> | ||
))} | ||
</Switch> | ||
</MainContainer> | ||
</LicenseProvider> | ||
</LoadingIndicatorProvider> | ||
</UrlParamsProvider> | ||
</MatchedRouteProvider> | ||
</LocationProvider> | ||
</Router> | ||
</i18nCore.Context> | ||
</ApmPluginContext.Provider> | ||
); | ||
}; | ||
|
||
export function renderApp( | ||
apmPluginContextValue: ApmPluginContextValue, | ||
params: AppMountParameters | ||
) { | ||
ReactDOM.render( | ||
<App apmPluginContextValue={apmPluginContextValue} />, | ||
params.element | ||
); | ||
return () => ReactDOM.unmountComponentAtNode(params.element); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters