-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Logs + Metrics UI] Clean up async plugin initialization #67654
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
Merged
weltenwort
merged 19 commits into
elastic:master
from
weltenwort:logs-metrics-ui-cleanup-plugin-init
Jun 9, 2020
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
5dab918
Create clean, app-specific mount functions
weltenwort 8d2862a
Fix styles and make dependencies more explicit
weltenwort ef5e9bf
lazily load metric and inventory alert components
weltenwort 3559240
remove depdency on lodash
weltenwort 582779b
Use history from router context
weltenwort f0e268a
Remove unused files
weltenwort 41873c5
Adapt legacy app to more closely follow guidelines
weltenwort 2c564de
Avoid simultaneous import of metrics and logs router
weltenwort c2fadb9
Remove unused code
weltenwort cdcff8a
Fix metrics_time hook test due to provider changes
weltenwort b195f93
Merge branch 'master' into logs-metrics-ui-cleanup-plugin-init
weltenwort 6d7ca54
Remove one redirection step in the link-to routes
weltenwort 5fcd9ad
Move a redirect into the affected page
weltenwort 9fcfc87
Remove unused router files
weltenwort d80b92b
Fix redirect_to_node_logs unit tests
weltenwort b43e62c
Merge branch 'master' into logs-metrics-ui-cleanup-plugin-init
weltenwort 35b562a
Merge branch 'master' into logs-metrics-ui-cleanup-plugin-init
weltenwort cf11771
Fix typo in comment
weltenwort 80efa79
Colocate default exports with definition
weltenwort File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,47 @@ | ||
| /* | ||
| * 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 { CoreStart } from 'kibana/public'; | ||
| import { ApolloClient } from 'apollo-client'; | ||
| import { | ||
| useUiSetting$, | ||
| KibanaContextProvider, | ||
| } from '../../../../../src/plugins/kibana_react/public'; | ||
| import { TriggersActionsProvider } from '../utils/triggers_actions_context'; | ||
| import { ClientPluginDeps } from '../types'; | ||
| import { TriggersAndActionsUIPublicPluginStart } from '../../../triggers_actions_ui/public'; | ||
| import { ApolloClientContext } from '../utils/apollo_context'; | ||
| import { EuiThemeProvider } from '../../../observability/public'; | ||
| import { NavigationWarningPromptProvider } from '../utils/navigation_warning_prompt'; | ||
|
|
||
| export const CommonInfraProviders: React.FC<{ | ||
| apolloClient: ApolloClient<{}>; | ||
| triggersActionsUI: TriggersAndActionsUIPublicPluginStart; | ||
| }> = ({ apolloClient, children, triggersActionsUI }) => { | ||
| const [darkMode] = useUiSetting$<boolean>('theme:darkMode'); | ||
|
|
||
| return ( | ||
| <TriggersActionsProvider triggersActionsUI={triggersActionsUI}> | ||
| <ApolloClientContext.Provider value={apolloClient}> | ||
| <EuiThemeProvider darkMode={darkMode}> | ||
| <NavigationWarningPromptProvider>{children}</NavigationWarningPromptProvider> | ||
| </EuiThemeProvider> | ||
| </ApolloClientContext.Provider> | ||
| </TriggersActionsProvider> | ||
| ); | ||
| }; | ||
|
|
||
| export const CoreProviders: React.FC<{ | ||
| core: CoreStart; | ||
| plugins: ClientPluginDeps; | ||
| }> = ({ children, core, plugins }) => { | ||
| return ( | ||
| <KibanaContextProvider services={{ ...core, ...plugins }}> | ||
| <core.i18n.Context>{children}</core.i18n.Context> | ||
| </KibanaContextProvider> | ||
| ); | ||
| }; |
This file contains hidden or 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,13 @@ | ||
| /* | ||
| * 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 const CONTAINER_CLASSNAME = 'infra-container-element'; | ||
|
|
||
| export const prepareMountElement = (element: HTMLElement) => { | ||
| // Ensure the element we're handed from application mounting is assigned a class | ||
| // for our index.scss styles to apply to. | ||
| element.classList.add(CONTAINER_CLASSNAME); | ||
| }; |
This file contains hidden or 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,98 @@ | ||
| /* | ||
| * 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 { EuiErrorBoundary } from '@elastic/eui'; | ||
| import { createBrowserHistory, History } from 'history'; | ||
| import { AppMountParameters } from 'kibana/public'; | ||
| import React from 'react'; | ||
| import ReactDOM from 'react-dom'; | ||
| import { Route, RouteProps, Router, Switch } from 'react-router-dom'; | ||
| import url from 'url'; | ||
|
|
||
| // This exists purely to facilitate legacy app/infra URL redirects. | ||
| // It will be removed in 8.0.0. | ||
| export async function renderApp({ element }: AppMountParameters) { | ||
| const history = createBrowserHistory(); | ||
|
|
||
| ReactDOM.render(<LegacyApp history={history} />, element); | ||
|
|
||
| return () => { | ||
| ReactDOM.unmountComponentAtNode(element); | ||
| }; | ||
| } | ||
|
|
||
| const LegacyApp: React.FunctionComponent<{ history: History<unknown> }> = ({ history }) => { | ||
| return ( | ||
| <EuiErrorBoundary> | ||
| <Router history={history}> | ||
| <Switch> | ||
| <Route | ||
| path={'/'} | ||
| render={({ location }: RouteProps) => { | ||
| if (!location) { | ||
| return null; | ||
| } | ||
|
|
||
| let nextPath = ''; | ||
| let nextBasePath = ''; | ||
| let nextSearch; | ||
|
|
||
| if ( | ||
| location.hash.indexOf('#infrastructure') > -1 || | ||
| location.hash.indexOf('#/infrastructure') > -1 | ||
| ) { | ||
| nextPath = location.hash.replace( | ||
| new RegExp( | ||
| '#infrastructure/|#/infrastructure/|#/infrastructure|#infrastructure', | ||
| 'g' | ||
| ), | ||
| '' | ||
| ); | ||
| nextBasePath = location.pathname.replace('app/infra', 'app/metrics'); | ||
| } else if ( | ||
| location.hash.indexOf('#logs') > -1 || | ||
| location.hash.indexOf('#/logs') > -1 | ||
| ) { | ||
| nextPath = location.hash.replace( | ||
| new RegExp('#logs/|#/logs/|#/logs|#logs', 'g'), | ||
| '' | ||
| ); | ||
| nextBasePath = location.pathname.replace('app/infra', 'app/logs'); | ||
| } else { | ||
| // This covers /app/infra and /app/infra/home (both of which used to render | ||
| // the metrics inventory page) | ||
| nextPath = 'inventory'; | ||
| nextBasePath = location.pathname.replace('app/infra', 'app/metrics'); | ||
| nextSearch = undefined; | ||
| } | ||
|
|
||
| // app/infra#infrastructure/metrics/:type/:node was changed to app/metrics/detail/:type/:node, this | ||
| // accounts for that edge case | ||
| nextPath = nextPath.replace('metrics/', 'detail/'); | ||
|
|
||
| // Query parameters (location.search) will arrive as part of location.hash and not location.search | ||
| const nextPathParts = nextPath.split('?'); | ||
| nextPath = nextPathParts[0]; | ||
| nextSearch = nextPathParts[1] ? nextPathParts[1] : undefined; | ||
|
|
||
| let nextUrl = url.format({ | ||
| pathname: `${nextBasePath}/${nextPath}`, | ||
| hash: undefined, | ||
| search: nextSearch, | ||
| }); | ||
|
|
||
| nextUrl = nextUrl.replace('//', '/'); | ||
|
|
||
| window.location.href = nextUrl; | ||
|
|
||
| return null; | ||
| }} | ||
| /> | ||
| </Switch> | ||
| </Router> | ||
| </EuiErrorBoundary> | ||
| ); | ||
| }; |
This file contains hidden or 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,66 @@ | ||
| /* | ||
| * 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 { ApolloClient } from 'apollo-client'; | ||
| import { History } from 'history'; | ||
| import { CoreStart } from 'kibana/public'; | ||
| import React from 'react'; | ||
| import ReactDOM from 'react-dom'; | ||
| import { Route, Router, Switch } from 'react-router-dom'; | ||
| import { AppMountParameters } from '../../../../../src/core/public'; | ||
| import '../index.scss'; | ||
| import { NotFoundPage } from '../pages/404'; | ||
| import { LinkToLogsPage } from '../pages/link_to/link_to_logs'; | ||
| import { LogsPage } from '../pages/logs'; | ||
| import { ClientPluginDeps } from '../types'; | ||
| import { createApolloClient } from '../utils/apollo_client'; | ||
| import { CommonInfraProviders, CoreProviders } from './common_providers'; | ||
| import { prepareMountElement } from './common_styles'; | ||
|
|
||
| export const renderApp = ( | ||
| core: CoreStart, | ||
| plugins: ClientPluginDeps, | ||
| { element, history }: AppMountParameters | ||
| ) => { | ||
| const apolloClient = createApolloClient(core.http.fetch); | ||
|
|
||
| prepareMountElement(element); | ||
|
|
||
| ReactDOM.render( | ||
| <LogsApp apolloClient={apolloClient} core={core} history={history} plugins={plugins} />, | ||
| element | ||
| ); | ||
|
|
||
| return () => { | ||
| ReactDOM.unmountComponentAtNode(element); | ||
| }; | ||
| }; | ||
|
|
||
| const LogsApp: React.FC<{ | ||
| apolloClient: ApolloClient<{}>; | ||
| core: CoreStart; | ||
| history: History<unknown>; | ||
| plugins: ClientPluginDeps; | ||
| }> = ({ apolloClient, core, history, plugins }) => { | ||
| const uiCapabilities = core.application.capabilities; | ||
|
|
||
| return ( | ||
| <CoreProviders core={core} plugins={plugins}> | ||
| <CommonInfraProviders | ||
| apolloClient={apolloClient} | ||
| triggersActionsUI={plugins.triggers_actions_ui} | ||
| > | ||
| <Router history={history}> | ||
| <Switch> | ||
| <Route path="/link-to" component={LinkToLogsPage} /> | ||
| {uiCapabilities?.logs?.show && <Route path="/" component={LogsPage} />} | ||
| <Route component={NotFoundPage} /> | ||
| </Switch> | ||
| </Router> | ||
| </CommonInfraProviders> | ||
| </CoreProviders> | ||
| ); | ||
| }; | ||
This file contains hidden or 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,82 @@ | ||
| /* | ||
| * 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 { ApolloClient } from 'apollo-client'; | ||
| import { History } from 'history'; | ||
| import { CoreStart } from 'kibana/public'; | ||
| import React from 'react'; | ||
| import ReactDOM from 'react-dom'; | ||
| import { Route, Router, Switch } from 'react-router-dom'; | ||
| import { AppMountParameters } from '../../../../../src/core/public'; | ||
| import '../index.scss'; | ||
| import { NotFoundPage } from '../pages/404'; | ||
| import { LinkToMetricsPage } from '../pages/link_to/link_to_metrics'; | ||
| import { InfrastructurePage } from '../pages/metrics'; | ||
| import { MetricDetail } from '../pages/metrics/metric_detail'; | ||
| import { ClientPluginDeps } from '../types'; | ||
| import { createApolloClient } from '../utils/apollo_client'; | ||
| import { RedirectWithQueryParams } from '../utils/redirect_with_query_params'; | ||
| import { CommonInfraProviders, CoreProviders } from './common_providers'; | ||
| import { prepareMountElement } from './common_styles'; | ||
|
|
||
| export const renderApp = ( | ||
| core: CoreStart, | ||
| plugins: ClientPluginDeps, | ||
| { element, history }: AppMountParameters | ||
| ) => { | ||
| const apolloClient = createApolloClient(core.http.fetch); | ||
|
|
||
| prepareMountElement(element); | ||
|
|
||
| ReactDOM.render( | ||
| <MetricsApp apolloClient={apolloClient} core={core} history={history} plugins={plugins} />, | ||
| element | ||
| ); | ||
|
|
||
| return () => { | ||
| ReactDOM.unmountComponentAtNode(element); | ||
| }; | ||
| }; | ||
|
|
||
| const MetricsApp: React.FC<{ | ||
| apolloClient: ApolloClient<{}>; | ||
| core: CoreStart; | ||
| history: History<unknown>; | ||
| plugins: ClientPluginDeps; | ||
| }> = ({ apolloClient, core, history, plugins }) => { | ||
| const uiCapabilities = core.application.capabilities; | ||
|
|
||
| return ( | ||
| <CoreProviders core={core} plugins={plugins}> | ||
| <CommonInfraProviders | ||
| apolloClient={apolloClient} | ||
| triggersActionsUI={plugins.triggers_actions_ui} | ||
| > | ||
| <Router history={history}> | ||
| <Switch> | ||
| <Route path="/link-to" component={LinkToMetricsPage} /> | ||
| {uiCapabilities?.infrastructure?.show && ( | ||
| <RedirectWithQueryParams from="/" exact={true} to="/inventory" /> | ||
| )} | ||
| {uiCapabilities?.infrastructure?.show && ( | ||
| <RedirectWithQueryParams from="/snapshot" exact={true} to="/inventory" /> | ||
| )} | ||
| {uiCapabilities?.infrastructure?.show && ( | ||
| <RedirectWithQueryParams from="/metrics-explorer" exact={true} to="/explorer" /> | ||
| )} | ||
| {uiCapabilities?.infrastructure?.show && ( | ||
| <Route path="/detail/:type/:node" component={MetricDetail} /> | ||
| )} | ||
| {uiCapabilities?.infrastructure?.show && ( | ||
| <Route path="/" component={InfrastructurePage} /> | ||
| )} | ||
| <Route component={NotFoundPage} /> | ||
| </Switch> | ||
| </Router> | ||
| </CommonInfraProviders> | ||
| </CoreProviders> | ||
| ); | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.