Skip to content

A modern platform for visual, flexible, and extensible graph-based investigations. For cybersecurity analysts and investigators.

feat(app): actions on edges

dextmorgn64c0a8226c5a
diff --git a/flowsint-app/src/api/sketch-service.ts b/flowsint-app/src/api/sketch-service.ts
index ce9642bf..496c4120 100644
--- a/flowsint-app/src/api/sketch-service.ts
+++ b/flowsint-app/src/api/sketch-service.ts
@@ -51,6 +51,12 @@ export const sketchService = {
body: body
})
},
+ deleteEdges: async (sketchId: string, body: BodyInit): Promise<any> => {
+ return fetchWithAuth(`/api/sketches/${sketchId}/relationships`, {
+ method: 'DELETE',
+ body: body
+ })
+ },
updateNode: async (sketchId: string, body: BodyInit): Promise<any> => {
return fetchWithAuth(`/api/sketches/${sketchId}/nodes/edit`, {
method: 'PUT',
diff --git a/flowsint-app/src/components/graphs/details-panel/edge-details-panel.tsx b/flowsint-app/src/components/graphs/details-panel/edge-details-panel.tsx
new file mode 100644
index 00000000..a1d30528
--- /dev/null
+++ b/flowsint-app/src/components/graphs/details-panel/edge-details-panel.tsx
@@ -0,0 +1,167 @@
+import { memo, useCallback } from 'react'
+import { Button } from '@/components/ui/button'
+import { Trash2, ArrowRight, MousePointer } from 'lucide-react'
+import { useGraphStore } from '@/stores/graph-store'
+import { useParams } from '@tanstack/react-router'
+import { toast } from 'sonner'
+import { useIcon } from '@/hooks/use-icon'
+import { useConfirm } from '@/components/use-confirm-dialog'
+import { sketchService } from '@/api/sketch-service'
+import { CopyButton } from '@/components/copy'
+import { GraphEdge } from '@/types'
+import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'
+
+const EdgeDetailsPanel = memo(({ edge }: { edge: GraphEdge | null }) => {
+ const { id: sketchId } = useParams({ strict: false })
+ const edges = useGraphStore((s) => s.edges)
+ const nodes = useGraphStore((s) => s.nodes)
+ const setCurrentNode = useGraphStore((s) => s.setCurrentNode)
+ const setCurrentEdge = useGraphStore((s) => s.setCurrentEdge)
+ const removeEdges = useGraphStore((s) => s.removeEdges)
+ const { confirm } = useConfirm()
+
+ // Get fresh edge data from store
+ edge = edges.find((e) => e.id === edge?.id) || null
+
+ // Find source and target nodes
+ const sourceNode = edge ? nodes.find((n) => n.id === edge.source) : null
+ const targetNode = edge ? nodes.find((n) => n.id === edge.target) : null
+
+ const SourceIcon = useIcon(sourceNode?.data?.type ?? "default", sourceNode?.data?.src)
+ const TargetIcon = useIcon(targetNode?.data?.type ?? "default", targetNode?.data?.src)
+
+ const handleDelete = useCallback(async () => {
+ if (!edge || !sketchId) return
+
+ if (
+ !(await confirm({
+ title: 'You are about to delete this relationship?',
+ message: 'The action is irreversible.'
+ }))
+ ) {
+ return
+ }
+
+ // Close panel
+ setCurrentEdge(null)
+
+ // Optimistic delete + API call with toast
+ toast.promise(
+ (async () => {
+ removeEdges([edge.id])
+ return sketchService.deleteEdges(
+ sketchId as string,
+ JSON.stringify({ relationshipIds: [edge.id] })
+ )
+ })(),
+ {
+ loading: 'Deleting relationship...',
+ success: 'Relationship deleted successfully.',
+ error: 'Failed to delete relationship.'
+ }
+ )
+ }, [edge, sketchId, confirm, removeEdges, setCurrentEdge])
+
+ const handleJumpToSource = useCallback(() => {
+ if (sourceNode) {
+ setCurrentNode(sourceNode)
+ }
+ }, [sourceNode, setCurrentNode])
+
+ const handleJumpToTarget = useCallback(() => {
+ if (targetNode) {
+ setCurrentNode(targetNode)
+ }
+ }, [targetNode, setCurrentNode])
+
+ if (!edge) {
+ return (
+ <div className="flex p-12 rounded-xl border flex-col items-center justify-center h-full text-center p-8">
+ <div className="w-16 h-16 bg-muted rounded-full flex items-center justify-center mb-4">
+ <MousePointer className="h-8 w-8 text-muted-foreground" />
+ </div>
+ <h3 className="text-lg font-semibold text-foreground mb-2">No Relationship Selected</h3>
+ <p className="text-sm text-muted-foreground max-w-xs">
+ Click on any relationship in the graph to view its details
+ </p>
+ </div>
+ )
+ }
+
+ return (
+ <div className="flex items-center h-10 bg-card border-b px-3 gap-2">
+ {/* Source */}
+ {sourceNode && (
+ <TooltipProvider>
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <button
+ onClick={handleJumpToSource}
+ className="flex items-center justify-center w-6 h-6 rounded-full bg-muted hover:bg-muted/80 flex-shrink-0"
+ >
+ <SourceIcon className="h-3 w-3" />
+ </button>
+ </TooltipTrigger>
+ <TooltipContent>
+ <p>{sourceNode.data.label}</p>
+ </TooltipContent>
+ </Tooltip>
+ </TooltipProvider>
+ )}
+
+ {/* Arrow */}
+ <ArrowRight className="h-3 w-3 text-muted-foreground flex-shrink-0" />
+
+ {/* Label */}
+ <div className="flex-1 min-w-0 flex items-center gap-1">
+ <span className="text-xs font-medium truncate">{edge.label || 'Relationship'}</span>
+ {edge.label && <CopyButton content={edge.label} size="icon" className="h-5 w-5 flex-shrink-0" />}
+ </div>
+
+ {/* Arrow */}
+ <ArrowRight className="h-3 w-3 text-muted-foreground flex-shrink-0" />
+
+ {/* Target */}
+ {targetNode && (
+ <TooltipProvider>
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <button
+ onClick={handleJumpToTarget}
+ className="flex items-center justify-center w-6 h-6 rounded-full bg-muted hover:bg-muted/80 flex-shrink-0"
+ >
+ <TargetIcon className="h-3 w-3" />
+ </button>
+ </TooltipTrigger>
+ <TooltipContent>
+ <p>{targetNode.data.label}</p>
+ </TooltipContent>
+ </Tooltip>
+ </TooltipProvider>
+ )}
+
+ {/* Delete */}
+ <TooltipProvider>
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <Button
+ variant="ghost"
+ size="sm"
+ onClick={handleDelete}
+ className="h-6 w-6 p-0 hover:bg-muted opacity-70 hover:opacity-100 text-destructive hover:text-destructive flex-shrink-0"
+ >
+ <Trash2 className="h-3 w-3" strokeWidth={2} />
+ </Button>
+ </TooltipTrigger>
+ <TooltipContent>
+ <p>Delete relationship</p>
+ </TooltipContent>
+ </Tooltip>
+ </TooltipProvider>
+ </div>
+ )
+})
+
+EdgeDetailsPanel.displayName = 'EdgeDetailsPanel'
+
+export default EdgeDetailsPanel
diff --git a/flowsint-app/src/components/graphs/edge-context-menu.tsx b/flowsint-app/src/components/graphs/edge-context-menu.tsx
new file mode 100644
index 00000000..4c49af39
--- /dev/null
+++ b/flowsint-app/src/components/graphs/edge-context-menu.tsx
@@ -0,0 +1,127 @@
+import React, { useCallback } from 'react'
+import { Button } from '@/components/ui/button'
+import { Trash2 } from 'lucide-react'
+import { GraphEdge } from '@/types'
+import BaseContextMenu from '@/components/xyflow/context-menu'
+import { CopyButton } from '../copy'
+import { sketchService } from '@/api/sketch-service'
+import { useParams } from '@tanstack/react-router'
+import { useGraphStore } from '@/stores/graph-store'
+import { useConfirm } from '@/components/use-confirm-dialog'
+import { toast } from 'sonner'
+
+interface EdgeContextMenuProps {
+ edge?: GraphEdge
+ edges?: GraphEdge[]
+ top?: number
+ left?: number
+ right?: number
+ bottom?: number
+ rawTop?: number
+ rawLeft?: number
+ wrapperWidth: number
+ wrapperHeight: number
+ setMenu: (menu: any | null) => void
+ [key: string]: any
+}
+
+export default function EdgeContextMenu({
+ edge,
+ edges,
+ top,
+ left,
+ right,
+ bottom,
+ wrapperWidth,
+ wrapperHeight,
+ setMenu,
+ ...props
+}: EdgeContextMenuProps) {
+ const { id: sketchId } = useParams({ strict: false })
+ const removeEdges = useGraphStore((s) => s.removeEdges)
+ const clearSelectedEdges = useGraphStore((s) => s.clearSelectedEdges)
+ const { confirm } = useConfirm()
+
+ // Determine if multi-select or single
+ const isMultiSelect = edges && edges.length > 0
+ const edgesToDelete = isMultiSelect ? edges : edge ? [edge] : []
+ const edgeIds = edgesToDelete.map((e) => e.id)
+
+ const handleDelete = useCallback(async (e: React.MouseEvent) => {
+ e.stopPropagation()
+
+ if (edgeIds.length === 0 || !sketchId) return
+
+ // Confirm deletion
+ const count = edgeIds.length
+ if (
+ !(await confirm({
+ title: `You are about to delete ${count} relationship${count > 1 ? 's' : ''}?`,
+ message: 'The action is irreversible.'
+ }))
+ ) {
+ return
+ }
+
+ // Close menu
+ setMenu(null)
+
+ // Optimistic delete + API call with toast
+ toast.promise(
+ (async () => {
+ // Optimistic update
+ removeEdges(edgeIds)
+ if (isMultiSelect) clearSelectedEdges()
+ // API call
+ return sketchService.deleteEdges(
+ sketchId,
+ JSON.stringify({ relationshipIds: edgeIds })
+ )
+ })(),
+ {
+ loading: `Deleting ${count} relationship${count > 1 ? 's' : ''}...`,
+ success: `Relationship${count > 1 ? 's' : ''} deleted successfully.`,
+ error: 'Failed to delete relationship.'
+ }
+ )
+ }, [edgeIds, sketchId, setMenu, removeEdges, clearSelectedEdges, isMultiSelect, confirm])
+
+ return (
+ <BaseContextMenu
+ top={top}
+ left={left}
+ right={right}
+ bottom={bottom}
+ wrapperWidth={wrapperWidth}
+ wrapperHeight={wrapperHeight}
+ setMenu={setMenu}
+ {...props}
+ >
+ {/* Header with label */}
+ <div className="px-3 py-2 border-b border-border flex items-center justify-between flex-shrink-0">
+ <div className="flex text-xs items-center gap-1 truncate">
+ {isMultiSelect ? (
+ <span className="block truncate">{edgeIds.length} relationships selected</span>
+ ) : (
+ <span className="block truncate">{edge?.label || 'Relationship'}</span>
+ )}
+ </div>
+ </div>
+
+ {/* Actions */}
+ <div className="p-1 flex gap-1">
+ {!isMultiSelect && edge && (
+ <CopyButton size="icon" content={edge.label} className="h-7 w-7" />
+ )}
+ <Button
+ onClick={handleDelete}
+ size="icon"
+ variant="ghost"
+ className="h-7 w-7"
+ >
+ <Trash2 className="!h-3.5 !w-3.5 opacity-50" />
+ </Button>
+ </div>
+ </BaseContextMenu>
+ )
+}
diff --git a/flowsint-app/src/components/graphs/graph-main.tsx b/flowsint-app/src/components/graphs/graph-main.tsx
index ed0d4317..e8738536 100644
--- a/flowsint-app/src/components/graphs/graph-main.tsx
+++ b/flowsint-app/src/components/graphs/graph-main.tsx
@@ -4,6 +4,7 @@ import GraphViewer from './graph-viewer'
// import WebGLGraphViewer from './webgl'
import NodeContextMenu from './node-context-menu'
import BackgroundContextMenu from './background-context-menu'
+import EdgeContextMenu from './edge-context-menu'
import { useParams } from '@tanstack/react-router'
const GraphMain = () => {
@@ -12,11 +13,15 @@ const GraphMain = () => {
const filteredEdges = useGraphStore((s) => s.filteredEdges)
const toggleNodeSelection = useGraphStore((s) => s.toggleNodeSelection)
const clearSelectedNodes = useGraphStore((s) => s.clearSelectedNodes)
+ const clearSelectedEdges = useGraphStore((s) => s.clearSelectedEdges)
+ const setCurrentEdge = useGraphStore((s) => s.setCurrentEdge)
const selectedNodes = useGraphStore(s => s.selectedNodes)
+ const selectedEdges = useGraphStore(s => s.selectedEdges)
const graphRef = useRef<any>(null)
const containerRef = useRef<HTMLDivElement>(null)
const [nodeMenu, setNodeMenu] = React.useState<any>(null)
+ const [edgeMenu, setEdgeMenu] = React.useState<any>(null)
const [background, setBackgroundMenu] = React.useState<any>(null)
const handleNodeClick = useCallback(
@@ -29,9 +34,12 @@ const GraphMain = () => {
const handleBackgroundClick = useCallback(() => {
clearSelectedNodes()
+ clearSelectedEdges()
+ setCurrentEdge(null)
setNodeMenu(null)
+ setEdgeMenu(null)
setBackgroundMenu(null)
- }, [clearSelectedNodes])
+ }, [clearSelectedNodes, clearSelectedEdges, setCurrentEdge])
const onNodeContextMenu = useCallback((node: any, event: MouseEvent) => {
if (!containerRef.current || !node) return
@@ -71,6 +79,42 @@ const GraphMain = () => {
})
}, [selectedNodes])
+ const onEdgeContextMenu = useCallback((edge: any, event: MouseEvent) => {
+ if (!containerRef.current || !edge) return
+
+ const pane = containerRef.current.getBoundingClientRect()
+ const relativeX = event.clientX - pane.left
+ const relativeY = event.clientY - pane.top
+
+ // If multiple edges are selected, show multi-select menu
+ if (selectedEdges.length > 0) {
+ setEdgeMenu({
+ edges: selectedEdges,
+ rawTop: relativeY,
+ rawLeft: relativeX,
+ wrapperWidth: pane.width,
+ wrapperHeight: pane.height,
+ setMenu: setEdgeMenu,
+ onClick: handleBackgroundClick
+ })
+ } else {
+ // Otherwise show single edge menu
+ setEdgeMenu({
+ edge: {
+ id: edge.id || '',
+ label: edge.label || edge.edgeLabel || ''
+ },
+ rawTop: relativeY,
+ rawLeft: relativeX,
+ wrapperWidth: pane.width,
+ wrapperHeight: pane.height,
+ setMenu: setEdgeMenu,
+ onClick: handleBackgroundClick
+ })
+ }
+ setNodeMenu(null)
+ setBackgroundMenu(null)
+ }, [selectedEdges, handleBackgroundClick])
const onBackgroundContextMenu = useCallback((event: MouseEvent) => {
if (!containerRef.current) return
@@ -107,6 +151,7 @@ const GraphMain = () => {
edges={filteredEdges}
onNodeClick={handleNodeClick}
onNodeRightClick={onNodeContextMenu}
+ onEdgeRightClick={onEdgeContextMenu}
onBackgroundRightClick={onBackgroundContextMenu}
onBackgroundClick={handleBackgroundClick}
showLabels={true}
@@ -121,6 +166,12 @@ const GraphMain = () => {
{...nodeMenu}
/>
)}
+ {edgeMenu && (
+ <EdgeContextMenu
+ onClick={handleBackgroundClick}
+ {...edgeMenu}
+ />
+ )}
{(background || (nodeMenu && selectedNodes.length > 0)) && (
<BackgroundContextMenu
onClick={handleBackgroundClick}
diff --git a/flowsint-app/src/components/graphs/graph-viewer.tsx b/flowsint-app/src/components/graphs/graph-viewer.tsx
index d5c9faac..74c3f182 100644
--- a/flowsint-app/src/components/graphs/graph-viewer.tsx
+++ b/flowsint-app/src/components/graphs/graph-viewer.tsx
@@ -3,6 +3,7 @@ import { useGraphSettingsStore } from '@/stores/graph-settings-store'
import { useGraphStore } from '@/stores/graph-store'
import { ItemType, useNodesDisplaySettings } from '@/stores/node-display-settings'
import React, { useCallback, useMemo, useEffect, useState, useRef } from 'react'
+import { useShallow } from 'zustand/react/shallow'
import ForceGraph2D from 'react-force-graph-2d'
import { Button } from '../ui/button'
import { useTheme } from '@/components/theme-provider'
@@ -22,6 +23,7 @@ interface GraphViewerProps {
edges: GraphEdge[]
onNodeClick?: (node: GraphNode, event: MouseEvent) => void
onNodeRightClick?: (node: GraphNode, event: MouseEvent) => void
+ onEdgeRightClick?: (edge: GraphEdge, event: MouseEvent) => void
onBackgroundClick?: () => void
onBackgroundRightClick: (event: MouseEvent) => void
showLabels?: boolean
@@ -120,6 +122,7 @@ const GraphViewer: React.FC<GraphViewerProps> = ({
edges,
onNodeClick,
onNodeRightClick,
+ onEdgeRightClick,
onBackgroundClick,
onBackgroundRightClick,
showLabels = true,
@@ -165,12 +168,42 @@ const GraphViewer: React.FC<GraphViewerProps> = ({
const nodeColors = useNodesDisplaySettings((s) => s.colors)
const setActions = useGraphControls((s) => s.setActions)
const setCurrentLayoutType = useGraphControls((s) => s.setCurrentLayoutType)
- const currentNode = useGraphStore((s) => s.currentNode)
- const selectedNodes = useGraphStore((s) => s.selectedNodes)
+
+ // Combine graph store selectors with useShallow for better performance
+ const { currentNode, currentEdge, selectedNodes, selectedEdges, toggleEdgeSelection, setCurrentEdge, clearSelectedEdges, setOpenMainDialog } = useGraphStore(
+ useShallow((s) => ({
+ currentNode: s.currentNode,
+ currentEdge: s.currentEdge,
+ selectedNodes: s.selectedNodes,
+ selectedEdges: s.selectedEdges,
+ toggleEdgeSelection: s.toggleEdgeSelection,
+ setCurrentEdge: s.setCurrentEdge,
+ clearSelectedEdges: s.clearSelectedEdges,
+ setOpenMainDialog: s.setOpenMainDialog
+ }))
+ )
+
const { theme } = useTheme()
- const setOpenMainDialog = useGraphStore((state) => state.setOpenMainDialog)
const setImportModalOpen = useGraphSettingsStore((s) => s.setImportModalOpen)
+ // Create Sets for O(1) lookups instead of O(n) array operations
+ const selectedNodeIds = useMemo(
+ () => new Set(selectedNodes.map(n => n.id)),
+ [selectedNodes]
+ )
+ const selectedEdgeIds = useMemo(
+ () => new Set(selectedEdges.map(e => e.id)),
+ [selectedEdges]
+ )
+ const currentNodeId = currentNode?.id
+ const currentEdgeId = currentEdge?.id
+
+ // Create edgeMap for O(1) edge lookups in handleEdgeClick
+ const edgeMap = useMemo(
+ () => new Map(edges.map(e => [e.id, e])),
+ [edges]
+ )
+
// Add state for tooltip
const [tooltip, setTooltip] = useState<{
x: number
@@ -196,18 +229,15 @@ const GraphViewer: React.FC<GraphViewerProps> = ({
[]
)
+ // O(1) lookups instead of O(n)
const isCurrent = useCallback(
- (nodeId: string) => {
- return currentNode?.id === nodeId
- },
- [currentNode]
+ (nodeId: string) => nodeId === currentNodeId,
+ [currentNodeId]
)
const isSelected = useCallback(
- (nodeId: string) => {
- return selectedNodes.some((node) => node.id === nodeId)
- },
- [selectedNodes]
+ (nodeId: string) => selectedNodeIds.has(nodeId),
+ [selectedNodeIds]
)
// Preload icons when nodes change
@@ -290,6 +320,7 @@ const GraphViewer: React.FC<GraphViewerProps> = ({
})
// Create a map for quick node lookup
const nodeMap = new Map(transformedNodes.map((node) => [node.id, node]))
+
// Group and transform edges
const edgeGroups = new Map<string, GraphEdge[]>()
edges.forEach((edge) => {
@@ -313,24 +344,37 @@ const GraphViewer: React.FC<GraphViewerProps> = ({
groupSize
}
})
- // Build node relationships (neighbors and links)
+
+ // Build node relationships (neighbors and links) with O(1) Set lookups
+ const neighborsMap = new Map<string, Set<any>>()
+ const linksMap = new Map<string, any[]>()
+
transformedEdges.forEach((link) => {
const sourceNode = nodeMap.get(link.source)
const targetNode = nodeMap.get(link.target)
if (sourceNode && targetNode) {
- // Add neighbors
- if (!sourceNode.neighbors.includes(targetNode)) {
- sourceNode.neighbors.push(targetNode)
- }
- if (!targetNode.neighbors.includes(sourceNode)) {
- targetNode.neighbors.push(sourceNode)
- }
+ // Initialize Sets if they don't exist
+ if (!neighborsMap.has(sourceNode.id)) neighborsMap.set(sourceNode.id, new Set())
+ if (!neighborsMap.has(targetNode.id)) neighborsMap.set(targetNode.id, new Set())
+ if (!linksMap.has(sourceNode.id)) linksMap.set(sourceNode.id, [])
+ if (!linksMap.has(targetNode.id)) linksMap.set(targetNode.id, [])
+
+ // Add neighbors using Set (O(1) instead of includes O(n))
+ neighborsMap.get(sourceNode.id)!.add(targetNode)
+ neighborsMap.get(targetNode.id)!.add(sourceNode)
+
// Add links
- sourceNode.links.push(link)
- targetNode.links.push(link)
+ linksMap.get(sourceNode.id)!.push(link)
+ linksMap.get(targetNode.id)!.push(link)
}
})
+ // Assign neighbors and links to nodes (convert Set to Array for ForceGraph)
+ transformedNodes.forEach((node) => {
+ node.neighbors = Array.from(neighborsMap.get(node.id) || [])
+ node.links = linksMap.get(node.id) || []
+ })
+
// Always use force layout - positions are preserved if they exist (fx/fy set above)
return {
nodes: transformedNodes,
@@ -474,6 +518,35 @@ const GraphViewer: React.FC<GraphViewerProps> = ({
[onNodeRightClick]
)
+ const handleEdgeRightClick = useCallback(
+ (edge: any, event: MouseEvent) => {
+ onEdgeRightClick?.(edge, event)
+ },
+ [onEdgeRightClick]
+ )
+
+ const handleEdgeClick = useCallback(
+ (edge: any, event: MouseEvent) => {
+ event.stopPropagation()
+ const isMultiSelect = event.ctrlKey || event.shiftKey
+
+ // O(1) lookup using edgeMap instead of O(n) find
+ const fullEdge = edgeMap.get(edge.id)
+
+ if (!fullEdge) return
+
+ if (isMultiSelect) {
+ // Multi-select: toggle edge in selection
+ toggleEdgeSelection(fullEdge, true)
+ } else {
+ // Single select: set as current edge and clear selections
+ setCurrentEdge(fullEdge)
+ clearSelectedEdges()
+ }
+ },
+ [toggleEdgeSelection, setCurrentEdge, clearSelectedEdges, edgeMap]
+ )
+
const handleBackgroundClick = useCallback(() => {
onBackgroundClick?.()
}, [onBackgroundClick])
@@ -751,13 +824,25 @@ const GraphViewer: React.FC<GraphViewerProps> = ({
if (typeof start !== 'object' || typeof end !== 'object') return
const linkKey = `${start.id}-${end.id}`
const isHighlighted = highlightLinks.has(linkKey)
+ const isSelected = selectedEdges.some((e) => e.id === link.id)
+ const isCurrent = currentEdge?.id === link.id
const hasAnyHighlight = highlightNodes.size > 0 || highlightLinks.size > 0
const linkWidth = forceSettings?.linkWidth?.value ?? 2
const nodeSize = forceSettings?.nodeSize?.value ?? 14
let strokeStyle: string
let lineWidth: number
let fillStyle: string
- if (isHighlighted) {
+ if (isCurrent) {
+ // Current edge: use blue/primary color with thicker line
+ strokeStyle = 'rgba(59, 130, 246, 0.95)'
+ fillStyle = 'rgba(59, 130, 246, 0.95)'
+ lineWidth = CONSTANTS.LINK_WIDTH * (linkWidth / 2.3)
+ } else if (isSelected) {
+ // Selected edges: use orange/highlight color with thicker line
+ strokeStyle = 'rgba(255, 115, 0, 0.9)'
+ fillStyle = 'rgba(255, 115, 0, 0.9)'
+ lineWidth = CONSTANTS.LINK_WIDTH * (linkWidth / 2.5)
+ } else if (isHighlighted) {
strokeStyle = GRAPH_COLORS.LINK_HIGHLIGHTED
fillStyle = GRAPH_COLORS.LINK_HIGHLIGHTED
lineWidth = CONSTANTS.LINK_WIDTH * (linkWidth / 3)
@@ -914,7 +999,7 @@ const GraphViewer: React.FC<GraphViewerProps> = ({
ctx.restore()
}
},
- [forceSettings, theme, highlightLinks, highlightNodes]
+ [forceSettings, theme, highlightLinks, highlightNodes, selectedEdges, currentEdge]
)
// Clear highlights when graph data changes
@@ -1042,6 +1127,8 @@ const GraphViewer: React.FC<GraphViewerProps> = ({
onNodeClick={handleNodeClick}
onBackgroundClick={handleBackgroundClick}
onBackgroundRightClick={handleBackgroundRightClick}
+ onLinkClick={handleEdgeClick}
+ onLinkRightClick={handleEdgeRightClick}
linkCurvature={(link) => link.curvature || 0}
nodeCanvasObject={renderNode}
onNodeDragEnd={handleNodeDragEnd}
diff --git a/flowsint-app/src/components/layout/root.layout.tsx b/flowsint-app/src/components/layout/root.layout.tsx
index 1b8e5906..2533e0cc 100644
--- a/flowsint-app/src/components/layout/root.layout.tsx
+++ b/flowsint-app/src/components/layout/root.layout.tsx
@@ -10,6 +10,7 @@ import NotesPanel from '../analyses/notes-panel'
import { useKeyboardShortcut } from '@/hooks/use-keyboard-shortcut'
import { useParams } from '@tanstack/react-router'
import DetailsPanel from '../graphs/details-panel/details-panel'
+import EdgeDetailsPanel from '../graphs/details-panel/edge-details-panel'
import { useGraphStore } from '@/stores/graph-store'
interface LayoutProps {
@@ -28,6 +29,7 @@ export default function RootLayout({ children }: LayoutProps) {
const openPanel = useLayoutStore((s) => s.openPanel)
const closeDetails = useLayoutStore((s) => s.closeDetails)
const currentNode = useGraphStore((s) => s.currentNode)
+ const currentEdge = useGraphStore((s) => s.currentEdge)
const { id, type } = useParams({ strict: false })
// Set up keyboard shortcut for chat panel
@@ -73,8 +75,11 @@ export default function RootLayout({ children }: LayoutProps) {
)
}
- // Priority 2: DetailsPanel when currentNode exists (auto-opens via useEffect)
- if (currentNode) {
+ // Priority 2: Show DetailsPanel and/or EdgeDetailsPanel when currentNode/currentEdge exist
+ const hasNode = !!currentNode
+ const hasEdge = !!currentEdge
+
+ if (hasNode || hasEdge) {
return (
<>
<ResizableHandle withHandle />
@@ -89,7 +94,24 @@ export default function RootLayout({ children }: LayoutProps) {
collapsible={true}
collapsedSize={2}
>
- <DetailsPanel node={currentNode} />
+ {hasNode && hasEdge ? (
+ // Both node and edge: show both in a vertical split
+ <ResizablePanelGroup direction="vertical" className="h-full">
+ <ResizablePanel defaultSize={50} minSize={30}>
+ <DetailsPanel node={currentNode} />
+ </ResizablePanel>
+ <ResizableHandle withHandle />
+ <ResizablePanel defaultSize={50} minSize={30}>
+ <EdgeDetailsPanel edge={currentEdge} />
+ </ResizablePanel>
+ </ResizablePanelGroup>
+ ) : hasNode ? (
+ // Only node
+ <DetailsPanel node={currentNode} />
+ ) : (
+ // Only edge
+ <EdgeDetailsPanel edge={currentEdge} />
+ )}
</ResizablePanel>
</>
)
@@ -97,7 +119,7 @@ export default function RootLayout({ children }: LayoutProps) {
// No panel should be shown
return null
- }, [id, currentNode?.id, currentNode?.data, isOpenAnalysis, closeDetails])
+ }, [id, currentNode?.id, currentNode?.data, currentEdge?.id, isOpenAnalysis, closeDetails])
// Memoize the entire layout content to prevent unnecessary re-renders
const layoutContent = useMemo(
diff --git a/flowsint-app/src/components/table/relationships-view.tsx b/flowsint-app/src/components/table/relationships-view.tsx
index f3226e82..597eb978 100644
--- a/flowsint-app/src/components/table/relationships-view.tsx
+++ b/flowsint-app/src/components/table/relationships-view.tsx
@@ -7,7 +7,7 @@ import { useRef, useState, useMemo, useCallback } from 'react'
import { Input } from '@/components/ui/input'
import { Badge } from '@/components/ui/badge'
import { Card, CardContent } from '@/components/ui/card'
-import { Search, ArrowRight, Users, Link, Filter } from 'lucide-react'
+import { Search, ArrowRight, Users, Link, Filter, Trash2 } from 'lucide-react'
import { Skeleton } from '@/components/ui/skeleton'
import { useIcon } from '@/hooks/use-icon'
import {
@@ -19,7 +19,11 @@ import {
} from '@/components/ui/select'
import { CopyButton } from '../copy'
import { RelationshipType } from '@/types'
-import { GraphNode } from '@/types'
+import { GraphNode, GraphEdge } from '@/types'
+import { Checkbox } from '@/components/ui/checkbox'
+import { Button } from '@/components/ui/button'
+import { useConfirm } from '@/components/use-confirm-dialog'
+import { toast } from 'sonner'
const ITEM_HEIGHT = 67 // Balanced spacing between items (55px card + 12px padding)
@@ -28,9 +32,11 @@ interface RelationshipItemProps {
relationship: RelationshipType
style: React.CSSProperties
onNodeClick: (node: GraphNode) => void
+ isSelected: boolean
+ onSelectionChange: (edge: GraphEdge, checked: boolean) => void
}
-function RelationshipItem({ relationship, style, onNodeClick }: RelationshipItemProps) {
+function RelationshipItem({ relationship, style, onNodeClick, isSelected, onSelectionChange }: RelationshipItemProps) {
const SourceIcon = useIcon(relationship.source.data?.type, relationship.source.data?.src)
const TargetIcon = useIcon(relationship.target.data?.type, relationship.target.data?.src)
@@ -41,10 +47,22 @@ function RelationshipItem({ relationship, style, onNodeClick }: RelationshipItem
onNodeClick(relationship.target)
}, [])
+ const handleCheckboxChange = useCallback(
+ (checked: boolean) => {
+ onSelectionChange(relationship.edge, checked)
+ },
+ [onSelectionChange, relationship.edge]
+ )
+
return (
<div style={style} className="px-3 pb-2">
<Card className="h-[55px] p-0">
<CardContent className="p-3 h-[55px] flex items-center gap-3 min-w-0">
+ {/* Checkbox */}
+ <div className="flex items-center flex-shrink-0">
+ <Checkbox checked={isSelected} onCheckedChange={handleCheckboxChange} />
+ </div>
+
{/* Source Node */}
<div className="flex items-center gap-2 flex-1 min-w-0 max-w-[35%]">
<div className="flex items-center justify-center w-8 h-8 rounded-full bg-muted flex-shrink-0">
@@ -111,6 +129,11 @@ export default function RelationshipsTable() {
const [selectedType, setSelectedType] = useState<string>('all')
const parentRef = useRef<HTMLDivElement>(null)
const setCurrentNode = useGraphStore((s) => s.setCurrentNode)
+ const selectedEdges = useGraphStore((s) => s.selectedEdges)
+ const setSelectedEdges = useGraphStore((s) => s.setSelectedEdges)
+ const removeEdges = useGraphStore((s) => s.removeEdges)
+ const clearSelectedEdges = useGraphStore((s) => s.clearSelectedEdges)
+ const { confirm } = useConfirm()
// const setOpenNodeEditorModal = useGraphStore(s => s.setOpenNodeEditorModal)
const onNodeClick = useCallback(
@@ -155,6 +178,76 @@ export default function RelationshipsTable() {
return Array.from(types).sort()
}, [relationships])
+ const handleSelectAll = useCallback(
+ (checked: boolean) => {
+ if (checked) {
+ setSelectedEdges(filteredRelationships.map((rel: RelationshipType) => rel.edge))
+ } else {
+ setSelectedEdges([])
+ }
+ },
+ [setSelectedEdges, filteredRelationships]
+ )
+
+ const handleEdgeSelectionChange = useCallback(
+ (edge: GraphEdge, checked: boolean) => {
+ const isSelected = selectedEdges.some((e) => e.id === edge.id)
+ if (checked && !isSelected) {
+ setSelectedEdges([...selectedEdges, edge])
+ } else if (!checked && isSelected) {
+ setSelectedEdges(selectedEdges.filter((e) => e.id !== edge.id))
+ }
+ },
+ [selectedEdges, setSelectedEdges]
+ )
+
+ const isEdgeSelected = useCallback(
+ (edgeId: string) => {
+ return selectedEdges.some((edge) => edge.id === edgeId)
+ },
+ [selectedEdges]
+ )
+
+ const isAllSelected = useMemo(() => {
+ return filteredRelationships.length > 0 && filteredRelationships.every((rel: RelationshipType) => isEdgeSelected(rel.edge.id))
+ }, [filteredRelationships, isEdgeSelected])
+
+ const isIndeterminate = useMemo(() => {
+ const selectedCount = filteredRelationships.filter((rel: RelationshipType) => isEdgeSelected(rel.edge.id)).length
+ return selectedCount > 0 && selectedCount < filteredRelationships.length
+ }, [filteredRelationships, isEdgeSelected])
+
+ const handleDeleteSelected = useCallback(async () => {
+ if (selectedEdges.length === 0 || !sketchId) return
+
+ const count = selectedEdges.length
+ if (
+ !(await confirm({
+ title: `You are about to delete ${count} relationship${count > 1 ? 's' : ''}?`,
+ message: 'The action is irreversible.'
+ }))
+ ) {
+ return
+ }
+
+ toast.promise(
+ (async () => {
+ const edgeIds = selectedEdges.map((e) => e.id)
+ removeEdges(edgeIds)
+ clearSelectedEdges()
+ return sketchService.deleteEdges(
+ sketchId as string,
+ JSON.stringify({ relationshipIds: edgeIds })
+ )
+ })(),
+ {
+ loading: `Deleting ${count} relationship${count > 1 ? 's' : ''}...`,
+ success: `Relationship${count > 1 ? 's' : ''} deleted successfully.`,
+ error: 'Failed to delete relationships.'
+ }
+ )
+ }, [selectedEdges, sketchId, confirm, removeEdges, clearSelectedEdges])
+
const virtualizer = useVirtualizer({
count: filteredRelationships.length,
getScrollElement: () => parentRef.current,
@@ -271,6 +364,39 @@ export default function RelationshipsTable() {
</Select>
</div>
+ {/* Selection Controls */}
+ {filteredRelationships.length > 0 && (
+ <div className="flex items-center gap-4 mb-2">
+ <div className="flex items-center gap-2">
+ <Checkbox
+ checked={isAllSelected}
+ ref={(el) => {
+ if (el && 'indeterminate' in el) {
+ (el as HTMLInputElement).indeterminate = isIndeterminate
+ }
+ }}
+ onCheckedChange={handleSelectAll}
+ />
+ <span className="text-sm text-muted-foreground">
+ {selectedEdges.length > 0
+ ? `${selectedEdges.length} selected`
+ : 'Select all'}
+ </span>
+ </div>
+ {selectedEdges.length > 0 && (
+ <Button
+ onClick={handleDeleteSelected}
+ variant="destructive"
+ size="sm"
+ className="h-8"
+ >
+ <Trash2 className="h-3.5 w-3.5 mr-1" />
+ Delete {selectedEdges.length}
+ </Button>
+ )}
+ </div>
+ )}
+
{/* Virtualized List */}
<div ref={parentRef} className="grow overflow-auto py-4 rounded-lg border">
<div
@@ -289,6 +415,8 @@ export default function RelationshipsTable() {
key={virtualRow.index}
relationship={relationship}
onNodeClick={onNodeClick}
+ isSelected={isEdgeSelected(relationship.edge.id)}
+ onSelectionChange={handleEdgeSelectionChange}
style={{
position: 'absolute',
top: 0,
diff --git a/flowsint-app/src/components/xyflow/context-menu.tsx b/flowsint-app/src/components/xyflow/context-menu.tsx
index 0501b78f..2b6e0e6f 100644
--- a/flowsint-app/src/components/xyflow/context-menu.tsx
+++ b/flowsint-app/src/components/xyflow/context-menu.tsx
@@ -1,4 +1,5 @@
import React from 'react'
+import { useKeyboard } from '@/hooks/use-keyboard'
interface ContextMenuProps {
top?: number
@@ -11,6 +12,8 @@ interface ContextMenuProps {
// Raw position for overflow calculation
rawTop?: number
rawLeft?: number
+ // Callback to close menu
+ setMenu?: (menu: any | null) => void
}
export default function ContextMenu({
@@ -22,9 +25,15 @@ export default function ContextMenu({
wrapperHeight,
rawTop,
rawLeft,
+ setMenu,
children,
...props
}: ContextMenuProps): JSX.Element {
+ // Close menu on ESC key
+ useKeyboard('Escape', () => {
+ setMenu?.(null)
+ })
+
// If raw position is provided, calculate overflow and adjust position
let finalTop = top
let finalLeft = left
diff --git a/flowsint-app/src/hooks/use-keyboard-shortcut.ts b/flowsint-app/src/hooks/use-keyboard-shortcut.ts
index cdc687bb..ba2bbb00 100644
--- a/flowsint-app/src/hooks/use-keyboard-shortcut.ts
+++ b/flowsint-app/src/hooks/use-keyboard-shortcut.ts
@@ -1,5 +1,5 @@
import { isMac } from '@/lib/utils'
-import { useEffect, useState } from 'react'
+import { useEffect } from 'react'
type ShortcutOptions = {
key: string
diff --git a/flowsint-app/src/stores/graph-store.ts b/flowsint-app/src/stores/graph-store.ts
index 4213779d..6846a463 100644
--- a/flowsint-app/src/stores/graph-store.ts
+++ b/flowsint-app/src/stores/graph-store.ts
@@ -31,11 +31,17 @@ interface GraphState {
// === Selection & Current ===
currentNode: GraphNode | null
+ currentEdge: GraphEdge | null
selectedNodes: GraphNode[]
+ selectedEdges: GraphEdge[]
setCurrentNode: (node: GraphNode | null) => void
+ setCurrentEdge: (edge: GraphEdge | null) => void
setSelectedNodes: (nodes: GraphNode[]) => void
+ setSelectedEdges: (edges: GraphEdge[]) => void
clearSelectedNodes: () => void
+ clearSelectedEdges: () => void
toggleNodeSelection: (node: GraphNode, multiSelect?: boolean) => void
+ toggleEdgeSelection: (edge: GraphEdge, multiSelect?: boolean) => void
// === Relation ===
relatedNodeToAdd: GraphNode | null
@@ -216,7 +222,9 @@ export const useGraphStore = create<GraphState>()(
// === Selection & Current ===
currentNode: null,
+ currentEdge: null,
selectedNodes: [],
+ selectedEdges: [],
setCurrentNode: (node) => {
const { currentNode } = get()
// Only update if the node is actually different
@@ -224,8 +232,17 @@ export const useGraphStore = create<GraphState>()(
set({ currentNode: node })
}
},
+ setCurrentEdge: (edge) => {
+ const { currentEdge } = get()
+ // Only update if the edge is actually different
+ if (currentEdge?.id !== edge?.id) {
+ set({ currentEdge: edge })
+ }
+ },
setSelectedNodes: (nodes) => set({ selectedNodes: nodes }),
+ setSelectedEdges: (edges) => set({ selectedEdges: edges }),
clearSelectedNodes: () => set({ selectedNodes: [], currentNode: null }),
+ clearSelectedEdges: () => set({ selectedEdges: [] }),
toggleNodeSelection: (node, multiSelect = false) => {
const { selectedNodes, currentNode } = get()
const isSelected = selectedNodes.some((n) => n.id === node.id)
@@ -257,6 +274,28 @@ export const useGraphStore = create<GraphState>()(
})
}
},
+ toggleEdgeSelection: (edge, multiSelect = false) => {
+ const { selectedEdges } = get()
+ const isSelected = selectedEdges.some((e) => e.id === edge.id)
+ let newSelected: GraphEdge[]
+
+ if (multiSelect) {
+ newSelected = isSelected
+ ? selectedEdges.filter((e) => e.id !== edge.id)
+ : [...selectedEdges, edge]
+ } else {
+ newSelected = isSelected && selectedEdges.length === 1 ? [] : [edge]
+ }
+
+ // Only update if there are actual changes
+ const hasSelectionChanges =
+ newSelected.length !== selectedEdges.length ||
+ newSelected.some((e, i) => e.id !== selectedEdges[i]?.id)
+
+ if (hasSelectionChanges) {
+ set({ selectedEdges: newSelected })
+ }
+ },
// === Relation ===
relatedNodeToAdd: null,
@@ -378,7 +417,9 @@ export const useGraphStore = create<GraphState>()(
reset: () => {
set({
currentNode: null,
+ currentEdge: null,
selectedNodes: [],
+ selectedEdges: [],
relatedNodeToAdd: null,
openMainDialog: false,
openFormDialog: false,
diff --git a/flowsint-app/src/types/table.ts b/flowsint-app/src/types/table.ts
index 8a11fb62..473eb95b 100644
--- a/flowsint-app/src/types/table.ts
+++ b/flowsint-app/src/types/table.ts
@@ -1,4 +1,4 @@
-import { GraphNode } from '@/stores/graph-store'
+import { GraphNode, GraphEdge } from "./graph"
export type Row = {
id: string
@@ -10,5 +10,5 @@ export type Row = {
export type RelationshipType = {
source: GraphNode
target: GraphNode
- edge: { label: string }
+ edge: GraphEdge
}
diff --git a/flowsint-core/src/flowsint_core/core/graph_repository.py b/flowsint-core/src/flowsint_core/core/graph_repository.py
index 95cf1565..8377e223 100644
--- a/flowsint-core/src/flowsint_core/core/graph_repository.py
+++ b/flowsint-core/src/flowsint_core/core/graph_repository.py
@@ -376,6 +376,38 @@ class GraphRepository:
)
return result[0]["deleted_count"] if result else 0
+ def delete_relationships(
+ self,
+ relationship_ids: List[str],
+ sketch_id: str
+ ) -> int:
+ """
+ Delete relationships by their element IDs.
+
+ Args:
+ relationship_ids: List of Neo4j element IDs
+ sketch_id: Investigation sketch ID (for safety)
+
+ Returns:
+ Number of relationships deleted
+ """
+ if not self._connection or not relationship_ids:
+ return 0
+
+ query = """
+ UNWIND $relationship_ids AS rel_id
+ MATCH ()-[r]->()
+ WHERE elementId(r) = rel_id AND r.sketch_id = $sketch_id
+ DELETE r
+ RETURN count(r) as deleted_count
+ """
+
+ result = self._connection.query(
+ query,
+ {"relationship_ids": relationship_ids, "sketch_id": sketch_id}
+ )
+ return result[0]["deleted_count"] if result else 0
+
def delete_all_sketch_nodes(self, sketch_id: str) -> int:
"""
Delete all nodes and relationships for a sketch.