From f2be3afa54b3e25207a0d57c9be0dc879d5f2dec Mon Sep 17 00:00:00 2001 From: Manan Vaghasiya Date: Thu, 2 Nov 2023 13:39:00 +0000 Subject: [PATCH] show expand collapse state for graph nodes --- .../components/icons/common/ResizeDown.tsx | 21 +++++++++++++++++++ .../topology/components/TopologyGraph.tsx | 21 ++++++++++++++++--- 2 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 deepfence_frontend/apps/dashboard/src/components/icons/common/ResizeDown.tsx diff --git a/deepfence_frontend/apps/dashboard/src/components/icons/common/ResizeDown.tsx b/deepfence_frontend/apps/dashboard/src/components/icons/common/ResizeDown.tsx new file mode 100644 index 0000000000..ecff78aa87 --- /dev/null +++ b/deepfence_frontend/apps/dashboard/src/components/icons/common/ResizeDown.tsx @@ -0,0 +1,21 @@ +export const ResizeDownIcon = () => { + return ( + + + + + + ); +}; diff --git a/deepfence_frontend/apps/dashboard/src/features/topology/components/TopologyGraph.tsx b/deepfence_frontend/apps/dashboard/src/features/topology/components/TopologyGraph.tsx index a50780ff88..05d81a5219 100644 --- a/deepfence_frontend/apps/dashboard/src/features/topology/components/TopologyGraph.tsx +++ b/deepfence_frontend/apps/dashboard/src/features/topology/components/TopologyGraph.tsx @@ -1,4 +1,4 @@ -import { useEffect, useRef, useState } from 'react'; +import { useEffect, useMemo, useRef, useState } from 'react'; import { useFetcher, useParams } from 'react-router-dom'; import { useDebounce, useEffectOnce, useHoverDirty, useMeasure } from 'react-use'; import { cn } from 'tailwind-preset'; @@ -7,6 +7,7 @@ import { CircleSpinner } from 'ui-components'; import { DFLink } from '@/components/DFLink'; import { DetailsLineIcon } from '@/components/icons/common/DetailsLine'; import { ErrorStandardSolidIcon } from '@/components/icons/common/ErrorStandardSolid'; +import { ResizeDownIcon } from '@/components/icons/common/ResizeDown'; import { ResizeUpIcon } from '@/components/icons/common/ResizeUp'; import { NodeDetailsStackedModal } from '@/features/topology/components/NodeDetailsStackedModal'; import { @@ -208,7 +209,9 @@ export const TopologyGraph = () => { ref={tooltipRef} > { setDebouncedTooltipLoc((prev) => { return { ...prev, show: false }; @@ -282,15 +285,27 @@ const GraphTooltip = ({ item, onExpandCollapseClick, onViewDetailsClick, + isNodeExpanded, + visible, }: { item: G6Node | null; onExpandCollapseClick: (model: NodeModel) => void; onViewDetailsClick: (model: NodeModel) => void; + isNodeExpanded: ({ nodeId, nodeType }: { nodeId: string; nodeType: string }) => boolean; + visible: boolean; }) => { const model = item?.getModel() as NodeModel | undefined; if (!model) return null; const expands = itemExpands(model.df_data); const hasDetails = itemHasDetails(model.df_data); + + const expanded = useMemo(() => { + if (model.df_data?.id && model.df_data.type) { + return isNodeExpanded({ nodeId: model.df_data.id, nodeType: model.df_data.type }); + } + return false; + }, [model.df_data, isNodeExpanded, visible]); + return (
- + {expanded ? : }
-
Expand / Collapse
+
{expanded ? 'Collapse' : 'Expand'}
)}