diff --git a/x-pack/legacy/plugins/fleet/public/index.tsx b/x-pack/legacy/plugins/fleet/public/index.tsx
index fc640783cf6c9..17d3b072bf29f 100644
--- a/x-pack/legacy/plugins/fleet/public/index.tsx
+++ b/x-pack/legacy/plugins/fleet/public/index.tsx
@@ -20,7 +20,7 @@ async function startApp(libs: FrontendLibs) {
-
+
,
diff --git a/x-pack/legacy/plugins/fleet/public/pages/agent_details/components/details_section.tsx b/x-pack/legacy/plugins/fleet/public/pages/agent_details/components/details_section.tsx
index 3214bd970839a..dea3a8397cf16 100644
--- a/x-pack/legacy/plugins/fleet/public/pages/agent_details/components/details_section.tsx
+++ b/x-pack/legacy/plugins/fleet/public/pages/agent_details/components/details_section.tsx
@@ -91,7 +91,10 @@ export const AgentDetailSection: SFC = ({ agent, onClickUnenroll, unenrol
-
+
@@ -101,7 +104,10 @@ export const AgentDetailSection: SFC = ({ agent, onClickUnenroll, unenrol
isLoading={unenrollment.loading}
onClick={onClickUnenroll}
>
-
+
diff --git a/x-pack/legacy/plugins/fleet/public/pages/agent_details/components/metadata_form.tsx b/x-pack/legacy/plugins/fleet/public/pages/agent_details/components/metadata_form.tsx
index 1fb5a776b7f94..95cd02fdf3466 100644
--- a/x-pack/legacy/plugins/fleet/public/pages/agent_details/components/metadata_form.tsx
+++ b/x-pack/legacy/plugins/fleet/public/pages/agent_details/components/metadata_form.tsx
@@ -159,7 +159,7 @@ export const MetadataForm: SFC<{ agent: Agent }> = ({ agent }) => {
diff --git a/x-pack/legacy/plugins/fleet/public/routes.tsx b/x-pack/legacy/plugins/fleet/public/routes.tsx
index 384317e2d3f75..2b20e1daaf799 100644
--- a/x-pack/legacy/plugins/fleet/public/routes.tsx
+++ b/x-pack/legacy/plugins/fleet/public/routes.tsx
@@ -5,77 +5,70 @@
*/
import { get } from 'lodash';
-import React, { Component } from 'react';
+import React, { useState, useEffect, SFC } from 'react';
import { Redirect, Route, Switch } from 'react-router-dom';
import { Loading } from './components/loading';
import { ChildRoutes } from './components/navigation/child_routes';
import { URLStateProps, WithURLState } from './hooks/with_url_state';
-import { FrontendLibs } from './lib/types';
import { routeMap } from './pages';
+import { useLibs } from './hooks/use_libs';
-interface RouterProps {
- libs: FrontendLibs;
-}
+function useWaitUntilFrameworkReady() {
+ const libs = useLibs();
+ const [isLoading, setIsLoading] = useState(true);
-interface RouterState {
- loading: boolean;
-}
+ const waitUntilReady = async () => {
+ try {
+ await libs.framework.waitUntilFrameworkReady();
+ } catch (e) {
+ // Silently swallow error
+ }
+ setIsLoading(false);
+ };
-export class AppRoutes extends Component {
- constructor(props: RouterProps) {
- super(props);
- this.state = {
- loading: true,
- };
- }
+ useEffect(() => {
+ waitUntilReady();
+ }, []);
- public async componentWillMount() {
- if (this.state.loading === true) {
- try {
- await this.props.libs.framework.waitUntilFrameworkReady();
- } catch (e) {
- // Silently swallow error
- }
+ return { isLoading };
+}
- this.setState({
- loading: false,
- });
- }
+export const AppRoutes: SFC = () => {
+ const { isLoading } = useWaitUntilFrameworkReady();
+ const libs = useLibs();
+
+ if (isLoading === true) {
+ return ;
}
- public render() {
- if (this.state.loading === true) {
- return ;
- }
+ return (
+
+ {/* Redirects mapping */}
+
+ {/* License check (UI displays when license exists but is expired) */}
+ {get(libs.framework.info, 'license.expired', true) && (
+
+ !props.location.pathname.includes('/error') ? (
+
+ ) : null
+ }
+ />
+ )}
- return (
-
- {/* Redirects mapping */}
-
- {/* License check (UI displays when license exists but is expired) */}
- {get(this.props.libs.framework.info, 'license.expired', true) && (
-
- !props.location.pathname.includes('/error') ? (
-
- ) : null
- }
- />
- )}
+ {!libs.framework.capabilities.read && (
+
+ !props.location.pathname.includes('/error') ? (
+
+ ) : null
+ }
+ />
+ )}
- {!this.props.libs.framework.capabilities.read && (
-
- !props.location.pathname.includes('/error') ? (
-
- ) : null
- }
- />
- )}
-
- {/* Ensure security is eanabled for elastic and kibana */}
- {/* TODO: Disabled for now as we don't have this info set up on backend yet */}
- {/* {!get(this.props.libs.framework.info, 'security.enabled', true) && (
+ {/* Ensure security is eanabled for elastic and kibana */}
+ {/* TODO: Disabled for now as we don't have this info set up on backend yet */}
+ {/* {!get(this.props.libs.framework.info, 'security.enabled', true) && (
!props.location.pathname.includes('/error') ? (
@@ -85,15 +78,14 @@ export class AppRoutes extends Component {
/>
)} */}
- {/* This app does not make use of a homepage. The main page is agents list */}
- } />
-
+ {/* This app does not make use of a homepage. The main page is agents list */}
+ } />
+
- {/* Render routes from the FS */}
-
- {(URLProps: URLStateProps) => }
-
-
- );
- }
-}
+ {/* Render routes from the FS */}
+
+ {(URLProps: URLStateProps) => }
+
+
+ );
+};