Skip to content

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

feat(app): dedicated event for refresh

dextmorgne3fe1142d590
diff --git a/flowsint-app/src/components/graphs/add-item-dialog.tsx b/flowsint-app/src/components/graphs/add-item-dialog.tsx
index 9c53bf59..23964075 100644
--- a/flowsint-app/src/components/graphs/add-item-dialog.tsx
+++ b/flowsint-app/src/components/graphs/add-item-dialog.tsx
@@ -37,6 +37,7 @@ export default function AddItemDialog() {
const setImportModalOpen = useGraphSettingsStore((s) => s.setImportModalOpen)
const regenerateLayout = useGraphControls((s) => s.regenerateLayout)
const currentLayoutType = useGraphControls((s) => s.currentLayoutType)
+ const getViewportCenter = useGraphControls((s) => s.getViewportCenter)
const { id: sketch_id } = useParams({ strict: false })
const { actionItems, isLoading } = useActionItems()
@@ -77,26 +78,37 @@ export default function AddItemDialog() {
const type = currentNodeType.type
const label = data[label_key as keyof typeof data]
+ // Get viewport center for positioning new node
+ const center = getViewportCenter()
+ const nodeX = center?.x ?? 0
+ const nodeY = center?.y ?? 0
+
+ // Node data for API (with correct structure)
const newNode = {
- type: 'custom',
+ type: type.toLowerCase(), // Required at root level for API validation
label: label,
data: {
...flattenObj(data),
label,
- type: type.toLowerCase()
+ type: type.toLowerCase(),
+ x: nodeX, // Position at viewport center
+ y: nodeY
}
}
// Generate temporary ID for optimistic update
const tempId = generateTempId()
- // Optimistically add the node to local state with temporary ID
+ // Optimistically add the node to local state with temporary ID and position fields
const nodeWithTempId: GraphNode = {
id: tempId,
data: {
...newNode.data,
id: tempId,
created_at: new Date().toISOString()
- }
+ },
+ // Position fields for client-side graph rendering (at viewport center)
+ x: nodeX,
+ y: nodeY,
}
if (addNode) {
addNode(nodeWithTempId)
@@ -155,13 +167,13 @@ export default function AddItemDialog() {
console.error(error)
toast.error('Failed to sync node with server. Please refresh.')
}
- finally {
- setTimeout(() => {
- if (currentLayoutType && regenerateLayout) {
- regenerateLayout(currentLayoutType)
- }
- }, 500)
- }
+ // finally {
+ // setTimeout(() => {
+ // if (currentLayoutType && regenerateLayout) {
+ // regenerateLayout(currentLayoutType)
+ // }
+ // }, 500)
+ // }
}
const navigateToSubItems = (item: ActionItem) => {
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
index 55a9796c..ee1f2029 100644
--- a/flowsint-app/src/components/graphs/details-panel/edge-details-panel.tsx
+++ b/flowsint-app/src/components/graphs/details-panel/edge-details-panel.tsx
@@ -78,11 +78,11 @@ const EdgeDetailsPanel = memo(({ edge }: { edge: GraphEdge | null }) => {
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 className="flex p-12 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>
- <h3 className="text-lg font-semibold text-foreground mb-2">No Relationship Selected</h3>
+ <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>
diff --git a/flowsint-app/src/components/graphs/details-panel/relationships.tsx b/flowsint-app/src/components/graphs/details-panel/relationships.tsx
index f6e9cec3..31d3e1ce 100644
--- a/flowsint-app/src/components/graphs/details-panel/relationships.tsx
+++ b/flowsint-app/src/components/graphs/details-panel/relationships.tsx
@@ -76,12 +76,14 @@ const VirtualizedList = memo(({ relationships }: { relationships: Relation[] })
firstItem: virtualItems[0],
parentRefCurrent: parentRef.current
})
+ const totalSize
+ = virtualizer.getTotalSize()
return (
<div ref={parentRef} className="h-full py-1.5 overflow-auto">
<div
style={{
- height: `${virtualizer.getTotalSize()}px`,
+ height: `${totalSize}px`,
width: '100%',
position: 'relative',
paddingTop: '0.75rem',
@@ -105,27 +107,27 @@ const VirtualizedList = memo(({ relationships }: { relationships: Relation[] })
className="pb-1 px-3"
>
<Badge variant={'outline'} className="h-8 px-2 py-1 w-full block">
- <div className="flex items-center gap-1 w-full min-w-0 h-full">
- <div className="min-w-0 flex-1 flex items-center">
- <RelationshipItem node={rel.source} />
- </div>
- <ArrowRight className="flex-shrink-0 opacity-60 h-4 w-4" />
- <div className="min-w-0 flex-1 flex items-center justify-center">
- <span className="opacity-60 text-xs truncate block">{rel.edge.label}</span>
- </div>
- <ArrowRight className="flex-shrink-0 opacity-60 h-4 w-4" />
- <div className="min-w-0 flex-1 flex items-center justify-end">
- <RelationshipItem node={rel.target} />
- </div>
+ <div className="flex items-center gap-1 w-full min-w-0 h-full">
+ <div className="min-w-0 flex-1 flex items-center">
+ <RelationshipItem node={rel.source} />
</div>
- </Badge>
- </div>
- )
- })}
- </div>
+ <ArrowRight className="flex-shrink-0 opacity-60 h-4 w-4" />
+ <div className="min-w-0 flex-1 flex items-center justify-center">
+ <span className="opacity-60 text-xs truncate block">{rel.edge.label}</span>
+ </div>
+ <ArrowRight className="flex-shrink-0 opacity-60 h-4 w-4" />
+ <div className="min-w-0 flex-1 flex items-center justify-end">
+ <RelationshipItem node={rel.target} />
+ </div>
+ </div>
+ </Badge>
+ </div>
+ )
+ })}
</div>
- )
- }
+ </div>
+ )
+}
)
export default Relationships
diff --git a/flowsint-app/src/components/graphs/graph-viewer.tsx b/flowsint-app/src/components/graphs/graph-viewer.tsx
index c1ecbe99..d2f16212 100644
--- a/flowsint-app/src/components/graphs/graph-viewer.tsx
+++ b/flowsint-app/src/components/graphs/graph-viewer.tsx
@@ -463,7 +463,22 @@ const GraphViewer: React.FC<GraphViewerProps> = ({
graphRef.current.zoomToFit(400)
}
},
- regenerateLayout: regenerateLayout
+ regenerateLayout: regenerateLayout,
+ getViewportCenter: () => {
+ if (!graphRef.current || !containerRef.current) return null
+
+ // Get screen center coordinates
+ const rect = containerRef.current.getBoundingClientRect()
+ const screenCenterX = rect.width / 2
+ const screenCenterY = rect.height / 2
+
+ // Convert screen coordinates to graph coordinates
+ if (typeof graphRef.current.screen2GraphCoords === 'function') {
+ return graphRef.current.screen2GraphCoords(screenCenterX, screenCenterY)
+ }
+
+ return { x: 0, y: 0 }
+ }
})
}
// Call external ref callback
@@ -483,7 +498,8 @@ const GraphViewer: React.FC<GraphViewerProps> = ({
zoomIn: () => { },
zoomOut: () => { },
zoomToFit: () => { },
- regenerateLayout: () => { }
+ regenerateLayout: () => { },
+ getViewportCenter: () => null
})
isGraphReadyRef.current = false
}
@@ -494,24 +510,24 @@ const GraphViewer: React.FC<GraphViewerProps> = ({
useEffect(() => {
// Only auto-center if we have nodes and the graph is ready
if (graphRef.current && graphData.nodes.length > 0 && containerSize.width > 0) {
- // Wait a bit for the simulation to settle, then center
+ // If flag is set, regenerate layout instead of just zooming
+ if (shouldRegenerateLayoutOnNextRefetch && currentLayoutType) {
+ setShouldRegenerateLayoutOnNextRefetch(false)
+ const timer = setTimeout(() => {
+ regenerateLayout(currentLayoutType)
+ }, 500)
+ return () => clearTimeout(timer)
+ }
+
+ // Otherwise just zoom to fit on initial load
const timer = setTimeout(() => {
if (graphRef.current && typeof graphRef.current.zoomToFit === 'function') {
-
graphRef.current.zoomToFit(400)
}
}, 500)
return () => clearTimeout(timer)
}
- }, [graphData.nodes.length, containerSize.width])
-
- // Auto-regenerate layout when new nodes are added via refetch (from useEvents)
- useEffect(() => {
- if (shouldRegenerateLayoutOnNextRefetch && nodes.length > 0 && currentLayoutType) {
- setShouldRegenerateLayoutOnNextRefetch(false)
- regenerateLayout(currentLayoutType)
- }
- }, [nodes, shouldRegenerateLayoutOnNextRefetch, currentLayoutType, regenerateLayout, setShouldRegenerateLayoutOnNextRefetch])
+ }, [graphData.nodes.length, containerSize.width, shouldRegenerateLayoutOnNextRefetch, currentLayoutType, regenerateLayout, setShouldRegenerateLayoutOnNextRefetch])
// Event handlers with proper memoization
const handleNodeClick = useCallback(
diff --git a/flowsint-app/src/components/terminal/terminal-log-viewer.tsx b/flowsint-app/src/components/terminal/terminal-log-viewer.tsx
index 62307729..9adea839 100644
--- a/flowsint-app/src/components/terminal/terminal-log-viewer.tsx
+++ b/flowsint-app/src/components/terminal/terminal-log-viewer.tsx
@@ -70,13 +70,6 @@ export const TerminalLogViewer = ({
const previousLogs = previousLogsRef.current
const currentLogs = logs
-
- console.log('[TerminalLogViewer] Log update', {
- previousCount: previousLogs.length,
- currentCount: currentLogs.length,
- latestLogs: currentLogs.slice(-3)
- })
-
// Find new logs by comparing timestamps and messages
// This works even when the total length stays the same (e.g., 100 logs with slice)
const newLogs = currentLogs.filter((currentLog) => {
diff --git a/flowsint-app/src/components/xyflow/context-menu.tsx b/flowsint-app/src/components/xyflow/context-menu.tsx
index 2b6e0e6f..370a2427 100644
--- a/flowsint-app/src/components/xyflow/context-menu.tsx
+++ b/flowsint-app/src/components/xyflow/context-menu.tsx
@@ -1,4 +1,4 @@
-import React from 'react'
+import React, { JSX, useEffect, useRef } from 'react'
import { useKeyboard } from '@/hooks/use-keyboard'
interface ContextMenuProps {
@@ -29,11 +29,36 @@ export default function ContextMenu({
children,
...props
}: ContextMenuProps): JSX.Element {
+ const menuRef = useRef<HTMLDivElement>(null)
+
// Close menu on ESC key
useKeyboard('Escape', () => {
setMenu?.(null)
})
+ // Close menu on click outside or blur
+ useEffect(() => {
+ const handleClickOutside = (event: MouseEvent) => {
+ if (menuRef.current && !menuRef.current.contains(event.target as Node)) {
+ setMenu?.(null)
+ }
+ }
+
+ const handleBlur = () => {
+ setMenu?.(null)
+ }
+
+ // Add listeners
+ document.addEventListener('mousedown', handleClickOutside)
+ window.addEventListener('blur', handleBlur)
+
+ return () => {
+ // Cleanup
+ document.removeEventListener('mousedown', handleClickOutside)
+ window.removeEventListener('blur', handleBlur)
+ }
+ }, [setMenu])
+
// If raw position is provided, calculate overflow and adjust position
let finalTop = top
let finalLeft = left
@@ -115,6 +140,7 @@ export default function ContextMenu({
return (
<div
+ ref={menuRef}
style={dynamicStyles}
className="bg-background/90 backdrop-blur-sm border border-border flex flex-col rounded-lg shadow-lg absolute z-50"
onClick={handleMenuClick}
diff --git a/flowsint-app/src/hooks/use-events.ts b/flowsint-app/src/hooks/use-events.ts
index a471765e..533aa5b0 100644
--- a/flowsint-app/src/hooks/use-events.ts
+++ b/flowsint-app/src/hooks/use-events.ts
@@ -34,11 +34,28 @@ export function useEvents(sketch_id: string | undefined) {
eventSource.onmessage = (e) => {
try {
- const raw = JSON.parse(e.data) as any
+ // Handle malformed SSE data (connection message has extra "data: " prefix)
+ let dataStr = e.data
+ if (dataStr.startsWith('data: ')) {
+ dataStr = dataStr.substring(6) // Remove "data: " prefix
+ }
+
+ const raw = JSON.parse(dataStr) as any
+
+ // Ignore connection messages
+ if (raw.event === 'connected') {
+ return
+ }
+
+ // Only process log events
+ if (raw.event !== 'log') {
+ return
+ }
+
const event = JSON.parse(raw.data) as Event
setLiveLogs((prev) => [...prev.slice(-99), event])
} catch (error) {
- console.error('[useSketchEvents] Failed to parse SSE event:', error)
+ console.error('[useSketchEvents] Failed to parse SSE event:', error, e.data)
}
}
diff --git a/flowsint-app/src/hooks/use-graph-refresh.ts b/flowsint-app/src/hooks/use-graph-refresh.ts
index 37ebfe5e..53a2bf90 100644
--- a/flowsint-app/src/hooks/use-graph-refresh.ts
+++ b/flowsint-app/src/hooks/use-graph-refresh.ts
@@ -1,72 +1,85 @@
-import { useEffect } from 'react'
+import { useEffect, useRef } from 'react'
import { useGraphControls } from '@/stores/graph-controls-store'
import { EventLevel } from '@/types'
const API_URL = import.meta.env.VITE_API_URL
-/**
- * Dedicated hook for graph refresh on transform completion.
- *
- * This hook listens ONLY to COMPLETED events via SSE and triggers
- * a graph refetch followed by layout regeneration. It's completely
- * separate from the logging system (use-events.ts).
- *
- * Architecture:
- * - Transform completes → Logger.completed() → SSE event
- * - This hook receives COMPLETED event
- * - Calls refetchGraph() with callback
- * - Callback triggers regenerateLayout() with fresh data
- */
export function useGraphRefresh(sketch_id: string | undefined) {
const refetchGraph = useGraphControls((s) => s.refetchGraph)
- const regenerateLayout = useGraphControls((s) => s.regenerateLayout)
+ const setShouldRegenerateLayoutOnNextRefetch = useGraphControls((s) => s.setShouldRegenerateLayoutOnNextRefetch)
const currentLayoutType = useGraphControls((s) => s.currentLayoutType)
+ // Use refs to avoid reconnecting SSE when functions change
+ const refetchGraphRef = useRef(refetchGraph)
+ const setShouldRegenerateRef = useRef(setShouldRegenerateLayoutOnNextRefetch)
+ const currentLayoutTypeRef = useRef(currentLayoutType)
+
+ // Keep refs updated
+ useEffect(() => {
+ refetchGraphRef.current = refetchGraph
+ setShouldRegenerateRef.current = setShouldRegenerateLayoutOnNextRefetch
+ currentLayoutTypeRef.current = currentLayoutType
+ }, [refetchGraph, setShouldRegenerateLayoutOnNextRefetch, currentLayoutType])
+
useEffect(() => {
if (!sketch_id) return
- console.log('[useGraphRefresh] Connecting to SSE for sketch:', sketch_id)
const eventSource = new EventSource(
- `${API_URL}/api/events/sketch/${sketch_id}/stream`
+ `${API_URL}/api/events/sketch/${sketch_id}/status/stream`
)
- eventSource.onopen = () => {
- console.log('[useGraphRefresh] SSE connection opened')
- }
-
eventSource.onmessage = (e) => {
try {
- const raw = JSON.parse(e.data) as any
+ // Handle malformed SSE data (connection message has extra "data: " prefix)
+ let dataStr = e.data
+ if (dataStr.startsWith('data: ')) {
+ dataStr = dataStr.substring(6) // Remove "data: " prefix
+ }
+
+ const raw = JSON.parse(dataStr) as any
+
+ // Ignore connection messages
+ if (raw.event === 'connected') {
+ return
+ }
+
+ // Only process status events
+ if (raw.event !== 'status') {
+ return
+ }
+
const event = JSON.parse(raw.data) as any
- console.log('[useGraphRefresh] Received event:', event.type, event)
// Only handle COMPLETED events
if (event.type === EventLevel.COMPLETED) {
- console.log('[useGraphRefresh] COMPLETED event detected, triggering refetch')
- console.log('[useGraphRefresh] refetchGraph function:', refetchGraph)
- console.log('[useGraphRefresh] currentLayoutType:', currentLayoutType)
-
- // Refetch graph data, then regenerate layout with fresh data
- refetchGraph(() => {
- console.log('[useGraphRefresh] Refetch callback executing, regenerating layout')
- if (currentLayoutType) {
- regenerateLayout(currentLayoutType)
- }
- })
+ const refetch = refetchGraphRef.current
+ const setShouldRegenerate = setShouldRegenerateRef.current
+ const layoutType = currentLayoutTypeRef.current
+
+ if (typeof refetch !== 'function') {
+ return
+ }
+
+ // Set flag to regenerate layout when new data arrives
+ if (layoutType && typeof setShouldRegenerate === 'function') {
+ setShouldRegenerate(true)
+ }
+
+ // Refetch graph data - the regeneration will happen automatically
+ // via the useEffect in graph-viewer.tsx when nodes change
+ refetch()
}
} catch (error) {
- console.error('[useGraphRefresh] Failed to parse SSE event:', error)
+ console.error('[useGraphRefresh] Failed to parse SSE event:', error, e.data)
}
}
- eventSource.onerror = (error) => {
- console.error('[useGraphRefresh] EventSource error:', error)
+ eventSource.onerror = () => {
eventSource.close()
}
return () => {
- console.log('[useGraphRefresh] Disconnecting SSE')
eventSource.close()
}
- }, [sketch_id, refetchGraph, regenerateLayout, currentLayoutType])
+ }, [sketch_id]) // Only reconnect when sketch_id changes
}
diff --git a/flowsint-app/src/hooks/use-launch-enricher.ts b/flowsint-app/src/hooks/use-launch-enricher.ts
index c8f9aad8..2ea039b4 100644
--- a/flowsint-app/src/hooks/use-launch-enricher.ts
+++ b/flowsint-app/src/hooks/use-launch-enricher.ts
@@ -28,7 +28,7 @@ export function useLaunchEnricher(askUser: boolean = false) {
`Enricher ${enricherName} has been launched on ${count} node${count > 1 ? 's' : ''}.`,
error: () => `An error occurred launching enricher.`
})
- openClonsole()
+ // openClonsole()
return
}
return {
diff --git a/flowsint-app/src/hooks/use-launch-flow.ts b/flowsint-app/src/hooks/use-launch-flow.ts
index ce13fc40..c067fb07 100644
--- a/flowsint-app/src/hooks/use-launch-flow.ts
+++ b/flowsint-app/src/hooks/use-launch-flow.ts
@@ -15,7 +15,7 @@ export function useLaunchFlow(askUser: boolean = false) {
mutationFn: ({ flowId, body }: { flowId: string; body: BodyInit }) =>
flowService.launch(flowId, body),
onSuccess: (_, variables) => {
- openClonsole()
+ // openClonsole()
queryClient.invalidateQueries({
queryKey: queryKeys.flows.detail(variables.flowId)
})
diff --git a/flowsint-app/src/routes/_auth.dashboard.investigations.$investigationId.$type.$id.tsx b/flowsint-app/src/routes/_auth.dashboard.investigations.$investigationId.$type.$id.tsx
index a522ac9c..c7df7bd6 100644
--- a/flowsint-app/src/routes/_auth.dashboard.investigations.$investigationId.$type.$id.tsx
+++ b/flowsint-app/src/routes/_auth.dashboard.investigations.$investigationId.$type.$id.tsx
@@ -46,19 +46,17 @@ const GraphPageContent = () => {
useEffect(() => {
const refetchWithCallback = async (onSuccess?: () => void) => {
- console.log('[Route] refetchWithCallback called with callback:', !!onSuccess)
- await refetch()
- console.log('[Route] refetch completed')
+ const result = await refetch()
// Execute callback after refetch completes and data is updated
if (onSuccess) {
- console.log('[Route] executing callback after refetch')
// Small delay to ensure React Query has updated the data in the store
- setTimeout(onSuccess, 0)
+ setTimeout(() => {
+ onSuccess()
+ }, 100)
}
}
- console.log('[Route] Setting refetchGraph in store')
setActions({ refetchGraph: refetchWithCallback })
- }, [refetch, setActions, id])
+ }, [refetch, setActions, id, data])
if (type === 'graph') {
return <GraphPanel isLoading={isLoading} isRefetching={isRefetching} graphData={data} />
diff --git a/flowsint-app/src/stores/graph-controls-store.ts b/flowsint-app/src/stores/graph-controls-store.ts
index d9a0265e..39b83209 100644
--- a/flowsint-app/src/stores/graph-controls-store.ts
+++ b/flowsint-app/src/stores/graph-controls-store.ts
@@ -18,6 +18,7 @@ type GraphControlsStore = {
setActions: (actions: Partial<GraphControlsStore>) => void
refetchGraph: (onSuccess?: () => void) => void
regenerateLayout: (layoutType: LayoutType) => void
+ getViewportCenter: () => { x: number; y: number } | null
setCurrentLayoutType: (layoutType: LayoutType) => void
setShouldRegenerateLayoutOnNextRefetch: (should: boolean) => void
setView: (view: 'graph' | 'table' | 'map' | 'relationships') => void
@@ -40,6 +41,7 @@ export const useGraphControls = create<GraphControlsStore>()(
setActions: (actions) => set(actions),
refetchGraph: (onSuccess) => { },
regenerateLayout: () => { },
+ getViewportCenter: () => null,
setCurrentLayoutType: (layoutType) => set({ currentLayoutType: layoutType }),
setShouldRegenerateLayoutOnNextRefetch: (should) => set({ shouldRegenerateLayoutOnNextRefetch: should }),
setView: (view) => set({ view }),