-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Security Solution] Fix positioning of Kibana banners list inside Sec… #80124
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React, { useRef } from 'react'; | ||
import React, { useEffect, useMemo, useRef, useState } from 'react'; | ||
import styled from 'styled-components'; | ||
|
||
import { TimelineId } from '../../../common/types/timeline'; | ||
|
@@ -44,9 +44,18 @@ interface HomePageProps { | |
} | ||
|
||
const HomePageComponent: React.FC<HomePageProps> = ({ children }) => { | ||
const { application } = useKibana().services; | ||
const { application, overlays } = useKibana().services; | ||
const subPluginId = useRef<string>(''); | ||
const { ref, height = 0 } = useThrottledResizeObserver(300); | ||
const banners$ = overlays.banners.get$(); | ||
const [headerFixed, setHeaderFixed] = useState<boolean>(true); | ||
const mainPaddingTop = useMemo(() => (headerFixed ? height : 0), [headerFixed, height]); | ||
|
||
useEffect(() => { | ||
const subscription = banners$.subscribe((banners) => setHeaderFixed(!banners.length)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the logic is "the header is fixed when there are no banners?" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes that what we decide in the zoom meeting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A little bit more details here, only the banners coming from kibana. |
||
return () => subscription.unsubscribe(); | ||
}, [banners$]); // Only un/re-subscribe if the Observable changes | ||
|
||
application.currentAppId$.subscribe((appId) => { | ||
subPluginId.current = appId ?? ''; | ||
}); | ||
|
@@ -72,9 +81,9 @@ const HomePageComponent: React.FC<HomePageProps> = ({ children }) => { | |
|
||
return ( | ||
<SecuritySolutionAppWrapper> | ||
<HeaderGlobal ref={ref} /> | ||
<HeaderGlobal ref={ref} isFixed={headerFixed} /> | ||
|
||
<Main paddingTop={height} data-test-subj="pageContainer"> | ||
<Main paddingTop={mainPaddingTop} data-test-subj="pageContainer"> | ||
<DragDropContextWrapper browserFields={browserFields}> | ||
<UseUrlState indexPattern={indexPattern} navTabs={navTabs} /> | ||
{indicesExist && showTimeline && ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,13 +24,13 @@ import { APP_ID, ADD_DATA_PATH, APP_DETECTIONS_PATH } from '../../../../common/c | |
import { useGlobalHeaderPortal } from '../../hooks/use_global_header_portal'; | ||
import { LinkAnchor } from '../links'; | ||
|
||
const Wrapper = styled.header` | ||
${({ theme }) => ` | ||
const Wrapper = styled.header<{ $isFixed: boolean }>` | ||
${({ theme, $isFixed }) => ` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like any of the React components could calculate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because we need that information also to determine proper |
||
background: ${theme.eui.euiColorEmptyShade}; | ||
border-bottom: ${theme.eui.euiBorderThin}; | ||
width: 100%; | ||
z-index: ${theme.eui.euiZNavigation}; | ||
position: fixed; | ||
position: ${$isFixed ? 'fixed' : 'relative'}; | ||
`} | ||
`; | ||
Wrapper.displayName = 'Wrapper'; | ||
|
@@ -62,75 +62,78 @@ FlexGroup.displayName = 'FlexGroup'; | |
|
||
interface HeaderGlobalProps { | ||
hideDetectionEngine?: boolean; | ||
isFixed?: boolean; | ||
} | ||
export const HeaderGlobal = React.memo( | ||
forwardRef<HTMLDivElement, HeaderGlobalProps>(({ hideDetectionEngine = false }, ref) => { | ||
const { globalHeaderPortalNode } = useGlobalHeaderPortal(); | ||
const { globalFullScreen } = useFullScreen(); | ||
const search = useGetUrlSearch(navTabs.overview); | ||
const { application, http } = useKibana().services; | ||
const { navigateToApp } = application; | ||
const basePath = http.basePath.get(); | ||
const goToOverview = useCallback( | ||
(ev) => { | ||
ev.preventDefault(); | ||
navigateToApp(`${APP_ID}:${SecurityPageName.overview}`, { path: search }); | ||
}, | ||
[navigateToApp, search] | ||
); | ||
return ( | ||
<Wrapper ref={ref} className="siemHeaderGlobal"> | ||
<WrapperContent $globalFullScreen={globalFullScreen}> | ||
<FlexGroup | ||
alignItems="center" | ||
$hasSibling={globalHeaderPortalNode.hasChildNodes()} | ||
justifyContent="spaceBetween" | ||
wrap | ||
> | ||
<FlexItem> | ||
<EuiFlexGroup alignItems="center" responsive={false}> | ||
<FlexItem grow={false}> | ||
<LinkAnchor onClick={goToOverview} href={getAppOverviewUrl(search)}> | ||
<EuiIcon aria-label={i18n.SECURITY_SOLUTION} type="logoSecurity" size="l" /> | ||
</LinkAnchor> | ||
</FlexItem> | ||
|
||
<FlexItem component="nav"> | ||
<SiemNavigation | ||
display="condensed" | ||
navTabs={ | ||
hideDetectionEngine | ||
? pickBy((_, key) => key !== SecurityPageName.detections, navTabs) | ||
: navTabs | ||
} | ||
/> | ||
</FlexItem> | ||
</EuiFlexGroup> | ||
</FlexItem> | ||
<FlexItem grow={false}> | ||
<EuiFlexGroup alignItems="center" gutterSize="s" responsive={false} wrap> | ||
{window.location.pathname.includes(APP_DETECTIONS_PATH) && ( | ||
forwardRef<HTMLDivElement, HeaderGlobalProps>( | ||
({ hideDetectionEngine = false, isFixed = true }, ref) => { | ||
const { globalHeaderPortalNode } = useGlobalHeaderPortal(); | ||
const { globalFullScreen } = useFullScreen(); | ||
const search = useGetUrlSearch(navTabs.overview); | ||
const { application, http } = useKibana().services; | ||
const { navigateToApp } = application; | ||
const basePath = http.basePath.get(); | ||
const goToOverview = useCallback( | ||
(ev) => { | ||
ev.preventDefault(); | ||
navigateToApp(`${APP_ID}:${SecurityPageName.overview}`, { path: search }); | ||
}, | ||
[navigateToApp, search] | ||
); | ||
return ( | ||
<Wrapper ref={ref} $isFixed={isFixed}> | ||
<WrapperContent $globalFullScreen={globalFullScreen}> | ||
<FlexGroup | ||
alignItems="center" | ||
$hasSibling={globalHeaderPortalNode.hasChildNodes()} | ||
justifyContent="spaceBetween" | ||
wrap | ||
> | ||
<FlexItem> | ||
<EuiFlexGroup alignItems="center" responsive={false}> | ||
<FlexItem grow={false}> | ||
<MlPopover /> | ||
<LinkAnchor onClick={goToOverview} href={getAppOverviewUrl(search)}> | ||
<EuiIcon aria-label={i18n.SECURITY_SOLUTION} type="logoSecurity" size="l" /> | ||
</LinkAnchor> | ||
</FlexItem> | ||
|
||
<FlexItem component="nav"> | ||
<SiemNavigation | ||
display="condensed" | ||
navTabs={ | ||
hideDetectionEngine | ||
? pickBy((_, key) => key !== SecurityPageName.detections, navTabs) | ||
: navTabs | ||
} | ||
/> | ||
</FlexItem> | ||
)} | ||
</EuiFlexGroup> | ||
</FlexItem> | ||
<FlexItem grow={false}> | ||
<EuiFlexGroup alignItems="center" gutterSize="s" responsive={false} wrap> | ||
{window.location.pathname.includes(APP_DETECTIONS_PATH) && ( | ||
<FlexItem grow={false}> | ||
<MlPopover /> | ||
</FlexItem> | ||
)} | ||
|
||
<FlexItem grow={false}> | ||
<EuiButtonEmpty | ||
data-test-subj="add-data" | ||
href={`${basePath}${ADD_DATA_PATH}`} | ||
iconType="plusInCircle" | ||
> | ||
{i18n.BUTTON_ADD_DATA} | ||
</EuiButtonEmpty> | ||
</FlexItem> | ||
</EuiFlexGroup> | ||
</FlexItem> | ||
</FlexGroup> | ||
<OutPortal node={globalHeaderPortalNode} /> | ||
</WrapperContent> | ||
</Wrapper> | ||
); | ||
}) | ||
<FlexItem grow={false}> | ||
<EuiButtonEmpty | ||
data-test-subj="add-data" | ||
href={`${basePath}${ADD_DATA_PATH}`} | ||
iconType="plusInCircle" | ||
> | ||
{i18n.BUTTON_ADD_DATA} | ||
</EuiButtonEmpty> | ||
</FlexItem> | ||
</EuiFlexGroup> | ||
</FlexItem> | ||
</FlexGroup> | ||
<OutPortal node={globalHeaderPortalNode} /> | ||
</WrapperContent> | ||
</Wrapper> | ||
); | ||
} | ||
) | ||
); | ||
HeaderGlobal.displayName = 'HeaderGlobal'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a need for
useMemo
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe so, we don't want that prop being updated without the reason