Skip to content

Commit

Permalink
[Security Solution][RAC] Remove toggle column when not usable (#109534)…
Browse files Browse the repository at this point in the history
… (#109708)

Co-authored-by: Michael Olorunnisola <michael.olorunnisola@elastic.co>
  • Loading branch information
kibanamachine and michaelolo24 authored Aug 23, 2021
1 parent e60dc29 commit 60a477c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('useHoverActionItems', () => {
field: 'signal.rule.name',
handleHoverActionClicked: jest.fn(),
hideTopN: false,
isObjectArray: true,
isObjectArray: false,
ownFocus: false,
showTopN: false,
stKeyboardEvent: undefined,
Expand Down Expand Up @@ -130,4 +130,32 @@ describe('useHoverActionItems', () => {
});
});
});

test('should not have toggle column', async () => {
await act(async () => {
const { result, waitForNextUpdate } = renderHook(() => {
const defaultFocusedButtonRef = useRef(null);
const testProps = {
...defaultProps,
isObjectArray: true,
defaultFocusedButtonRef,
enableOverflowButton: true,
};
return useHoverActionItems(testProps);
});
await waitForNextUpdate();

expect(result.current.overflowActionItems).toHaveLength(3);
expect(result.current.overflowActionItems[0].props['data-test-subj']).toEqual(
'hover-actions-filter-for'
);
expect(result.current.overflowActionItems[1].props['data-test-subj']).toEqual(
'hover-actions-filter-out'
);

result.current.overflowActionItems[2].props.items.forEach((item: JSX.Element) => {
expect(item.props['data-test-subj']).not.toEqual('hover-actions-toggle-column');
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* 2.0.
*/

/* eslint-disable complexity */

import { EuiContextMenuItem } from '@elastic/eui';
import React, { useMemo } from 'react';
import { DraggableId } from 'react-beautiful-dnd';
Expand Down Expand Up @@ -118,6 +120,9 @@ export const useHoverActionItems = ({
*/
const showFilters =
values != null && (enableOverflowButton || (!showTopN && !enableOverflowButton));

const shouldDisableColumnToggle = isObjectArray && field !== 'geo_point';

const allItems = useMemo(
() =>
[
Expand Down Expand Up @@ -150,7 +155,7 @@ export const useHoverActionItems = ({
})}
</div>
) : null,
toggleColumn ? (
toggleColumn && !shouldDisableColumnToggle ? (
<div data-test-subj="hover-actions-toggle-column" key="hover-actions-toggle-column">
{getColumnToggleButton({
Component: enableOverflowButton ? EuiContextMenuItem : undefined,
Expand Down Expand Up @@ -236,6 +241,7 @@ export const useHoverActionItems = ({
isObjectArray,
onFilterAdded,
ownFocus,
shouldDisableColumnToggle,
showFilters,
showTopN,
stKeyboardEvent,
Expand Down

0 comments on commit 60a477c

Please sign in to comment.