Skip to content

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

fix(app): broken refetch pipeline

dextmorgn53165b8d0637
diff --git a/flowsint-app/src/components/sketches/filters.tsx b/flowsint-app/src/components/sketches/filters.tsx
deleted file mode 100644
index 4aeb1958..00000000
--- a/flowsint-app/src/components/sketches/filters.tsx
+++ /dev/null
@@ -1,45 +0,0 @@
-import { useGraphStore } from '@/stores/graph-store'
-import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
-import { Checkbox } from '../ui/checkbox'
-import { Separator } from '../ui/separator'
-
-const Filters = ({ children }: { children: React.ReactNode }) => {
- const filters = useGraphStore((s) => s.filters)
- const toggleTypeFilter = useGraphStore((s) => s.toggleTypeFilter)
-
- return (
- <Popover>
- <PopoverTrigger asChild>
- <div>{children}</div>
- </PopoverTrigger>
- <PopoverContent className="w-80">
- <div className="grid gap-4">
- <div className="space-y-2">
- <h4 className="leading-none font-medium">Filters</h4>
- </div>
- <Separator />
- <p className="text-muted-foreground text-sm">Filter by entity type</p>
- {filters.types.length === 0 ? (
- <p className="text-muted-foreground text-sm">No filter to display.</p>
- ) : (
- <ul className="grid grid-cols-2 gap-2">
- {filters.types.map((filter) => (
- <li>
- <div className="flex items-center gap-1">
- <Checkbox
- checked={filter.checked}
- onCheckedChange={() => toggleTypeFilter(filter)}
- />
- {filter.type}
- </div>
- </li>
- ))}
- </ul>
- )}
- </div>
- </PopoverContent>
- </Popover>
- )
-}
-
-export default Filters
diff --git a/flowsint-app/src/components/sketches/filters/filters.tsx b/flowsint-app/src/components/sketches/filters/filters.tsx
new file mode 100644
index 00000000..d01764e3
--- /dev/null
+++ b/flowsint-app/src/components/sketches/filters/filters.tsx
@@ -0,0 +1,32 @@
+import { useGraphStore } from '@/stores/graph-store'
+import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
+import { Separator } from '@/components//ui/separator'
+import TypeFilters from './type-filters'
+import RuleFilters from './rule-filters'
+
+const Filters = ({ children }: { children: React.ReactNode }) => {
+ const filters = useGraphStore((s) => s.filters)
+ const toggleTypeFilter = useGraphStore((s) => s.toggleTypeFilter)
+ const setFilters = useGraphStore((s) => s.setFilters)
+
+ return (
+ <Popover>
+ <PopoverTrigger asChild>
+ <div>{children}</div>
+ </PopoverTrigger>
+ <PopoverContent className="w-112 bg-background max-h-[60vh] overflow-auto">
+ <div className="grid gap-2">
+ <div className="space-y-1">
+ <h5 className="leading-none font-medium text-sm">Filters</h5>
+ </div>
+ <Separator />
+ <TypeFilters filters={filters} toggleTypeFilter={toggleTypeFilter} />
+ {/* <Separator />
+ <RuleFilters filters={filters} setFilters={setFilters} /> */}
+ </div>
+ </PopoverContent>
+ </Popover>
+ )
+}
+
+export default Filters
diff --git a/flowsint-app/src/components/sketches/filters/rule-filters.tsx b/flowsint-app/src/components/sketches/filters/rule-filters.tsx
new file mode 100644
index 00000000..4d58ef37
--- /dev/null
+++ b/flowsint-app/src/components/sketches/filters/rule-filters.tsx
@@ -0,0 +1,155 @@
+import { Button } from "@/components/ui/button"
+import { Input } from "@/components/ui/input"
+import { Plus, XIcon } from "lucide-react"
+import { Select, SelectItem, SelectContent, SelectTrigger, SelectValue } from "@/components/ui/select"
+import { memo, useState } from "react"
+import { v4 as uuidv4 } from "uuid"
+import type { RuleFilter, Filters, RuleKey, RuleOperator } from "@/types/filter"
+
+type RuleFiltersProps = {
+ filters: Filters
+ setFilters: (filters: Filters) => void
+}
+
+function RuleFilters({ filters, setFilters }: RuleFiltersProps) {
+ const [draft, setDraft] = useState<Filters>(filters)
+
+ const { rules } = draft
+
+ const setDraftRules = (newRules: RuleFilter[]) => {
+ setDraft(prev => ({ ...prev, rules: newRules }))
+ }
+
+ const addRule = () => {
+ setDraftRules([
+ ...rules,
+ {
+ id: uuidv4(),
+ key: "label",
+ operator: "is",
+ matcher: ""
+ }
+ ])
+ }
+
+ const removeRule = (id: string) => {
+ setDraftRules(rules.filter(r => r.id !== id))
+ }
+
+ const updateRule = (id: string, patch: Partial<Omit<RuleFilter, "id">>) => {
+ setDraftRules(
+ rules.map(r => (r.id === id ? { ...r, ...patch } : r))
+ )
+ }
+
+ const applyChanges = () => {
+ setFilters(draft)
+ }
+
+ return (
+ <div className="space-y-4">
+ <div className="flex justify-between items-center">
+ <p className="opacity-90 text-sm">Filter by rule</p>
+
+ <div className="flex gap-2">
+ <Button
+ variant="outline"
+ className="border-dashed h-7 text-xs"
+ size="sm"
+ onClick={addRule}
+ >
+ <Plus className="text-muted-foreground !h-3 !w-3" /> New rule
+ </Button>
+
+ <Button
+ disabled={rules.length === 0}
+ variant="default"
+ className="h-7 text-xs"
+ size="sm"
+ onClick={applyChanges}
+ >
+ Apply
+ </Button>
+ </div>
+ </div>
+
+ {rules.length === 0 ? (
+ <p className="text-xs text-muted-foreground">
+ Start by adding a filter rule.
+ </p>
+ ) : (
+ <ul className="space-y-2">
+ {rules.map(rule => (
+ <RuleItem
+ key={rule.id}
+ rule={rule}
+ onChange={patch => updateRule(rule.id, patch)}
+ onRemove={() => removeRule(rule.id)}
+ />
+ ))}
+ </ul>
+ )}
+ </div>
+ )
+}
+
+
+type RuleItemProps = {
+ rule: RuleFilter
+ onChange: (patch: Partial<Omit<RuleFilter, "id">>) => void
+ onRemove: () => void
+}
+
+const RuleItem = memo(({ rule, onChange, onRemove }: RuleItemProps) => (
+ <li>
+ <div className="flex gap-2 justify-between">
+ <KeyDropDown value={rule.key} onChange={(v) => onChange({ key: v })} />
+
+ <OperatorDropDown value={rule.operator} onChange={(v) => onChange({ operator: v })} />
+
+ <Input
+ value={rule.matcher}
+ onChange={e => onChange({ matcher: e.target.value })}
+ className="h-7 grow w-1/3"
+ placeholder="matcher"
+ />
+
+ <Button
+ onClick={onRemove}
+ variant="ghost"
+ size="icon"
+ className="rounded-full h-7 w-7 hover:bg-muted"
+ >
+ <XIcon />
+ </Button>
+ </div>
+ </li>
+))
+
+
+const KEYS: RuleKey[] = ["label", "domain", "ip"]
+const OPERATORS: RuleOperator[] = ["is", "not", "like", "startsWith", "endsWith"]
+
+const KeyDropDown = memo(({ value, onChange }: { value: RuleKey, onChange: (v: RuleKey) => void }) => (
+ <Select value={value} onValueChange={onChange}>
+ <SelectTrigger className="!h-7 w-1/3">
+ <SelectValue placeholder="property" />
+ </SelectTrigger>
+ <SelectContent>
+ {KEYS.map(k => <SelectItem key={k} value={k}>{k}</SelectItem>)}
+ </SelectContent>
+ </Select>
+))
+
+const OperatorDropDown = memo(({ value, onChange }: { value: RuleOperator, onChange: (v: RuleOperator) => void }) => (
+ <Select value={value} onValueChange={onChange}>
+ <SelectTrigger className="!h-7 grow w-1/3">
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent>
+ {OPERATORS.map(o => <SelectItem key={o} value={o}>{o}</SelectItem>)}
+ </SelectContent>
+ </Select>
+))
+
+export default RuleFilters
diff --git a/flowsint-app/src/components/sketches/filters/type-filters.tsx b/flowsint-app/src/components/sketches/filters/type-filters.tsx
new file mode 100644
index 00000000..c91f756b
--- /dev/null
+++ b/flowsint-app/src/components/sketches/filters/type-filters.tsx
@@ -0,0 +1,33 @@
+import { Checkbox } from '@/components/ui/checkbox'
+import { TypeFilter, Filters } from '@/types/filter'
+
+type TypeFiltersProps = {
+ filters: Filters,
+ toggleTypeFilter: (filter: TypeFilter) => void
+}
+const TypeFilters = ({ filters, toggleTypeFilter }: TypeFiltersProps) => {
+ return (
+ <div className='space-y-2'>
+ <p className="opacity-90 text-sm">Filter by entity type</p>
+ {filters.types.length === 0 ? (
+ <p className="text-muted-foreground text-xs">No filter to display.</p>
+ ) : (
+ <ul className="grid grid-cols-3 gap-2">
+ {filters.types.map((filter) => (
+ <li>
+ <div className="flex items-center gap-1">
+ <Checkbox
+ checked={filter.checked}
+ onCheckedChange={() => toggleTypeFilter(filter)}
+ />
+ {filter.type}
+ </div>
+ </li>
+ ))}
+ </ul>
+ )}
+ </div>
+ )
+}
+
+export default TypeFilters
\ No newline at end of file
diff --git a/flowsint-app/src/components/sketches/graph/index.tsx b/flowsint-app/src/components/sketches/graph/index.tsx
index c33ef1ec..2af5e3eb 100644
--- a/flowsint-app/src/components/sketches/graph/index.tsx
+++ b/flowsint-app/src/components/sketches/graph/index.tsx
@@ -54,9 +54,6 @@ const GraphViewer: React.FC<GraphViewerProps> = ({
const nodeColors = useNodesDisplaySettings((s) => s.colors)
const setActions = useGraphControls((s) => s.setActions)
const setCurrentLayoutType = useGraphControls((s) => s.setCurrentLayoutType)
- const shouldRegenerateLayoutOnNextRefetch = useGraphControls((s) => s.shouldRegenerateLayoutOnNextRefetch)
- const setShouldRegenerateLayoutOnNextRefetch = useGraphControls((s) => s.setShouldRegenerateLayoutOnNextRefetch)
- const currentLayoutType = useGraphControls((s) => s.currentLayoutType)
const autoZoomOnCurrentNode = useGraphSettingsStore((s) => s.getSettingValue('general', 'autoZoomOnCurrentNode'))
const forceSettings = useGraphSettingsStore((s) => s.forceSettings)
const setImportModalOpen = useGraphSettingsStore((s) => s.setImportModalOpen)
@@ -206,6 +203,18 @@ const GraphViewer: React.FC<GraphViewerProps> = ({
handleNodeDragEnd(node, graphData)
}, [handleNodeDragEnd, graphData])
+ const hasPerformedInitialZoom = useRef(false)
+
+ const handleEngineStop = useCallback(() => {
+ // Perform initial zoom to fit only once when graph is first rendered
+ if (!hasPerformedInitialZoom.current && graphRef.current) {
+ hasPerformedInitialZoom.current = true
+ if (typeof graphRef.current.zoomToFit === 'function') {
+ graphRef.current.zoomToFit(400)
+ }
+ }
+ }, [])
+
useGraphInitialization({
graphRef,
instanceId,
@@ -220,14 +229,6 @@ const GraphViewer: React.FC<GraphViewerProps> = ({
clearHighlights()
}, [nodes, edges, clearHighlights])
- // Auto-regenerate layout when data is refetched (if flag is set)
- useEffect(() => {
- if (shouldRegenerateLayoutOnNextRefetch && currentLayoutType && graphData.nodes.length > 0) {
- setShouldRegenerateLayoutOnNextRefetch(false)
- regenerateLayout(currentLayoutType)
- }
- }, [graphData.nodes.length, shouldRegenerateLayoutOnNextRefetch, currentLayoutType, regenerateLayout, setShouldRegenerateLayoutOnNextRefetch])
-
const handleOpenNewAddItemDialog = useCallback(() => {
setOpenMainDialog(true)
}, [setOpenMainDialog])
@@ -319,6 +320,7 @@ const GraphViewer: React.FC<GraphViewerProps> = ({
linkCurvature={(link) => link.curvature || 0}
nodeCanvasObject={renderNodeCallback}
onNodeDragEnd={wrappedHandleNodeDragEnd}
+ onEngineStop={handleEngineStop}
cooldownTicks={allowForces ? forceSettings.cooldownTicks.value : 0}
cooldownTime={forceSettings.cooldownTime.value}
d3AlphaDecay={forceSettings.d3AlphaDecay.value}
diff --git a/flowsint-app/src/components/sketches/graph/use-graph-initialization.ts b/flowsint-app/src/components/sketches/graph/use-graph-initialization.ts
index 7a93c136..03ed83c7 100644
--- a/flowsint-app/src/components/sketches/graph/use-graph-initialization.ts
+++ b/flowsint-app/src/components/sketches/graph/use-graph-initialization.ts
@@ -24,121 +24,91 @@ export const useGraphInitialization = ({
regenerateLayoutRef.current = regenerateLayout
}, [regenerateLayout])
- const initializeGraph = useCallback(
- (graphInstance: any) => {
- if (!graphInstance) return
+ // Set up graph control actions immediately (not waiting for graphRef)
+ useEffect(() => {
+ if (instanceId) return
- if (
- typeof graphInstance.zoom !== 'function' ||
- typeof graphInstance.zoomToFit !== 'function'
- ) {
- setTimeout(() => {
- if (graphRef.current && !isGraphReadyRef.current) {
- initializeGraph(graphRef.current)
- }
- }, 100)
- return
- }
- if (isGraphReadyRef.current) return
- isGraphReadyRef.current = true
- // Initial zoom to fit
- setTimeout(() => {
+ setActions({
+ zoomIn: () => {
+ if (graphRef.current && typeof graphRef.current.zoom === 'function') {
+ const zoom = graphRef.current.zoom()
+ graphRef.current.zoom(zoom * 1.5)
+ }
+ },
+ zoomOut: () => {
+ if (graphRef.current && typeof graphRef.current.zoom === 'function') {
+ const zoom = graphRef.current.zoom()
+ graphRef.current.zoom(zoom * 0.75)
+ }
+ },
+ zoomToFit: () => {
if (graphRef.current && typeof graphRef.current.zoomToFit === 'function') {
graphRef.current.zoomToFit(400)
}
- }, 50)
-
- if (!instanceId) {
- setActions({
- zoomIn: () => {
- if (graphRef.current && typeof graphRef.current.zoom === 'function') {
- const zoom = graphRef.current.zoom()
- graphRef.current.zoom(zoom * 1.5)
- }
- },
- zoomOut: () => {
- if (graphRef.current && typeof graphRef.current.zoom === 'function') {
- const zoom = graphRef.current.zoom()
- graphRef.current.zoom(zoom * 0.75)
- }
- },
- zoomToFit: () => {
- if (graphRef.current && typeof graphRef.current.zoomToFit === 'function') {
- graphRef.current.zoomToFit(400)
- }
- },
- zoomToSelection: () => {
- if (graphRef.current && typeof graphRef.current.zoomToFit === 'function') {
- const nodeFilterFn = (node: any) => selectedNodeIdsRef.current?.has(node.id)
- graphRef.current.zoomToFit(400, 50, nodeFilterFn)
- }
- },
- centerOnNode: (x: number, y: number) => {
- if (graphRef.current && typeof graphRef.current.centerAt === 'function') {
- graphRef.current.centerAt(x, y, 400)
- if (typeof graphRef.current.zoom === 'function') {
- graphRef.current.zoom(6, 400)
- }
- }
- },
- regenerateLayout: (layoutType: 'force' | 'hierarchy') => {
- regenerateLayoutRef.current(layoutType)
- },
- getViewportCenter: () => {
- if (!graphRef.current) return null
- const rect = graphRef.current.getBoundingClientRect?.()
- if (!rect) return { x: 0, y: 0 }
- const screenCenterX = rect.width / 2
- const screenCenterY = rect.height / 2
- if (typeof graphRef.current.screen2GraphCoords === 'function') {
- return graphRef.current.screen2GraphCoords(screenCenterX, screenCenterY)
- }
- return { x: 0, y: 0 }
+ },
+ zoomToSelection: () => {
+ if (graphRef.current && typeof graphRef.current.zoomToFit === 'function') {
+ const nodeFilterFn = (node: any) => selectedNodeIdsRef.current?.has(node.id)
+ graphRef.current.zoomToFit(400, 50, nodeFilterFn)
+ }
+ },
+ centerOnNode: (x: number, y: number) => {
+ if (graphRef.current && typeof graphRef.current.centerAt === 'function') {
+ graphRef.current.centerAt(x, y, 400)
+ if (typeof graphRef.current.zoom === 'function') {
+ graphRef.current.zoom(6, 400)
}
- })
+ }
+ },
+ regenerateLayout: (layoutType: 'force' | 'hierarchy') => {
+ regenerateLayoutRef.current(layoutType)
+ },
+ getViewportCenter: () => {
+ if (!graphRef.current) return null
+ const rect = graphRef.current.getBoundingClientRect?.()
+ if (!rect) return { x: 0, y: 0 }
+ const screenCenterX = rect.width / 2
+ const screenCenterY = rect.height / 2
+ if (typeof graphRef.current.screen2GraphCoords === 'function') {
+ return graphRef.current.screen2GraphCoords(screenCenterX, screenCenterY)
+ }
+ return { x: 0, y: 0 }
}
+ })
- onGraphRef?.(graphInstance)
- },
- [setActions, onGraphRef, instanceId, selectedNodeIdsRef, graphRef]
- )
+ return () => {
+ setActions({
+ zoomIn: () => { },
+ zoomOut: () => { },
+ zoomToFit: () => { },
+ zoomToSelection: () => { },
+ centerOnNode: () => { },
+ regenerateLayout: () => { },
+ getViewportCenter: () => null
+ })
+ }
+ }, [setActions, instanceId, selectedNodeIdsRef, graphRef])
- // Poll for graphRef to be ready
+ // Call onGraphRef when graph instance is ready
useEffect(() => {
- const checkAndInitialize = () => {
- if (graphRef.current && !isGraphReadyRef.current) {
- initializeGraph(graphRef.current)
- }
- }
+ const graphInstance = graphRef.current
+ if (!graphInstance || isGraphReadyRef.current) return
- // Check immediately
- checkAndInitialize()
+ // Wait for graph methods to be available
+ if (
+ typeof graphInstance.zoom !== 'function' ||
+ typeof graphInstance.zoomToFit !== 'function'
+ ) {
+ return
+ }
- // Then check every 100ms until initialized
- const interval = setInterval(() => {
- if (isGraphReadyRef.current) {
- clearInterval(interval)
- } else {
- checkAndInitialize()
- }
- }, 100)
+ isGraphReadyRef.current = true
+ onGraphRef?.(graphInstance)
return () => {
- clearInterval(interval)
- if (!instanceId && isGraphReadyRef.current) {
- setActions({
- zoomIn: () => { },
- zoomOut: () => { },
- zoomToFit: () => { },
- zoomToSelection: () => { },
- centerOnNode: () => { },
- regenerateLayout: () => { },
- getViewportCenter: () => null
- })
- isGraphReadyRef.current = false
- }
+ isGraphReadyRef.current = false
}
- }, [initializeGraph, instanceId, setActions])
+ }, [onGraphRef, graphRef])
return {
isGraphReadyRef
diff --git a/flowsint-app/src/components/sketches/graph/use-graph-layout.ts b/flowsint-app/src/components/sketches/graph/use-graph-layout.ts
index cb0b3d96..5641b3d1 100644
--- a/flowsint-app/src/components/sketches/graph/use-graph-layout.ts
+++ b/flowsint-app/src/components/sketches/graph/use-graph-layout.ts
@@ -45,17 +45,19 @@ export const useGraphLayout = ({
edges: graphData.links
})
- // Zoom to fit after layout
- if (graphRef.current?.zoomToFit) {
- graphRef.current.zoomToFit(400)
- }
+ // Wait a bit for positions to be applied, then zoom to fit
+ setTimeout(() => {
+ if (graphRef.current?.zoomToFit) {
+ graphRef.current.zoomToFit(400)
+ }
+ }, 100)
} catch (error) {
console.error('Layout calculation failed:', error)
} finally {
// Keep overlay visible for smooth transition
setTimeout(() => {
setIsRegeneratingLayout(false)
- }, 500)
+ }, 600)
}
}, [applyLayout, graphRef, graphData])
diff --git a/flowsint-app/src/components/sketches/toolbar.tsx b/flowsint-app/src/components/sketches/toolbar.tsx
index d1106ab7..d5d6360d 100644
--- a/flowsint-app/src/components/sketches/toolbar.tsx
+++ b/flowsint-app/src/components/sketches/toolbar.tsx
@@ -15,14 +15,13 @@ import {
Minus,
RotateCw,
ZoomIn,
- RectangleHorizontal,
ChevronDown,
SquareDashed,
Focus
} from 'lucide-react'
import { memo, useCallback } from 'react'
import { toast } from 'sonner'
-import Filters from './filters'
+import Filters from './filters/filters'
import { SaveStatusIndicator } from './save-status-indicator'
import { Separator } from '../ui/separator'
import { ViewToggle } from './view-toggle'
@@ -126,7 +125,6 @@ export const Toolbar = memo(function Toolbar({ isLoading }: { isLoading: boolean
if (!confirmed) {
return
}
-
try {
regenerateLayout('force')
toast.success('Force layout applied successfully')
@@ -204,7 +202,7 @@ export const Toolbar = memo(function Toolbar({ isLoading }: { isLoading: boolean
icon={<ZoomIn className="h-4 w-4 opacity-70" />}
tooltip="Zoom In"
onClick={zoomIn}
- disabled={view !== 'graph' || isSelectorModeActive}
+ disabled={view !== 'graph' || isSelectorModeActive || !zoomIn}
/>
<ToolbarButton
icon={<Minus className="h-4 w-4 opacity-70" />}
diff --git a/flowsint-app/src/hooks/use-graph-refresh.ts b/flowsint-app/src/hooks/use-graph-refresh.ts
index 53a2bf90..0415755d 100644
--- a/flowsint-app/src/hooks/use-graph-refresh.ts
+++ b/flowsint-app/src/hooks/use-graph-refresh.ts
@@ -6,28 +6,26 @@ const API_URL = import.meta.env.VITE_API_URL
export function useGraphRefresh(sketch_id: string | undefined) {
const refetchGraph = useGraphControls((s) => s.refetchGraph)
- const setShouldRegenerateLayoutOnNextRefetch = useGraphControls((s) => s.setShouldRegenerateLayoutOnNextRefetch)
+ const regenerateLayout = useGraphControls((s) => s.regenerateLayout)
const currentLayoutType = useGraphControls((s) => s.currentLayoutType)
// Use refs to avoid reconnecting SSE when functions change
const refetchGraphRef = useRef(refetchGraph)
- const setShouldRegenerateRef = useRef(setShouldRegenerateLayoutOnNextRefetch)
+ const regenerateLayoutRef = useRef(regenerateLayout)
const currentLayoutTypeRef = useRef(currentLayoutType)
// Keep refs updated
useEffect(() => {
refetchGraphRef.current = refetchGraph
- setShouldRegenerateRef.current = setShouldRegenerateLayoutOnNextRefetch
+ regenerateLayoutRef.current = regenerateLayout
currentLayoutTypeRef.current = currentLayoutType
- }, [refetchGraph, setShouldRegenerateLayoutOnNextRefetch, currentLayoutType])
+ }, [refetchGraph, regenerateLayout, currentLayoutType])
useEffect(() => {
if (!sketch_id) return
-
const eventSource = new EventSource(
`${API_URL}/api/events/sketch/${sketch_id}/status/stream`
)
-
eventSource.onmessage = (e) => {
try {
// Handle malformed SSE data (connection message has extra "data: " prefix)
@@ -35,39 +33,33 @@ export function useGraphRefresh(sketch_id: string | undefined) {
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
-
// Only handle COMPLETED events
if (event.type === EventLevel.COMPLETED) {
const refetch = refetchGraphRef.current
- const setShouldRegenerate = setShouldRegenerateRef.current
+ const regenerate = regenerateLayoutRef.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()
+ // Refetch graph data with callback to regenerate layout after
+ refetch(() => {
+ // After refetch completes, regenerate layout if we have one active
+ if (layoutType && typeof regenerate === 'function') {
+ regenerate(layoutType)
+ }
+ })
}
} catch (error) {
console.error('[useGraphRefresh] Failed to parse SSE event:', error, e.data)
diff --git a/flowsint-app/src/stores/graph-controls-store.ts b/flowsint-app/src/stores/graph-controls-store.ts
index ce81629e..88aaa514 100644
--- a/flowsint-app/src/stores/graph-controls-store.ts
+++ b/flowsint-app/src/stores/graph-controls-store.ts
@@ -10,7 +10,6 @@ type GraphControlsStore = {
isSelectorModeActive: boolean
selectionMode: SelectionMode
currentLayoutType: LayoutType
- shouldRegenerateLayoutOnNextRefetch: boolean
zoomToFit: () => void
zoomIn: () => void
zoomOut: () => void
@@ -22,7 +21,6 @@ type GraphControlsStore = {
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
setIsSelectorModeActive: (active: boolean) => void
setSelectionMode: (mode: SelectionMode) => void
@@ -35,7 +33,6 @@ export const useGraphControls = create<GraphControlsStore>()(
isSelectorModeActive: false,
selectionMode: 'lasso',
currentLayoutType: 'force',
- shouldRegenerateLayoutOnNextRefetch: false,
zoomToFit: () => { },
zoomIn: () => { },
zoomOut: () => { },
@@ -47,7 +44,6 @@ export const useGraphControls = create<GraphControlsStore>()(
regenerateLayout: () => { },
getViewportCenter: () => null,
setCurrentLayoutType: (layoutType) => set({ currentLayoutType: layoutType }),
- setShouldRegenerateLayoutOnNextRefetch: (should) => set({ shouldRegenerateLayoutOnNextRefetch: should }),
setView: (view) => set({ view }),
setIsSelectorModeActive: (active) => set({ isSelectorModeActive: active }),
setSelectionMode: (mode) => set({ selectionMode: mode })
diff --git a/flowsint-app/src/stores/graph-store.ts b/flowsint-app/src/stores/graph-store.ts
index 6846a463..ee61fe77 100644
--- a/flowsint-app/src/stores/graph-store.ts
+++ b/flowsint-app/src/stores/graph-store.ts
@@ -2,14 +2,7 @@ import { create } from 'zustand'
import { persist } from 'zustand/middleware'
import type { GraphNode, GraphEdge, NodeData } from '@/types'
import { type ActionItem } from '@/lib/action-items'
-
-export type TypeFilter = {
- type: string
- checked: boolean
-}
-export type Filters = {
- types: TypeFilter[]
-}
+import { Filters, TypeFilter } from '@/types/filter'
interface GraphState {
// === Graph ===
@@ -339,20 +332,8 @@ export const useGraphStore = create<GraphState>()(
// === Filters ===
filters: {
- types: [
- {
- type: 'domain',
- checked: true
- },
- {
- type: 'ip',
- checked: true
- },
- {
- type: 'individual',
- checked: true
- }
- ]
+ types: [],
+ rules: [],
},
setFilters: (filters) => {
const { nodes, edges } = get()
diff --git a/flowsint-app/src/types/filter.ts b/flowsint-app/src/types/filter.ts
new file mode 100644
index 00000000..8511e173
--- /dev/null
+++ b/flowsint-app/src/types/filter.ts
@@ -0,0 +1,19 @@
+export type TypeFilter = {
+ type: string
+ checked: boolean
+}
+
+export type RuleOperator = "is" | "not" | "like" | "startsWith" | "endsWith"
+export type RuleKey = "label" | "domain" | "ip"
+
+export type RuleFilter = {
+ id: string
+ key: RuleKey
+ operator: RuleOperator
+ matcher: string
+}
+
+export type Filters = {
+ types: TypeFilter[]
+ rules: RuleFilter[]
+}
\ No newline at end of file