Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kpollich committed May 10, 2022
1 parent 54123bc commit 1aabc76
Show file tree
Hide file tree
Showing 6 changed files with 4,068 additions and 29 deletions.
33 changes: 27 additions & 6 deletions x-pack/plugins/fleet/public/applications/fleet/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import type { FunctionComponent } from 'react';
import React, { memo, useEffect, useState } from 'react';
import type { AppMountParameters } from '@kbn/core/public';
import { EuiCode, EuiEmptyPrompt, EuiErrorBoundary, EuiPanel } from '@elastic/eui';
import { EuiCode, EuiEmptyPrompt, EuiErrorBoundary, EuiPanel, EuiPortal } from '@elastic/eui';
import type { History } from 'history';
import { Router, Redirect, Route, Switch, useRouteMatch } from 'react-router-dom';
import { FormattedMessage } from '@kbn/i18n-react';
Expand All @@ -27,7 +27,7 @@ import type { FleetConfigType, FleetStartServices } from '../../plugin';

import { PackageInstallProvider } from '../integrations/hooks';

import { useAuthz } from './hooks';
import { useAuthz, useFlyoutContext } from './hooks';

import {
ConfigContext,
Expand All @@ -40,8 +40,13 @@ import {
UIExtensionsContext,
FlyoutContextProvider,
} from './hooks';
import * as testHooks from './hooks';
import { Error, Loading, FleetSetupLoading } from './components';
import {
Error,
Loading,
FleetSetupLoading,
AgentEnrollmentFlyout,
FleetServerFlyout,
} from './components';
import type { UIExtensionsStorage } from './types';

import { FLEET_ROUTING_PATHS } from './constants';
Expand Down Expand Up @@ -237,8 +242,6 @@ export const FleetAppContext: React.FC<{
}) => {
const isDarkMode = useObservable<boolean>(startServices.uiSettings.get$('theme:darkMode'));

// console.log({ testHooks });

return (
<RedirectAppLinks application={startServices.application}>
<startServices.i18n.Context>
Expand Down Expand Up @@ -299,6 +302,8 @@ const FleetTopNav = memo(

export const AppRoutes = memo(
({ setHeaderActionMenu }: { setHeaderActionMenu: AppMountParameters['setHeaderActionMenu'] }) => {
const flyoutContext = useFlyoutContext();

return (
<>
<FleetTopNav setHeaderActionMenu={setHeaderActionMenu} />
Expand Down Expand Up @@ -347,6 +352,22 @@ export const AppRoutes = memo(
}}
/>
</Switch>

{flyoutContext.isEnrollmentFlyoutOpen && (
<EuiPortal>
<AgentEnrollmentFlyout
defaultMode="standalone"
isIntegrationFlow={true}
onClose={() => flyoutContext.closeEnrollmentFlyout()}
/>
</EuiPortal>
)}

{flyoutContext.isFleetServerFlyoutOpen && (
<EuiPortal>
<FleetServerFlyout onClose={() => flyoutContext.closeFleetServerFlyout()} />
</EuiPortal>
)}
</>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import { EditPackagePolicyPage } from '.';

type MockFn = jest.MockedFunction<any>;

// console.log({ actualHooks: jest.requireActual('../../../hooks') });

jest.mock('../../../hooks', () => {
return {
...jest.requireActual('../../../hooks'),
Expand Down
28 changes: 23 additions & 5 deletions x-pack/plugins/fleet/public/applications/integrations/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import React, { memo } from 'react';
import type { AppMountParameters } from '@kbn/core/public';
import { EuiErrorBoundary } from '@elastic/eui';
import { EuiErrorBoundary, EuiPortal } from '@elastic/eui';
import type { History } from 'history';
import { Router, Redirect, Route, Switch } from 'react-router-dom';
import useObservable from 'react-use/lib/useObservable';
Expand All @@ -22,15 +22,17 @@ import type { FleetConfigType, FleetStartServices } from '../../plugin';

import { ConfigContext, FleetStatusProvider, KibanaVersionContext } from '../../hooks';

import { AgentPolicyContextProvider } from './hooks';
import { FleetServerFlyout } from '../fleet/components';

import { AgentPolicyContextProvider, useFlyoutContext } from './hooks';
import { INTEGRATIONS_ROUTING_PATHS, pagePathGetters } from './constants';

import type { UIExtensionsStorage } from './types';

import { EPMApp } from './sections/epm';
import * as testHooks from './hooks';
import { PackageInstallProvider, UIExtensionsContext, FlyoutContextProvider } from './hooks';
import { IntegrationsHeader } from './components/header';
import { AgentEnrollmentFlyout } from './components';

const EmptyContext = () => <></>;

Expand Down Expand Up @@ -63,8 +65,6 @@ export const IntegrationsAppContext: React.FC<{
const isDarkMode = useObservable<boolean>(startServices.uiSettings.get$('theme:darkMode'));
const CloudContext = startServices.cloud?.CloudContextProvider || EmptyContext;

// console.log({ testHooks });

return (
<RedirectAppLinks application={startServices.application}>
<startServices.i18n.Context>
Expand Down Expand Up @@ -109,6 +109,8 @@ export const IntegrationsAppContext: React.FC<{
);

export const AppRoutes = memo(() => {
const flyoutContext = useFlyoutContext();

return (
<>
<Switch>
Expand Down Expand Up @@ -136,6 +138,22 @@ export const AppRoutes = memo(() => {
}}
/>
</Switch>

{flyoutContext.isEnrollmentFlyoutOpen && (
<EuiPortal>
<AgentEnrollmentFlyout
defaultMode="standalone"
isIntegrationFlow={true}
onClose={() => flyoutContext.closeEnrollmentFlyout()}
/>
</EuiPortal>
)}

{flyoutContext.isFleetServerFlyoutOpen && (
<EuiPortal>
<FleetServerFlyout onClose={() => flyoutContext.closeFleetServerFlyout()} />
</EuiPortal>
)}
</>
);
});
16 changes: 0 additions & 16 deletions x-pack/plugins/fleet/public/hooks/use_flyout_context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,6 @@ export const FlyoutContextProvider: React.FunctionComponent = ({ children }) =>
}}
>
{children}

{isEnrollmentFlyoutOpen && (
<EuiPortal>
<AgentEnrollmentFlyout
defaultMode="standalone"
isIntegrationFlow={true}
onClose={() => setIsEnrollmentFlyoutOpen(false)}
/>
</EuiPortal>
)}

{isFleetServerFlyoutOpen && (
<EuiPortal>
<FleetServerFlyout onClose={() => setIsFleetServerFlyoutOpen(false)} />
</EuiPortal>
)}
</agentFlyoutContext.Provider>
);
};
Expand Down
Loading

0 comments on commit 1aabc76

Please sign in to comment.