Skip to content

Commit

Permalink
cleanup wrapper page and renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelolo24 committed Jun 4, 2021
1 parent cba4e70 commit 75bb560
Show file tree
Hide file tree
Showing 25 changed files with 134 additions and 119 deletions.
6 changes: 3 additions & 3 deletions x-pack/plugins/security_solution/public/app/404.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
import React from 'react';
import { FormattedMessage } from '@kbn/i18n/react';

import { WrapperPage } from '../common/components/wrapper_page';
import { SecuritySolutionPageWrapper } from '../common/components/page_wrapper';

export const NotFoundPage = React.memo(() => (
<WrapperPage>
<SecuritySolutionPageWrapper>
<FormattedMessage
id="xpack.securitySolution.pages.fourohfour.noContentFoundDescription"
defaultMessage="No content found"
/>
</WrapperPage>
</SecuritySolutionPageWrapper>
));

NotFoundPage.displayName = 'NotFoundPage';
6 changes: 3 additions & 3 deletions x-pack/plugins/security_solution/public/cases/pages/case.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import React from 'react';

import { WrapperPage } from '../../common/components/wrapper_page';
import { SecuritySolutionPageWrapper } from '../../common/components/page_wrapper';
import { useGetUserSavedObjectPermissions } from '../../common/lib/kibana';
import { SpyRoute } from '../../common/utils/route/spy_routes';
import { AllCases } from '../components/all_cases';
Expand All @@ -21,15 +21,15 @@ export const CasesPage = React.memo(() => {

return userPermissions == null || userPermissions?.read ? (
<>
<WrapperPage>
<SecuritySolutionPageWrapper>
{userPermissions != null && !userPermissions?.crud && userPermissions?.read && (
<CaseCallOut
title={savedObjectReadOnlyErrorMessage.title}
messages={[{ ...savedObjectReadOnlyErrorMessage, title: '' }]}
/>
)}
<AllCases userCanCrud={userPermissions?.crud ?? false} />
</WrapperPage>
</SecuritySolutionPageWrapper>
<SpyRoute pageName={SecurityPageName.case} />
</>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useParams, useHistory } from 'react-router-dom';

import { SecurityPageName } from '../../app/types';
import { SpyRoute } from '../../common/utils/route/spy_routes';
import { WrapperPage } from '../../common/components/wrapper_page';
import { SecuritySolutionPageWrapper } from '../../common/components/page_wrapper';
import { useGetUrlSearch } from '../../common/components/navigation/use_get_url_search';
import { useGetUserSavedObjectPermissions } from '../../common/lib/kibana';
import { getCaseUrl } from '../../common/components/link_to';
Expand All @@ -34,7 +34,7 @@ export const CaseDetailsPage = React.memo(() => {

return caseId != null ? (
<>
<WrapperPage noPadding>
<SecuritySolutionPageWrapper noPadding>
{userPermissions != null && !userPermissions?.crud && userPermissions?.read && (
<CaseCallOut
title={savedObjectReadOnlyErrorMessage.title}
Expand All @@ -46,7 +46,7 @@ export const CaseDetailsPage = React.memo(() => {
subCaseId={subCaseId}
userCanCrud={userPermissions?.crud ?? false}
/>
</WrapperPage>
</SecuritySolutionPageWrapper>
<SpyRoute pageName={SecurityPageName.case} />
</>
) : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import styled from 'styled-components';
import { SecurityPageName } from '../../app/types';
import { getCaseUrl } from '../../common/components/link_to';
import { useGetUrlSearch } from '../../common/components/navigation/use_get_url_search';
import { WrapperPage } from '../../common/components/wrapper_page';
import { SecuritySolutionPageWrapper } from '../../common/components/page_wrapper';
import { useGetUserSavedObjectPermissions, useKibana } from '../../common/lib/kibana';
import { SpyRoute } from '../../common/utils/route/spy_routes';
import { navTabs } from '../../app/home/home_navigations';
Expand Down Expand Up @@ -46,7 +46,7 @@ const ConfigureCasesPageComponent: React.FC = () => {

return (
<>
<WrapperPage noPadding>
<SecuritySolutionPageWrapper noPadding>
<SectionWrapper>
<HeaderWrapper>
<CaseHeaderPage title={i18n.CONFIGURE_CASES_PAGE_TITLE} backOptions={backOptions} />
Expand All @@ -57,7 +57,7 @@ const ConfigureCasesPageComponent: React.FC = () => {
userCanCrud: userPermissions?.crud ?? false,
})}
</WhitePageWrapper>
</WrapperPage>
</SecuritySolutionPageWrapper>
<SpyRoute pageName={SecurityPageName.case} />
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useHistory } from 'react-router-dom';
import { SecurityPageName } from '../../app/types';
import { getCaseUrl } from '../../common/components/link_to';
import { useGetUrlSearch } from '../../common/components/navigation/use_get_url_search';
import { WrapperPage } from '../../common/components/wrapper_page';
import { SecuritySolutionPageWrapper } from '../../common/components/page_wrapper';
import { useGetUserSavedObjectPermissions } from '../../common/lib/kibana';
import { SpyRoute } from '../../common/utils/route/spy_routes';
import { navTabs } from '../../app/home/home_navigations';
Expand Down Expand Up @@ -40,10 +40,10 @@ export const CreateCasePage = React.memo(() => {

return (
<>
<WrapperPage>
<SecuritySolutionPageWrapper>
<CaseHeaderPage backOptions={backOptions} title={i18n.CREATE_TITLE} />
<Create />
</WrapperPage>
</SecuritySolutionPageWrapper>
<SpyRoute pageName={SecurityPageName.case} />
</>
);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,19 @@

/* eslint-disable react/display-name */

import React, { useMemo, useRef } from 'react';
import styled from 'styled-components';
import React, { useRef } from 'react';
import { KibanaPageTemplateProps } from '../../../../../../../../src/plugins/kibana_react/public';
import { useKibana } from '../../../../common/lib/kibana';
import { IS_DRAGGING_CLASS_NAME } from '../../../../common/components/drag_and_drop/drag_classnames';
import { useShowTimeline } from '../../../../common/utils/timeline/use_show_timeline';
import { useSourcererScope } from '../../../../common/containers/sourcerer';
import { DETECTIONS_SUB_PLUGIN_ID } from '../../../../../common/constants';
import { SourcererScopeName } from '../../../../common/store/sourcerer/model';
import { getTimelineShowStatusByIdSelector } from '../../../../timelines/components/flyout/selectors';
import { useDeepEqualSelector } from '../../../../common/hooks/use_selector';
import { TimelineId } from '../../../../../common/types/timeline';
import { AutoSaveWarningMsg } from '../../../../timelines/components/timeline/auto_save_warning';
import { Flyout } from '../../../../timelines/components/flyout';
import { useAppMountContext } from '../../../../app/app_mount_context';

const bottomBarClassName = 'timeline-bottom-bar';

const StyledBottomBar = styled.span<{ $isShowingTimelineOverlay?: boolean }>`
.${bottomBarClassName} {
animation: 'none !important'; // disable the default bottom bar slide animation
background: #ffffff; // Override bottom bar black background
color: inherit; // Necessary to override the bottom bar 'white text'
transform: ${(
{ $isShowingTimelineOverlay } // Since the bottom bar wraps the whole overlay now, need to override any transforms when it is open
) => ($isShowingTimelineOverlay ? 'none' : 'translateY(calc(100% - 50px))')};
z-index: ${({ theme }) => theme.eui.euiZLevel8};
.${IS_DRAGGING_CLASS_NAME} & {
// When a drag is in process the bottom flyout should slide up to allow a drop
transform: none;
}
}
`;
export const BOTTOM_BAR_CLASSNAME = 'timeline-bottom-bar';

export const SecuritySolutionBottomBar = React.memo(() => {
const subPluginId = useRef<string>('');
Expand All @@ -49,8 +28,6 @@ export const SecuritySolutionBottomBar = React.memo(() => {
application.currentAppId$.subscribe((appId) => {
subPluginId.current = appId ?? '';
});
const getTimelineShowStatus = useMemo(() => getTimelineShowStatusByIdSelector(), []);
const { show } = useDeepEqualSelector((state) => getTimelineShowStatus(state, TimelineId.active));

const [showTimeline] = useShowTimeline();

Expand All @@ -61,15 +38,15 @@ export const SecuritySolutionBottomBar = React.memo(() => {
);

return indicesExist && showTimeline ? (
<StyledBottomBar $isShowingTimelineOverlay={show}>
<>
<AutoSaveWarningMsg />
<Flyout timelineId={TimelineId.active} onAppLeave={onAppLeave} />
</StyledBottomBar>
</>
) : null;
});

export const SecuritySolutionBottomBarProps: KibanaPageTemplateProps['bottomBarProps'] = {
className: bottomBarClassName,
className: BOTTOM_BAR_CLASSNAME,
position: 'fixed',
usePortal: false,
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import React, { forwardRef } from 'react';
import styled from 'styled-components';
import { OutPortal } from 'react-reverse-portal';
import { useGlobalHeaderPortal } from '../../hooks/use_global_header_portal';
import { useGlobalHeaderPortal } from '../../../hooks/use_global_header_portal';

/**
* This component uses a reverse portal to render the global kql bar within the SecuritySolutionPageWrapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ import { shallow } from 'enzyme';
import React from 'react';

import { TestProviders } from '../../mock';
import { WrapperPage } from './index';
import { SecuritySolutionPageWrapper } from './index';

describe('WrapperPage', () => {
describe('SecuritySolutionPageWrapper', () => {
test('it renders', () => {
const wrapper = shallow(
<TestProviders>
<WrapperPage>
<SecuritySolutionPageWrapper>
<p>{'Test page'}</p>
</WrapperPage>
</SecuritySolutionPageWrapper>
</TestProviders>
);

expect(wrapper.find('Memo(WrapperPageComponent)')).toMatchSnapshot();
expect(wrapper.find('Memo(SecuritySolutionPageWrapperComponent)')).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,52 @@
* 2.0.
*/

import React, { useEffect, useState } from 'react';
import React, { useEffect, useMemo, useState } from 'react';
import styled from 'styled-components';
import { CommonProps, EuiPanel } from '@elastic/eui';
import { useKibana } from '../../../common/lib/kibana';
import { KibanaPageTemplate } from '../../../../../../../src/plugins/kibana_react/public';
import { useGlobalFullScreen } from '../../../common/containers/use_full_screen';
import { AppGlobalStyle } from '../../../common/components/page';
import { gutterTimeline } from '../../../common/lib/helpers';
import { TimelineId } from '../../../../common/types/timeline';
import { IS_DRAGGING_CLASS_NAME } from '../../../common/components/drag_and_drop/drag_classnames';
import { getTimelineShowStatusByIdSelector } from '../../../timelines/components/flyout/selectors';
import { useDeepEqualSelector } from '../../../common/hooks/use_selector';
import { useThrottledResizeObserver } from '../../../common/components/utils';
import { useKibana } from '../../../common/lib/kibana';
import { GlobalKQLHeader } from './global_kql_header';
import { SecuritySolutionBottomBar, SecuritySolutionBottomBarProps } from './bottom_bar';
import {
BOTTOM_BAR_CLASSNAME,
SecuritySolutionBottomBar,
SecuritySolutionBottomBarProps,
} from './bottom_bar';
import { useSecurityPageTemplateNav } from './navigation';

/* eslint-disable react/display-name */

/**
* Need to apply the styles via a className to effect the containing bottom bar
* rather than applying them to the timeline bar directly
*/
const StyledKibanaPageTemplate = styled(KibanaPageTemplate)<{
$isShowingTimelineOverlay?: boolean;
}>`
.${BOTTOM_BAR_CLASSNAME} {
animation: 'none !important'; // disable the default bottom bar slide animation
background: #ffffff; // Override bottom bar black background
color: inherit; // Necessary to override the bottom bar 'white text'
transform: ${(
{ $isShowingTimelineOverlay } // Since the bottom bar wraps the whole overlay now, need to override any transforms when it is open
) => ($isShowingTimelineOverlay ? 'none' : 'translateY(calc(100% - 50px))')};
z-index: ${({ theme }) => theme.eui.euiZLevel8};
.${IS_DRAGGING_CLASS_NAME} & {
// When a drag is in process the bottom flyout should slide up to allow a drop
transform: none;
}
}
`;

const StyledEuiPanel = styled(EuiPanel)<{
$paddingTop: number;
$noPadding?: boolean;
Expand All @@ -33,7 +64,7 @@ const StyledEuiPanel = styled(EuiPanel)<{
padding-bottom: ${({ $withTimeline }) => ($withTimeline ? gutterTimeline : undefined)};
`;

interface WrapperPageProps {
interface SecuritySolutionPageWrapperProps {
children: React.ReactNode;
noPadding?: boolean;
noTimeline?: boolean;
Expand All @@ -42,13 +73,19 @@ interface WrapperPageProps {
style?: Record<string, string>;
}

export const WrapperPage: React.FC<WrapperPageProps & CommonProps> = React.memo(
export const SecuritySolutionPageWrapper: React.FC<
SecuritySolutionPageWrapperProps & CommonProps
> = React.memo(
({ children, className, noPadding, noTimeline, pageHeaderChildren, style, ...otherProps }) => {
const securityPageTemplateNav = useSecurityPageTemplateNav();
const { globalFullScreen, setGlobalFullScreen } = useGlobalFullScreen();
useEffect(() => {
setGlobalFullScreen(false); // exit full screen mode on page load
}, [setGlobalFullScreen]);
const getTimelineShowStatus = useMemo(() => getTimelineShowStatusByIdSelector(), []);
const { show: isShowingTimelineOverlay } = useDeepEqualSelector((state) =>
getTimelineShowStatus(state, TimelineId.active)
);

const { overlays } = useKibana().services;
const { ref, height = 0 } = useThrottledResizeObserver(300);
Expand All @@ -63,7 +100,8 @@ export const WrapperPage: React.FC<WrapperPageProps & CommonProps> = React.memo(
}, [banners$]); // Only un/re-subscribe if the Observable changes

return (
<KibanaPageTemplate
<StyledKibanaPageTemplate
$isShowingTimelineOverlay={isShowingTimelineOverlay}
bottomBarProps={SecuritySolutionBottomBarProps}
bottomBar={<SecuritySolutionBottomBar />}
paddingSize="none"
Expand All @@ -87,7 +125,7 @@ export const WrapperPage: React.FC<WrapperPageProps & CommonProps> = React.memo(
{children}
<AppGlobalStyle />
</StyledEuiPanel>
</KibanaPageTemplate>
</StyledKibanaPageTemplate>
);
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const useSecurityPageTemplateNav = (): KibanaPageTemplateProps['solutionN

const navItems = [
{
name: null,
name: '',
id: APP_ID,
items: topLevelNavItems,
},
Expand Down

This file was deleted.

Loading

0 comments on commit 75bb560

Please sign in to comment.