A modern platform for visual, flexible, and extensible graph-based investigations. For cybersecurity analysts and investigators.
fix(app): generate layout on new nodes
dextmorgnf8d8bc7db612
diff --git a/flowsint-app/src/components/graphs/graph-viewer.tsx b/flowsint-app/src/components/graphs/graph-viewer.tsxindex 1e72004a..b50229af 100644--- a/flowsint-app/src/components/graphs/graph-viewer.tsx+++ b/flowsint-app/src/components/graphs/graph-viewer.tsx@@ -169,7 +169,10 @@ const GraphViewer: React.FC<GraphViewerProps> = ({// Store selectorsconst nodeColors = useNodesDisplaySettings((s) => s.colors)const setActions = useGraphControls((s) => s.setActions)+ const currentLayoutType = useGraphControls((s) => s.currentLayoutType)const setCurrentLayoutType = useGraphControls((s) => s.setCurrentLayoutType)+ const shouldRegenerateLayoutOnNextRefetch = useGraphControls((s) => s.shouldRegenerateLayoutOnNextRefetch)+ const setShouldRegenerateLayoutOnNextRefetch = useGraphControls((s) => s.setShouldRegenerateLayoutOnNextRefetch)// Combine graph store selectors with useShallow for better performanceconst { currentNode, currentEdge, selectedNodes, selectedEdges, toggleEdgeSelection, setCurrentEdge, clearSelectedEdges, setOpenMainDialog } = useGraphStore(@@ -193,12 +196,7 @@ const GraphViewer: React.FC<GraphViewerProps> = ({() => 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 handleEdgeClickconst edgeMap = useMemo(@@ -505,6 +503,14 @@ const GraphViewer: React.FC<GraphViewerProps> = ({}}, [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])+// Event handlers with proper memoizationconst handleNodeClick = useCallback((node: any, event: MouseEvent) => {diff --git a/flowsint-app/src/hooks/use-events.ts b/flowsint-app/src/hooks/use-events.tsindex d9f0e8e7..d2ade099 100644--- a/flowsint-app/src/hooks/use-events.ts+++ b/flowsint-app/src/hooks/use-events.ts@@ -10,10 +10,8 @@ const API_URL = import.meta.env.VITE_API_URLexport function useEvents(sketch_id: string | undefined) {const [liveLogs, setLiveLogs] = useState<Event[]>([])- // const [graphUpdates, setGraphUpdates] = useState<{ nodes: GraphNode[]; edges: GraphEdge[] }[]>([])const refetchGraph = useGraphControls((s) => s.refetchGraph)- const regenerateLayout = useGraphControls((s) => s.regenerateLayout)- const currentLayoutType = useGraphControls((s) => s.currentLayoutType)+ const setShouldRegenerateLayoutOnNextRefetch = useGraphControls((s) => s.setShouldRegenerateLayoutOnNextRefetch)const { data: previousLogs = [], refetch } = useQuery({queryKey: queryKeys.logs.bySketch(sketch_id as string),@@ -43,22 +41,9 @@ export function useEvents(sketch_id: string | undefined) {const raw = JSON.parse(e.data) as anyconst event = JSON.parse(raw.data) as Eventif (event.type === EventLevel.COMPLETED) {- // Refetch graph data+ // Set flag to regenerate layout after refetch completes+ setShouldRegenerateLayoutOnNextRefetch(true)refetchGraph()- // Auto-regenerate layout after refetch with 500ms delay- setTimeout(() => {- if (currentLayoutType && regenerateLayout) {- regenerateLayout(currentLayoutType)- }- }, 500)-- // const nodes = event.payload.nodes as GraphNode[]- // const edges = event.payload.edges as GraphEdge[]- // if (nodes && edges) {- // setGraphUpdates((prev) => [...prev, { nodes: nodes, edges: edges }])- // } else {- // console.error("[useSketchEvents] Graph append event has no nodes or edges")- // }}setLiveLogs((prev) => [...prev.slice(-99), event])} catch (error) {@@ -74,7 +59,7 @@ export function useEvents(sketch_id: string | undefined) {return () => {eventSource.close()}- }, [sketch_id, refetchGraph, currentLayoutType, regenerateLayout])+ }, [sketch_id, refetchGraph])const logs = useMemo(() => [...previousLogs, ...liveLogs].slice(-100),diff --git a/flowsint-app/src/stores/graph-controls-store.ts b/flowsint-app/src/stores/graph-controls-store.tsindex 20e6b144..8f6ca956 100644--- a/flowsint-app/src/stores/graph-controls-store.ts+++ b/flowsint-app/src/stores/graph-controls-store.ts@@ -10,6 +10,7 @@ type GraphControlsStore = {isSelectorModeActive: booleanselectionMode: SelectionModecurrentLayoutType: LayoutType+ shouldRegenerateLayoutOnNextRefetch: booleanzoomToFit: () => voidzoomIn: () => voidzoomOut: () => void@@ -18,6 +19,7 @@ type GraphControlsStore = {refetchGraph: () => voidregenerateLayout: (layoutType: LayoutType) => voidsetCurrentLayoutType: (layoutType: LayoutType) => void+ setShouldRegenerateLayoutOnNextRefetch: (should: boolean) => voidsetView: (view: 'graph' | 'table' | 'map' | 'relationships') => voidsetIsSelectorModeActive: (active: boolean) => voidsetSelectionMode: (mode: SelectionMode) => void@@ -30,6 +32,7 @@ export const useGraphControls = create<GraphControlsStore>()(isSelectorModeActive: false,selectionMode: 'lasso',currentLayoutType: 'force',+ shouldRegenerateLayoutOnNextRefetch: false,zoomToFit: () => { },zoomIn: () => { },zoomOut: () => { },@@ -38,6 +41,7 @@ export const useGraphControls = create<GraphControlsStore>()(refetchGraph: () => { },regenerateLayout: () => { },setCurrentLayoutType: (layoutType) => set({ currentLayoutType: layoutType }),+ setShouldRegenerateLayoutOnNextRefetch: (should) => set({ shouldRegenerateLayoutOnNextRefetch: should }),setView: (view) => set({ view }),setIsSelectorModeActive: (active) => set({ isSelectorModeActive: active }),setSelectionMode: (mode) => set({ selectionMode: mode })