From 71afebb2c04fc3b48cd9e4c71394160f5c184e98 Mon Sep 17 00:00:00 2001 From: balibabu Date: Mon, 23 Jun 2025 15:27:34 +0800 Subject: [PATCH] Feat: The delete button is displayed only when the cursor is hovered over the connection line #3221 (#8422) ### What problem does this PR solve? Feat: The delete button is displayed only when the cursor is hovered over the connection line #3221 ### Type of change - [x] New Feature (non-breaking change which adds functionality) --- web/src/pages/agent/canvas/edge/index.tsx | 24 +++++++++++++++++---- web/src/pages/agent/canvas/index.tsx | 4 ++++ web/src/pages/agent/canvas/node/toolbar.tsx | 23 ++++++++++++-------- web/src/pages/agent/hooks.tsx | 2 ++ web/src/pages/agent/store.ts | 19 ++++++++++++++++ web/src/pages/agent/utils.ts | 20 +++++++++++++++++ 6 files changed, 79 insertions(+), 13 deletions(-) diff --git a/web/src/pages/agent/canvas/edge/index.tsx b/web/src/pages/agent/canvas/edge/index.tsx index 2b67cdbad..aa6e8f94d 100644 --- a/web/src/pages/agent/canvas/edge/index.tsx +++ b/web/src/pages/agent/canvas/edge/index.tsx @@ -1,5 +1,6 @@ import { BaseEdge, + Edge, EdgeLabelRenderer, EdgeProps, getBezierPath, @@ -8,7 +9,9 @@ import useGraphStore from '../../store'; import { useTheme } from '@/components/theme-provider'; import { useFetchAgent } from '@/hooks/use-agent-request'; +import { cn } from '@/lib/utils'; import { useMemo } from 'react'; +import { NodeHandleId, Operator } from '../../constant'; import styles from './index.less'; export function ButtonEdge({ @@ -24,7 +27,9 @@ export function ButtonEdge({ style = {}, markerEnd, selected, -}: EdgeProps) { + data, + sourceHandleId, +}: EdgeProps>) { const deleteEdgeById = useGraphStore((state) => state.deleteEdgeById); const [edgePath, labelX, labelY] = getBezierPath({ sourceX, @@ -72,6 +77,14 @@ export function ButtonEdge({ return {}; }, [source, target, graphPath]); + const visible = useMemo(() => { + return ( + data?.isHovered && + sourceHandleId !== NodeHandleId.Tool && // The connection between the agent node and the tool node does not need to display the delete button + !target.startsWith(Operator.Tool) + ); + }, [data?.isHovered, sourceHandleId, target]); + return ( <> +