Skip to content

Commit

Permalink
[Security Solution] Fixes the position of popover when presenting dyn…
Browse files Browse the repository at this point in the history
…amic content (#139079)

## Summary

Issue #133186 ( as shown in below video) demonstrates couple of issues and this PR tries to fix those.

https://user-images.githubusercontent.com/61860752/171141631-f633a223-af76-457d-bed2-6bd8ea418a0e.mp4

**ISSUE - 1**

When in host details flyout, clicking on `show Top N`, the datagrid will flicker scrolling from right to left and then back to its original position.

**Solution** : This issue was not reproducible so I am assuming this has been already resolved. ( See below video for more details)

 
**ISSUE - 2**

When in host details flyout, clicking on `show Top N`, the popup hides behind the bottom screen edge. This is because initially the popup was small but when `Show TopN` is clicked, the content of Popup is changed and popup becomes bigger in size forcing it to exceed out of the screen's real estate.

**Solution** : This PR makes sure that, if hover actions Popup's content changes, Popup is re-positioned according to its new dimensions. Checkout below demonstration.


https://user-images.githubusercontent.com/7485038/185380538-d8fb159a-d666-4be2-b3b0-161a21d1b9d6.mov
  • Loading branch information
logeekal authored Aug 25, 2022
1 parent e1e9a1a commit acf675c
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
HOVER_ACTIONS_ALWAYS_SHOW_CLASS_NAME,
IS_DRAGGING_CLASS_NAME,
} from '@kbn/securitysolution-t-grid';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import styled from 'styled-components';

/**
Expand Down Expand Up @@ -82,6 +82,7 @@ export const WithHoverActions = React.memo<Props>(
const [isOpen, setIsOpen] = useState(hoverContent != null && alwaysShow);
const [showHoverContent, setShowHoverContent] = useState(false);
const [, setHoverTimeout] = useState<number | undefined>(undefined);
const popoverRef = useRef<EuiPopover>(null);

const tryClosePopover = useCallback(() => {
setHoverTimeout((prevHoverTimeout) => {
Expand Down Expand Up @@ -143,12 +144,19 @@ export const WithHoverActions = React.memo<Props>(
setShowHoverContent(false);
}, [closePopOverTrigger]); // NOTE: the `closePopOverTrigger` dependency here will close the hover menu whenever `closePopOverTrigger` changes

useEffect(() => {
// in case of dynamic content i.e when the value of hoverContent changes,
// we will try to reposition the popover so that the content does not collide with screen edge.
if (isOpen) popoverRef?.current?.positionPopoverFluid();
}, [hoverContent, isOpen]);

return (
<div
className={alwaysShow ? HOVER_ACTIONS_ALWAYS_SHOW_CLASS_NAME : ''}
onMouseLeave={onMouseLeave}
>
<WithHoverActionsPopover
ref={popoverRef}
anchorPosition={'downCenter'}
button={content}
closePopover={tryClosePopover}
Expand Down

0 comments on commit acf675c

Please sign in to comment.