forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Cloud Security] Added labels popover (elastic#204954)
## Summary Added expand button for labels with popover: https://github.com/user-attachments/assets/80950f51-b45b-4174-9be2-267b6aca569b https://github.com/user-attachments/assets/690ef85b-be48-42df-bf00-02ee7d9303f2 **How to test** To test this PR you can run ``` yarn storybook cloud_security_posture_packages ``` To test e2e - Enable the feature flag `kibana.dev.yml`: ```yml uiSettings.overrides.securitySolution:enableVisualizationsInFlyout: true xpack.securitySolution.enableExperimental: ['graphVisualizationInFlyoutEnabled'] ``` - Load mocked data: ``` node scripts/es_archiver load x-pack/test/cloud_security_posture_functional/es_archives/logs_gcp_audit \ --es-url http://elastic:changeme@localhost:9200 \ --kibana-url http://elastic:changeme@localhost:5601 node scripts/es_archiver load x-pack/test/cloud_security_posture_functional/es_archives/security_alerts \ --es-url http://elastic:changeme@localhost:9200 \ --kibana-url http://elastic:changeme@localhost:5601 ``` - Make sure you include data from Oct 13 2024. (in the video I use Last year) ### Checklist - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed --------- Co-authored-by: Sean Rathier <[email protected]> Co-authored-by: Brad White <[email protected]> Co-authored-by: seanrathier <[email protected]> Co-authored-by: kibanamachine <[email protected]> (cherry picked from commit fd47d2e)
- Loading branch information
Showing
31 changed files
with
376 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...-security-posture/graph/src/components/graph_investigation/graph_label_expand_popover.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React, { memo } from 'react'; | ||
import { EuiListGroup } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { ExpandPopoverListItem } from '../styles'; | ||
import { GraphPopover } from '../../..'; | ||
import { | ||
GRAPH_LABEL_EXPAND_POPOVER_TEST_ID, | ||
GRAPH_LABEL_EXPAND_POPOVER_SHOW_EVENTS_WITH_THIS_ACTION_ITEM_ID, | ||
} from '../test_ids'; | ||
|
||
interface GraphLabelExpandPopoverProps { | ||
isOpen: boolean; | ||
anchorElement: HTMLElement | null; | ||
closePopover: () => void; | ||
onShowEventsWithThisActionClick: () => void; | ||
} | ||
|
||
export const GraphLabelExpandPopover = memo<GraphLabelExpandPopoverProps>( | ||
({ isOpen, anchorElement, closePopover, onShowEventsWithThisActionClick }) => { | ||
return ( | ||
<GraphPopover | ||
panelPaddingSize="s" | ||
anchorPosition="rightCenter" | ||
isOpen={isOpen} | ||
anchorElement={anchorElement} | ||
closePopover={closePopover} | ||
data-test-subj={GRAPH_LABEL_EXPAND_POPOVER_TEST_ID} | ||
> | ||
<EuiListGroup gutterSize="none" bordered={false} flush={true}> | ||
<ExpandPopoverListItem | ||
iconType="users" | ||
label={i18n.translate( | ||
'securitySolutionPackages.csp.graph.graphLabelExpandPopover.showEventsWithThisAction', | ||
{ defaultMessage: 'Show events with this action' } | ||
)} | ||
onClick={onShowEventsWithThisActionClick} | ||
data-test-subj={GRAPH_LABEL_EXPAND_POPOVER_SHOW_EVENTS_WITH_THIS_ACTION_ITEM_ID} | ||
/> | ||
</EuiListGroup> | ||
</GraphPopover> | ||
); | ||
} | ||
); | ||
|
||
GraphLabelExpandPopover.displayName = 'GraphLabelExpandPopover'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
...urity-posture/graph/src/components/graph_investigation/use_graph_label_expand_popover.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React, { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react'; | ||
import { useGraphPopover } from '../../..'; | ||
import type { ExpandButtonClickCallback, NodeProps } from '../types'; | ||
import type { PopoverActions } from '../graph/use_graph_popover'; | ||
import { GraphLabelExpandPopover } from './graph_label_expand_popover'; | ||
|
||
interface UseGraphLabelExpandPopoverArgs { | ||
onShowEventsWithThisActionClick: (node: NodeProps) => void; | ||
} | ||
|
||
export const useGraphLabelExpandPopover = ({ | ||
onShowEventsWithThisActionClick, | ||
}: UseGraphLabelExpandPopoverArgs) => { | ||
const { id, state, actions } = useGraphPopover('label-expand-popover'); | ||
const { openPopover, closePopover } = actions; | ||
|
||
const selectedNode = useRef<NodeProps | null>(null); | ||
const unToggleCallbackRef = useRef<(() => void) | null>(null); | ||
const [pendingOpen, setPendingOpen] = useState<{ | ||
node: NodeProps; | ||
el: HTMLElement; | ||
unToggleCallback: () => void; | ||
} | null>(null); | ||
|
||
const closePopoverHandler = useCallback(() => { | ||
selectedNode.current = null; | ||
unToggleCallbackRef.current?.(); | ||
unToggleCallbackRef.current = null; | ||
closePopover(); | ||
}, [closePopover]); | ||
|
||
const onLabelExpandButtonClick: ExpandButtonClickCallback = useCallback( | ||
(e, node, unToggleCallback) => { | ||
if (selectedNode.current?.id === node.id) { | ||
// If the same node is clicked again, close the popover | ||
closePopoverHandler(); | ||
} else { | ||
// Close the current popover if open | ||
closePopoverHandler(); | ||
|
||
// Set the pending open state | ||
setPendingOpen({ node, el: e.currentTarget, unToggleCallback }); | ||
} | ||
}, | ||
[closePopoverHandler] | ||
); | ||
|
||
useEffect(() => { | ||
// Open pending popover if the popover is not open | ||
if (!state.isOpen && pendingOpen) { | ||
const { node, el, unToggleCallback } = pendingOpen; | ||
|
||
selectedNode.current = node; | ||
unToggleCallbackRef.current = unToggleCallback; | ||
openPopover(el); | ||
|
||
setPendingOpen(null); | ||
} | ||
}, [state.isOpen, pendingOpen, openPopover]); | ||
|
||
const PopoverComponent = memo(() => ( | ||
<GraphLabelExpandPopover | ||
isOpen={state.isOpen} | ||
anchorElement={state.anchorElement} | ||
closePopover={closePopoverHandler} | ||
onShowEventsWithThisActionClick={() => { | ||
onShowEventsWithThisActionClick(selectedNode.current as NodeProps); | ||
closePopoverHandler(); | ||
}} | ||
/> | ||
)); | ||
|
||
PopoverComponent.displayName = GraphLabelExpandPopover.displayName; | ||
|
||
const actionsWithClose: PopoverActions = useMemo( | ||
() => ({ | ||
...actions, | ||
closePopover: closePopoverHandler, | ||
}), | ||
[actions, closePopoverHandler] | ||
); | ||
|
||
return useMemo( | ||
() => ({ | ||
onLabelExpandButtonClick, | ||
PopoverComponent, | ||
id, | ||
actions: actionsWithClose, | ||
state, | ||
}), | ||
[PopoverComponent, actionsWithClose, id, onLabelExpandButtonClick, state] | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.