Skip to content

Commit

Permalink
[8.x] [Cloud Security] Update graph appearance (#204610) (#204974)
Browse files Browse the repository at this point in the history
# Backport

This will backport the following commits from `main` to `8.x`:
- [[Cloud Security] Update graph appearance
(#204610)](#204610)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Kfir
Peled","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-12-19T14:50:39Z","message":"[Cloud
Security] Update graph appearance (#204610)\n\n## Summary\r\n\r\n- [x]
Remove the unknown or question symbols for entities who's type
we\r\ndon't know\r\n- [x] Replace edges to be sharp path instead of a
smooth one \r\n- [x] Changed background of alerted node from `danger` to
`primary`\r\n- [x] Fix arrow popover color not in sync with background
color \r\n- [x] Handles should be visible as a small dot\r\n- [x] Expand
button's color should be similar to the nodes color\r\n- [x] Main alert
path should be a solid line\r\n\r\nBefore:\r\n\r\n![Screenshot
2024-12-18 at 18
45\r\n31](https://github.com/user-attachments/assets/4fd24ec7-8a8b-4659-8605-a53685be8d78)\r\n\r\n\r\nAfter:\r\n\r\n![Screenshot
2024-12-18 at 19
08\r\n31](https://github.com/user-attachments/assets/ebeae458-075d-48a3-8a42-66787440adc1)\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/4253ec83-19da-4c34-bb80-cb4ca900672d\r\n\r\n\r\n**How
to test**\r\n\r\nTo test this PR you can run\r\n\r\n```\r\nyarn
storybook cloud_security_posture_packages\r\n```\r\n\r\nTo test
e2e\r\n\r\n- Enable the feature flag
\r\n\r\n`kibana.dev.yml`:\r\n\r\n```yaml\r\nuiSettings.overrides.securitySolution:enableVisualizationsInFlyout:
true\r\nxpack.securitySolution.enableExperimental:
['graphVisualizationInFlyoutEnabled']\r\n```\r\n\r\n- Load mocked
data:\r\n\r\n```bash\r\nnode scripts/es_archiver load
x-pack/test/cloud_security_posture_functional/es_archives/logs_gcp_audit
\\ \r\n --es-url http://elastic:changeme@localhost:9200 \\\r\n
--kibana-url http://elastic:changeme@localhost:5601\r\n\r\nnode
scripts/es_archiver load
x-pack/test/cloud_security_posture_functional/es_archives/security_alerts
\\\r\n --es-url http://elastic:changeme@localhost:9200 \\\r\n
--kibana-url http://elastic:changeme@localhost:5601\r\n```\r\n\r\n- Make
sure you include data from Oct 13 2024. (in the video I use
Last\r\nyear)\r\n\r\n\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Sean Rathier
<[email protected]>\r\nCo-authored-by: Brad White
<[email protected]>\r\nCo-authored-by: seanrathier
<[email protected]>","sha":"576f3c5e81fee12cf1146b8d25b25e5ec865ea48","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:Cloud
Security","backport:prev-minor","ci:build-storybooks"],"title":"[Cloud
Security] Update graph
appearance","number":204610,"url":"https://github.com/elastic/kibana/pull/204610","mergeCommit":{"message":"[Cloud
Security] Update graph appearance (#204610)\n\n## Summary\r\n\r\n- [x]
Remove the unknown or question symbols for entities who's type
we\r\ndon't know\r\n- [x] Replace edges to be sharp path instead of a
smooth one \r\n- [x] Changed background of alerted node from `danger` to
`primary`\r\n- [x] Fix arrow popover color not in sync with background
color \r\n- [x] Handles should be visible as a small dot\r\n- [x] Expand
button's color should be similar to the nodes color\r\n- [x] Main alert
path should be a solid line\r\n\r\nBefore:\r\n\r\n![Screenshot
2024-12-18 at 18
45\r\n31](https://github.com/user-attachments/assets/4fd24ec7-8a8b-4659-8605-a53685be8d78)\r\n\r\n\r\nAfter:\r\n\r\n![Screenshot
2024-12-18 at 19
08\r\n31](https://github.com/user-attachments/assets/ebeae458-075d-48a3-8a42-66787440adc1)\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/4253ec83-19da-4c34-bb80-cb4ca900672d\r\n\r\n\r\n**How
to test**\r\n\r\nTo test this PR you can run\r\n\r\n```\r\nyarn
storybook cloud_security_posture_packages\r\n```\r\n\r\nTo test
e2e\r\n\r\n- Enable the feature flag
\r\n\r\n`kibana.dev.yml`:\r\n\r\n```yaml\r\nuiSettings.overrides.securitySolution:enableVisualizationsInFlyout:
true\r\nxpack.securitySolution.enableExperimental:
['graphVisualizationInFlyoutEnabled']\r\n```\r\n\r\n- Load mocked
data:\r\n\r\n```bash\r\nnode scripts/es_archiver load
x-pack/test/cloud_security_posture_functional/es_archives/logs_gcp_audit
\\ \r\n --es-url http://elastic:changeme@localhost:9200 \\\r\n
--kibana-url http://elastic:changeme@localhost:5601\r\n\r\nnode
scripts/es_archiver load
x-pack/test/cloud_security_posture_functional/es_archives/security_alerts
\\\r\n --es-url http://elastic:changeme@localhost:9200 \\\r\n
--kibana-url http://elastic:changeme@localhost:5601\r\n```\r\n\r\n- Make
sure you include data from Oct 13 2024. (in the video I use
Last\r\nyear)\r\n\r\n\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Sean Rathier
<[email protected]>\r\nCo-authored-by: Brad White
<[email protected]>\r\nCo-authored-by: seanrathier
<[email protected]>","sha":"576f3c5e81fee12cf1146b8d25b25e5ec865ea48"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/204610","number":204610,"mergeCommit":{"message":"[Cloud
Security] Update graph appearance (#204610)\n\n## Summary\r\n\r\n- [x]
Remove the unknown or question symbols for entities who's type
we\r\ndon't know\r\n- [x] Replace edges to be sharp path instead of a
smooth one \r\n- [x] Changed background of alerted node from `danger` to
`primary`\r\n- [x] Fix arrow popover color not in sync with background
color \r\n- [x] Handles should be visible as a small dot\r\n- [x] Expand
button's color should be similar to the nodes color\r\n- [x] Main alert
path should be a solid line\r\n\r\nBefore:\r\n\r\n![Screenshot
2024-12-18 at 18
45\r\n31](https://github.com/user-attachments/assets/4fd24ec7-8a8b-4659-8605-a53685be8d78)\r\n\r\n\r\nAfter:\r\n\r\n![Screenshot
2024-12-18 at 19
08\r\n31](https://github.com/user-attachments/assets/ebeae458-075d-48a3-8a42-66787440adc1)\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/4253ec83-19da-4c34-bb80-cb4ca900672d\r\n\r\n\r\n**How
to test**\r\n\r\nTo test this PR you can run\r\n\r\n```\r\nyarn
storybook cloud_security_posture_packages\r\n```\r\n\r\nTo test
e2e\r\n\r\n- Enable the feature flag
\r\n\r\n`kibana.dev.yml`:\r\n\r\n```yaml\r\nuiSettings.overrides.securitySolution:enableVisualizationsInFlyout:
true\r\nxpack.securitySolution.enableExperimental:
['graphVisualizationInFlyoutEnabled']\r\n```\r\n\r\n- Load mocked
data:\r\n\r\n```bash\r\nnode scripts/es_archiver load
x-pack/test/cloud_security_posture_functional/es_archives/logs_gcp_audit
\\ \r\n --es-url http://elastic:changeme@localhost:9200 \\\r\n
--kibana-url http://elastic:changeme@localhost:5601\r\n\r\nnode
scripts/es_archiver load
x-pack/test/cloud_security_posture_functional/es_archives/security_alerts
\\\r\n --es-url http://elastic:changeme@localhost:9200 \\\r\n
--kibana-url http://elastic:changeme@localhost:5601\r\n```\r\n\r\n- Make
sure you include data from Oct 13 2024. (in the video I use
Last\r\nyear)\r\n\r\n\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Sean Rathier
<[email protected]>\r\nCo-authored-by: Brad White
<[email protected]>\r\nCo-authored-by: seanrathier
<[email protected]>","sha":"576f3c5e81fee12cf1146b8d25b25e5ec865ea48"}}]}]
BACKPORT-->

Co-authored-by: Kfir Peled <[email protected]>
  • Loading branch information
kibanamachine and kfirpeled authored Dec 19, 2024
1 parent 78fc144 commit d3a325a
Show file tree
Hide file tree
Showing 19 changed files with 337 additions and 195 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,5 @@ export const edgeDataSchema = schema.object({
source: schema.string(),
target: schema.string(),
color: colorSchema,
type: schema.maybe(schema.oneOf([schema.literal('solid'), schema.literal('dashed')])),
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import React from 'react';
import React, { useEffect, useMemo, useRef } from 'react';
import { ThemeProvider } from '@emotion/react';
import {
ReactFlow,
Expand All @@ -17,14 +17,18 @@ import {
useEdgesState,
type BuiltInNode,
type NodeProps,
type Node as xyNode,
type Edge as xyEdge,
} from '@xyflow/react';
import { isEmpty, isEqual, pick, size, xorWith } from 'lodash';
import { Story } from '@storybook/react';
import { SvgDefsMarker } from './styles';
import { DefaultEdge } from '.';
import { LabelNode } from '../node';
import type { EdgeViewModel } from '../types';
import { SvgDefsMarker } from './markers';

import '@xyflow/react/dist/style.css';
import { LabelNode } from '../node';
import type { NodeViewModel } from '../types';
import { HandleStyleOverride } from '../node/styles';

export default {
title: 'Components/Graph Components/Default Edge',
Expand All @@ -34,22 +38,32 @@ export default {
options: ['primary', 'danger', 'warning'],
control: { type: 'radio' },
},
type: {
options: ['solid', 'dashed'],
control: { type: 'radio' },
},
},
};

const nodeTypes = {
default: ((props: NodeProps<BuiltInNode>) => {
const handleStyle = {
width: 0,
height: 0,
'min-width': 0,
'min-height': 0,
border: 'none',
};
// eslint-disable-next-line react/display-name
default: React.memo((props: NodeProps<BuiltInNode>) => {
return (
<div>
<Handle type="source" position={Position.Right} style={handleStyle} />
<Handle type="target" position={Position.Left} style={handleStyle} />
<Handle
type="target"
isConnectable={false}
position={Position.Left}
id="in"
style={HandleStyleOverride}
/>
<Handle
type="source"
isConnectable={false}
position={Position.Right}
id="out"
style={HandleStyleOverride}
/>
{props.data.label}
</div>
);
Expand All @@ -61,79 +75,101 @@ const edgeTypes = {
default: DefaultEdge,
};

const Template: Story<NodeViewModel> = (args: NodeViewModel) => {
const initialNodes = [
{
id: 'source',
type: 'default',
data: { label: 'source' },
position: { x: 0, y: 0 },
draggable: true,
},
{
id: 'target',
type: 'default',
data: { label: 'target' },
position: { x: 320, y: 100 },
draggable: true,
},
{
id: args.id,
type: 'label',
data: args,
position: { x: 160, y: 50 },
draggable: true,
},
];
const Template: Story<EdgeViewModel> = (args: EdgeViewModel) => {
const nodes = useMemo(
() => [
{
id: 'source',
type: 'default',
data: {
label: 'source',
},
position: { x: 0, y: 0 },
},
{
id: 'target',
type: 'default',
data: {
label: 'target',
},
position: { x: 420, y: 0 },
},
{
id: args.id,
type: 'label',
data: pick(args, ['id', 'label', 'interactive', 'source', 'target', 'color', 'type']),
position: { x: 230, y: 6 },
},
],
[args]
);

const initialEdges = [
{
id: `source-${args.id}`,
source: 'source',
target: args.id,
data: {
const edges = useMemo(
() => [
{
id: `source-${args.id}`,
source: 'source',
sourceShape: 'rectangle',
target: args.id,
targetShape: 'label',
color: args.color,
interactive: true,
data: {
id: `source-${args.id}`,
source: 'source',
sourceShape: 'custom',
target: args.id,
targetShape: 'label',
color: args.color,
type: args.type,
},
type: 'default',
},
type: 'default',
},
{
id: `${args.id}-target`,
source: args.id,
target: 'target',
data: {
{
id: `${args.id}-target`,
source: args.id,
sourceShape: 'label',
target: 'target',
targetShape: 'rectangle',
color: args.color,
interactive: true,
data: {
id: `${args.id}-target`,
source: args.id,
sourceShape: 'label',
target: 'target',
targetShape: 'custom',
color: args.color,
type: args.type,
},
type: 'default',
},
type: 'default',
},
];
],
[args]
);

const [nodes, _setNodes, onNodesChange] = useNodesState(initialNodes);
const [edges, _setEdges, onEdgesChange] = useEdgesState(initialEdges);
const [nodesState, setNodes, onNodesChange] = useNodesState<xyNode>(nodes);
const [edgesState, setEdges, onEdgesChange] = useEdgesState<xyEdge<EdgeViewModel>>(edges);
const currNodesRef = useRef(nodes);
const currEdgesRef = useRef(edges);

useEffect(() => {
if (
!isArrayOfObjectsEqual(nodes, currNodesRef.current) ||
!isArrayOfObjectsEqual(edges, currEdgesRef.current)
) {
setNodes(nodes);
setEdges(edges);
currNodesRef.current = nodes;
currEdgesRef.current = edges;
}
}, [setNodes, setEdges, nodes, edges]);

return (
<ThemeProvider theme={{ darkMode: false }}>
<SvgDefsMarker />
<ReactFlow
fitView
attributionPosition={undefined}
nodesDraggable={true}
nodeTypes={nodeTypes}
edgeTypes={edgeTypes}
onNodesChange={onNodesChange}
onEdgesChange={onEdgesChange}
nodes={nodes}
edges={edges}
nodes={nodesState}
edges={edgesState}
>
<Controls />
<Background />
Expand All @@ -148,6 +184,9 @@ Edge.args = {
id: 'siem-windows',
label: 'User login to OKTA',
color: 'primary',
icon: 'okta',
interactive: true,
type: 'solid',
};

const isArrayOfObjectsEqual = (x: object[], y: object[]) =>
size(x) === size(y) && isEmpty(xorWith(x, y, isEqual));
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
*/

import React from 'react';
import { BaseEdge, getBezierPath } from '@xyflow/react';
import { BaseEdge, getSmoothStepPath } from '@xyflow/react';
import { useEuiTheme } from '@elastic/eui';
import type { Color } from '@kbn/cloud-security-posture-common/types/graph/latest';
import type { EdgeProps } from '../types';
import { getMarker } from './styles';
import type { EdgeProps, EdgeViewModel } from '../types';
import { getShapeHandlePosition } from './utils';
import { getMarkerStart, getMarkerEnd } from './markers';

type EdgeColor = EdgeViewModel['color'];

export function DefaultEdge({
id,
Expand All @@ -25,22 +26,18 @@ export function DefaultEdge({
data,
}: EdgeProps) {
const { euiTheme } = useEuiTheme();
const color: Color = data?.color ?? 'primary';
const color: EdgeColor = data?.color ?? 'primary';

const [edgePath] = getBezierPath({
const [edgePath] = getSmoothStepPath({
// sourceX and targetX are adjusted to account for the shape handle position
sourceX: sourceX - getShapeHandlePosition(data?.sourceShape),
sourceY,
sourcePosition,
targetX: targetX + getShapeHandlePosition(data?.targetShape),
targetY,
targetPosition,
curvature:
0.1 *
(data?.sourceShape === 'group' ||
(data?.sourceShape === 'label' && data?.targetShape === 'group')
? -1 // We flip direction when the edge is between parent node to child nodes (groups always contain children in our graph)
: 1),
borderRadius: 15,
offset: 0,
});

return (
Expand All @@ -50,12 +47,19 @@ export function DefaultEdge({
style={{
stroke: euiTheme.colors[color],
}}
css={{
strokeDasharray: '2,2',
}}
css={
(!data?.type || data?.type === 'dashed') && {
strokeDasharray: '2,2',
}
}
markerStart={
data?.sourceShape !== 'label' && data?.sourceShape !== 'group'
? getMarkerStart(color)
: undefined
}
markerEnd={
data?.targetShape !== 'label' && data?.targetShape !== 'group'
? getMarker(color)
? getMarkerEnd(color)
: undefined
}
/>
Expand Down
Loading

0 comments on commit d3a325a

Please sign in to comment.