A modern platform for visual, flexible, and extensible graph-based investigations. For cybersecurity analysts and investigators.
feat(app): update edge label
dextmorgn9251ea3dda63
diff --git a/flowsint-app/src/api/sketch-service.ts b/flowsint-app/src/api/sketch-service.tsindex 6cdc943e..7ab2ffe1 100644--- a/flowsint-app/src/api/sketch-service.ts+++ b/flowsint-app/src/api/sketch-service.ts@@ -63,6 +63,12 @@ export const sketchService = {body: body})},+ updateEdge: async (sketchId: string, body: BodyInit): Promise<any> => {+ return fetchWithAuth(`/api/sketches/${sketchId}/relationships/edit`, {+ method: 'PUT',+ body: body+ })+ },getNodeNeighbors: async (sketchId: string, nodeId: string): Promise<any> => {return fetchWithAuth(`/api/sketches/${sketchId}/nodes/${nodeId}`, {method: 'GET'diff --git a/flowsint-app/src/components/sketches/details-panel/edge-details-panel.tsx b/flowsint-app/src/components/sketches/details-panel/edge-details-panel.tsxindex ee1f2029..6fa7169d 100644--- a/flowsint-app/src/components/sketches/details-panel/edge-details-panel.tsx+++ b/flowsint-app/src/components/sketches/details-panel/edge-details-panel.tsx@@ -1,4 +1,4 @@-import { memo, useCallback } from 'react'+import { memo, useCallback, useRef, ChangeEvent } from 'react'import { Button } from '@/components/ui/button'import { Trash2, ArrowRight, MousePointer, Link2 } from 'lucide-react'import { useGraphStore } from '@/stores/graph-store'@@ -12,6 +12,7 @@ import { GraphEdge } from '@/types'import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'import { cn } from '@/lib/utils'import { Badge } from '@/components/ui/badge'+import { Input } from '@/components/ui/input'const EdgeDetailsPanel = memo(({ edge }: { edge: GraphEdge | null }) => {const { id: sketchId } = useParams({ strict: false })@@ -20,7 +21,9 @@ const EdgeDetailsPanel = memo(({ edge }: { edge: GraphEdge | null }) => {const setCurrentNode = useGraphStore((s) => s.setCurrentNode)const setCurrentEdge = useGraphStore((s) => s.setCurrentEdge)const removeEdges = useGraphStore((s) => s.removeEdges)+ const updateEdge = useGraphStore((s) => s.updateEdge)const { confirm } = useConfirm()+ const labelRef = useRef<HTMLInputElement>(null)// Get fresh edge data from storeedge = edges.find((e) => e.id === edge?.id) || null@@ -29,8 +32,46 @@ const EdgeDetailsPanel = memo(({ edge }: { edge: GraphEdge | null }) => {const sourceNode = edge ? nodes.find((n) => n.id === edge.source) : nullconst 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 SourceIcon = useIcon(sourceNode?.data?.type ?? 'default', sourceNode?.data?.src)+ const TargetIcon = useIcon(targetNode?.data?.type ?? 'default', targetNode?.data?.src)++ const handleInputChange = useCallback((e: ChangeEvent<HTMLInputElement>) => {+ e.stopPropagation()+ }, [])++ const handleBlur = useCallback(async () => {+ if (!edge || !labelRef.current?.value || !sketchId) return+ const newLabel = labelRef.current.value.trim()+ if (newLabel !== edge.label) {+ const previousLabel = edge.label++ // Optimistic update+ updateEdge(edge.id, { label: newLabel })++ // Call API+ try {+ await sketchService.updateEdge(+ sketchId,+ JSON.stringify({+ relationshipId: edge.id,+ data: { label: newLabel }+ })+ )+ toast.success('Relationship updated successfully.')+ } catch (error) {+ // Rollback on error+ updateEdge(edge.id, { label: previousLabel })+ toast.error('Failed to update relationship.')+ }+ }+ }, [edge, updateEdge, sketchId])++ const handleKeyDown = useCallback((e: React.KeyboardEvent<HTMLInputElement>) => {+ if (e.key === 'Enter') {+ e.preventDefault()+ labelRef.current?.blur()+ }+ }, [])const handleDelete = useCallback(async () => {if (!edge || !sketchId) return@@ -78,7 +119,7 @@ const EdgeDetailsPanel = memo(({ edge }: { edge: GraphEdge | null }) => {if (!edge) {return (- <div className="flex p-12 flex-col items-center justify-center h-full text-center p-8">+ <div className="flex flex-col items-center justify-center h-full text-center p-8"><div className="w-12 h-12 bg-muted rounded-full flex items-center justify-center mb-4"><MousePointer className="h-4 w-4 text-muted-foreground" /></div>@@ -94,8 +135,16 @@ const EdgeDetailsPanel = memo(({ edge }: { edge: GraphEdge | null }) => {<div className="flex flex-col h-full overflow-x-hidden overflow-y-auto bg-card">{/* Header */}<div className="flex items-center bg-card h-10 sticky w-full top-0 border-b justify-start px-3 gap-2 z-1">- <Link2 className="h-3 w-3 text-muted-foreground flex-shrink-0" />- <p className="text-sm font-semibold truncate">{edge.label || 'Relationship'}</p>+ <Link2 className="h-3 w-3 text-muted-foreground shrink-0" />+ <Input+ ref={labelRef}+ className="h-7 text-sm font-semibold border-0 px-1 focus-visible:ring-1"+ defaultValue={edge.label || 'Relationship'}+ onChange={handleInputChange}+ onFocus={(e) => e.stopPropagation()}+ onBlur={handleBlur}+ onKeyDown={handleKeyDown}+ /><div className="grow" /><div className="flex items-center"><TooltipProvider>@@ -235,7 +284,9 @@ const EdgeDetailsPanel = memo(({ edge }: { edge: GraphEdge | null }) => {style={{ width: `${Number(edge.confidence_level)}%` }}/></div>- <span className="font-semibold text-[10px] shrink-0">{edge.confidence_level}%</span>+ <span className="font-semibold text-[10px] shrink-0">+ {edge.confidence_level}%+ </span></div></div></div>diff --git a/flowsint-app/src/components/sketches/edge-context-menu.tsx b/flowsint-app/src/components/sketches/edge-context-menu.tsxindex 4c49af39..d8c376c8 100644--- a/flowsint-app/src/components/sketches/edge-context-menu.tsx+++ b/flowsint-app/src/components/sketches/edge-context-menu.tsx@@ -1,14 +1,15 @@-import React, { useCallback } from 'react'+import React, { ChangeEvent, useCallback, useRef } 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 { CopyButton } from '@/components/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'+import { Input } from '@/components/ui/input'interface EdgeContextMenuProps {edge?: GraphEdge@@ -39,7 +40,9 @@ export default function EdgeContextMenu({}: EdgeContextMenuProps) {const { id: sketchId } = useParams({ strict: false })const removeEdges = useGraphStore((s) => s.removeEdges)+ const updateEdge = useGraphStore((s) => s.updateEdge)const clearSelectedEdges = useGraphStore((s) => s.clearSelectedEdges)+ const labelRef = useRef<HTMLInputElement>(null)const { confirm } = useConfirm()// Determine if multi-select or single@@ -47,44 +50,74 @@ export default function EdgeContextMenu({const edgesToDelete = isMultiSelect ? edges : edge ? [edge] : []const edgeIds = edgesToDelete.map((e) => e.id)- const handleDelete = useCallback(async (e: React.MouseEvent) => {+ const handleInputChange = useCallback((e: ChangeEvent<HTMLInputElement>) => {e.stopPropagation()+ }, [])- if (edgeIds.length === 0 || !sketchId) return+ const handleBlur = useCallback(async () => {+ if (!edge || !labelRef.current?.value || !sketchId) return+ const newLabel = labelRef.current.value.trim()+ if (newLabel !== edge.label) {+ const previousLabel = edge.label- // 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 update+ updateEdge(edge.id, { label: newLabel })+ setMenu(null)- // Optimistic delete + API call with toast- toast.promise(- (async () => {- // Optimistic update- removeEdges(edgeIds)- if (isMultiSelect) clearSelectedEdges()- // API call- return sketchService.deleteEdges(+ // Call API+ try {+ await sketchService.updateEdge(sketchId,- JSON.stringify({ relationshipIds: edgeIds })+ JSON.stringify({+ relationshipId: edge.id,+ data: { label: newLabel }+ }))- })(),- {- loading: `Deleting ${count} relationship${count > 1 ? 's' : ''}...`,- success: `Relationship${count > 1 ? 's' : ''} deleted successfully.`,- error: 'Failed to delete relationship.'+ toast.success('Relationship updated successfully.')+ } catch (error) {+ // Rollback on error+ updateEdge(edge.id, { label: previousLabel })+ toast.error('Failed to update relationship.')+ }+ }+ }, [edge, updateEdge, sketchId, setMenu])++ const handleKeyDown = useCallback((e: React.KeyboardEvent<HTMLInputElement>) => {+ if (e.key === 'Enter') {+ e.preventDefault()+ labelRef.current?.blur()+ }+ }, [])++ const handleDelete = useCallback(+ async (e: React.MouseEvent) => {+ e.stopPropagation()+ if (edgeIds.length === 0 || !sketchId) return+ const count = edgeIds.length+ if (+ !(await confirm({+ title: `You are about to delete ${count} relationship${count > 1 ? 's' : ''}?`,+ message: 'The action is irreversible.'+ }))+ ) {+ return}- )- }, [edgeIds, sketchId, setMenu, removeEdges, clearSelectedEdges, isMultiSelect, confirm])+ setMenu(null)+ toast.promise(+ (async () => {+ removeEdges(edgeIds)+ if (isMultiSelect) clearSelectedEdges()+ 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@@ -97,30 +130,33 @@ export default function EdgeContextMenu({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="px-3 py-1 flex items-center justify-between 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 className="p-1">+ <Input+ ref={labelRef}+ className="h-7"+ defaultValue={edge?.label ?? '??'}+ onChange={handleInputChange}+ onFocus={(e) => e.stopPropagation()}+ onBlur={handleBlur}+ onKeyDown={handleKeyDown}+ autoFocus+ />+ </div>)}</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 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></div></BaseContextMenu>)diff --git a/flowsint-app/src/components/sketches/graph/constants.ts b/flowsint-app/src/components/sketches/graph/constants.tsindex 8247ee8f..ef86efc1 100644--- a/flowsint-app/src/components/sketches/graph/constants.ts+++ b/flowsint-app/src/components/sketches/graph/constants.ts@@ -32,7 +32,7 @@ export const CONSTANTS = {MIN_FONT_SIZE: 0.5,LINK_WIDTH: 1,MIN_ZOOM: 0.1,- MAX_ZOOM: 8,+ MAX_ZOOM: 12,ZOOM_NODE_DETAIL_THRESHOLD: 2,ZOOM_EDGE_DETAIL_THRESHOLD: 1,ZOOMED_OUT_SIZE_MULTIPLIER: 3diff --git a/flowsint-app/src/stores/graph-store.ts b/flowsint-app/src/stores/graph-store.tsindex 128577f9..6a769bce 100644--- a/flowsint-app/src/stores/graph-store.ts+++ b/flowsint-app/src/stores/graph-store.ts@@ -181,7 +181,7 @@ export const useGraphStore = create<GraphState>()(updateEdge: (edgeId, updates) => {const { edges, nodes, filters } = get()const updatedEdges = edges.map((edge) =>- edge.id === edgeId ? { ...edge, data: { ...edge, ...updates } as GraphEdge } : edge+ edge.id === edgeId ? ({ ...edge, ...updates } as GraphEdge) : edge)const filteredNodes = computeFilteredNodes(nodes, filters)const filteredEdges = computeFilteredEdges(updatedEdges, filteredNodes)@@ -207,10 +207,17 @@ export const useGraphStore = create<GraphState>()(const filteredNodes = computeFilteredNodes(updatedNodes, filters)const filteredEdges = computeFilteredEdges(updatedEdges, filteredNodes)// Update currentNode if it matches the old ID- const updatedCurrentNode = currentNode?.id === oldId- ? { ...currentNode, id: newData.id, data: newData }- : currentNode- set({ nodes: updatedNodes, edges: updatedEdges, filteredNodes, filteredEdges, currentNode: updatedCurrentNode })+ const updatedCurrentNode =+ currentNode?.id === oldId+ ? { ...currentNode, id: newData.id, data: newData }+ : currentNode+ set({+ nodes: updatedNodes,+ edges: updatedEdges,+ filteredNodes,+ filteredEdges,+ currentNode: updatedCurrentNode+ })},// === Selection & Current ===@@ -333,7 +340,7 @@ export const useGraphStore = create<GraphState>()(// === Filters ===filters: {types: [],- rules: [],+ rules: []},setFilters: (filters) => {const { nodes, edges } = get()