Skip to content

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

feat(app): relayout on new data

dextmorgnfe2872784eb9
diff --git a/flowsint-app/src/components/graphs/add-item-dialog.tsx b/flowsint-app/src/components/graphs/add-item-dialog.tsx
index 28028f7c..9c53bf59 100644
--- a/flowsint-app/src/components/graphs/add-item-dialog.tsx
+++ b/flowsint-app/src/components/graphs/add-item-dialog.tsx
@@ -18,6 +18,7 @@ import { useLayoutStore } from '@/stores/layout-store'
import { useActionItems } from '@/hooks/use-action-items'
import { GraphNode } from '@/types'
import { useGraphSettingsStore } from '@/stores/graph-settings-store'
+import { useGraphControls } from '@/stores/graph-controls-store'
export default function AddItemDialog() {
const handleOpenFormModal = useGraphStore((state) => state.handleOpenFormModal)
@@ -34,6 +35,9 @@ export default function AddItemDialog() {
const replaceNodeId = useGraphStore((state) => state.replaceNodeId)
const setActiveTab = useLayoutStore((state) => state.setActiveTab)
const setImportModalOpen = useGraphSettingsStore((s) => s.setImportModalOpen)
+ const regenerateLayout = useGraphControls((s) => s.regenerateLayout)
+ const currentLayoutType = useGraphControls((s) => s.currentLayoutType)
+
const { id: sketch_id } = useParams({ strict: false })
const { actionItems, isLoading } = useActionItems()
@@ -151,6 +155,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)
+ }
}
const navigateToSubItems = (item: ActionItem) => {
diff --git a/flowsint-app/src/components/graphs/background-context-menu.tsx b/flowsint-app/src/components/graphs/background-context-menu.tsx
index c074516c..3380c49a 100644
--- a/flowsint-app/src/components/graphs/background-context-menu.tsx
+++ b/flowsint-app/src/components/graphs/background-context-menu.tsx
@@ -7,7 +7,7 @@ import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import { Tabs, TabsList, TabsTrigger, TabsContent } from '@/components/ui/tabs'
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'
-import { FileCode2, Search, Info, Zap, BadgeCheck, BadgeAlert, Plus, Download } from 'lucide-react'
+import { FileCode2, Search, Info, Zap, BadgeCheck, BadgeAlert, Plus, Download, Trash2 } from 'lucide-react'
import { Transform, Flow, GraphNode } from '@/types'
import { useLaunchFlow } from '@/hooks/use-launch-flow'
import { useLaunchTransform } from '@/hooks/use-launch-transform'
@@ -16,8 +16,10 @@ import { capitalizeFirstLetter } from '@/lib/utils'
import BaseContextMenu from '@/components/xyflow/context-menu'
import { useGraphStore } from '@/stores/graph-store'
import { CopyButton } from '../copy'
-import { Badge } from '../ui/badge'
import { useGraphSettingsStore } from '@/stores/graph-settings-store'
+import { useConfirm } from '../use-confirm-dialog'
+import { toast } from 'sonner'
+import { sketchService } from '@/api/sketch-service'
interface GraphContextMenuProps {
nodes: GraphNode[]
@@ -56,6 +58,9 @@ export default function BackgroundContextMenu({
const { launchTransform } = useLaunchTransform(false)
const selectedNodes = useGraphStore(s => s.selectedNodes)
const selectedNodeIds = selectedNodes.map((n) => n.id)
+ const { confirm } = useConfirm()
+ const removeNodes = useGraphStore((s) => s.removeNodes)
+ const clearSelectedNodes = useGraphStore((s) => s.clearSelectedNodes)
let sharedType = selectedNodes?.[0]?.data?.type
const isSameType = selectedNodes.every((n) => n.data.type === sharedType)
@@ -104,6 +109,33 @@ export default function BackgroundContextMenu({
setMenu(null)
}
+ const handleDeleteNodes = useCallback(async () => {
+ if (!selectedNodes.length || !sketchId) return
+ if (
+ !(await confirm({
+ title: `You are about to delete ${selectedNodes.length} node(s).`,
+ message: 'The action is irreversible.'
+ }))
+ )
+ return
+
+ toast.promise(
+ (async () => {
+ removeNodes(selectedNodes.map((n) => n.id))
+ clearSelectedNodes()
+ return sketchService.deleteNodes(
+ sketchId as string,
+ JSON.stringify({ nodeIds: selectedNodes.map((n) => n.id) })
+ )
+ })(),
+ {
+ loading: `Deleting ${selectedNodes.length} node(s)...`,
+ success: 'Nodes deleted successfully.',
+ error: 'Failed to delete selectedNodes.'
+ }
+ )
+ }, [selectedNodes, confirm, removeNodes, clearSelectedNodes, sketchId])
+
return (
<BaseContextMenu
top={top}
@@ -120,8 +152,28 @@ export default function BackgroundContextMenu({
{/* Header with title and action buttons */}
<div className="px-3 py-2 border-b gap-1 border-border flex items-center justify-between flex-shrink-0">
<div className="flex text-xs items-center gap-1 truncate">
- <span className="block truncate">{selectedNodes.length} selected</span> -{' '}
- <span className="block">{sharedType}</span>
+ <span className="block truncate">{selectedNodes.length} selected</span>
+ {isSameType && <span className="block">-{' '}{sharedType}</span>}
+ </div>
+ <div className='grow' />
+ <div>
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <div>
+ <Button
+ variant="ghost"
+ size="sm"
+ className="h-6 p-0 hover:bg-muted opacity-70 hover:opacity-100 text-destructive hover:text-destructive"
+ onClick={handleDeleteNodes}
+ >
+ <Trash2 className="h-3 w-3" strokeWidth={1.5} /> Delete {selectedNodeIds.length}
+ </Button>
+ </div>
+ </TooltipTrigger>
+ <TooltipContent>
+ <p>Delete {selectedNodeIds.length} node(s)</p>
+ </TooltipContent>
+ </Tooltip>
</div>
</div>
diff --git a/flowsint-app/src/components/graphs/graph-viewer.tsx b/flowsint-app/src/components/graphs/graph-viewer.tsx
index 69f3ea98..d5c9faac 100644
--- a/flowsint-app/src/components/graphs/graph-viewer.tsx
+++ b/flowsint-app/src/components/graphs/graph-viewer.tsx
@@ -164,6 +164,7 @@ const GraphViewer: React.FC<GraphViewerProps> = ({
// Store selectors
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)
const { theme } = useTheme()
@@ -346,6 +347,9 @@ const GraphViewer: React.FC<GraphViewerProps> = ({
if (!graphData || !graphData.nodes) {
throw new Error('No nodes available in graph')
}
+
+ // Save the layout type in store for auto-regenerate after refetch
+ setCurrentLayoutType(layoutType)
setIsRegeneratingLayout(true)
// Run layout calculation in worker (non-blocking)
@@ -371,7 +375,7 @@ const GraphViewer: React.FC<GraphViewerProps> = ({
setIsRegeneratingLayout(false)
}
})
- }, [graphData, applyLayout])
+ }, [graphData, applyLayout, setCurrentLayoutType])
// Optimized graph initialization callback
const initializeGraph = useCallback(
diff --git a/flowsint-app/src/components/graphs/items-panel.tsx b/flowsint-app/src/components/graphs/items-panel.tsx
index abc331c3..f3b6a9da 100644
--- a/flowsint-app/src/components/graphs/items-panel.tsx
+++ b/flowsint-app/src/components/graphs/items-panel.tsx
@@ -82,7 +82,7 @@ export const ItemsPanel = memo(function LeftPanel() {
</div>
</div>
<div className='my-1'>
- <Button onClick={handleOpenImportModal} className="w-full" variant={"outline"}><Download /> Import entities</Button>
+ <Button onClick={handleOpenImportModal} className="w-full shadow-none" variant={"outline"}><Download /> Import entities</Button>
</div>
<div className="flex flex-col gap-3">
{isLoading ? (
diff --git a/flowsint-app/src/components/graphs/node-context-menu.tsx b/flowsint-app/src/components/graphs/node-context-menu.tsx
index 90a8b380..fbb9131f 100644
--- a/flowsint-app/src/components/graphs/node-context-menu.tsx
+++ b/flowsint-app/src/components/graphs/node-context-menu.tsx
@@ -289,7 +289,7 @@ type SubActionsProps = {
}
const SubActions = memo(({ node, handleOpenNodeDetails }: SubActionsProps) => {
return (
- <div className='flex gap-1'>
+ <div className='flex'>
<CopyButton size={"icon"} content={node?.data?.label} />
<Button onClick={handleOpenNodeDetails} size={'icon'} className='h-7 w-7' variant="ghost"><SquareArrowOutUpRight className='!h-3.5 !w-3.5 opacity-50' /></Button>
</div>)
diff --git a/flowsint-app/src/components/graphs/settings.tsx b/flowsint-app/src/components/graphs/settings.tsx
index b8e60cee..9eaaa7b6 100644
--- a/flowsint-app/src/components/graphs/settings.tsx
+++ b/flowsint-app/src/components/graphs/settings.tsx
@@ -278,10 +278,10 @@ function NodeColorsSection() {
</div>
<div className="border-b flex items-center gap-2 pb-4">
- <Button variant="outline" size="sm" onClick={handleReset} className="grow">
+ <Button variant="outline" size="sm" onClick={handleReset} className="grow shadow-none">
Reset to default colors
</Button>
- <Button variant="outline" size="sm" onClick={handleRandomizeColors} className="grow">
+ <Button variant="outline" size="sm" onClick={handleRandomizeColors} className="grow shadow-none">
Randomize
</Button>
</div>
@@ -382,14 +382,14 @@ function DynamicSection({ categoryId, category, title, description }: DynamicSec
applyPreset(presetName)
toast.success('Settings saved. Re-apply a layout to see changes.')
}}
- className="justify-start"
+ className="justify-start shadow-none"
>
{presetName}
</Button>
))}
</div>
<div className="mt-4">
- <Button variant="outline" size="sm" onClick={() => resetSettings()} className="w-full">
+ <Button variant="outline" size="sm" onClick={() => resetSettings()} className="w-full shadow-none">
Reset to defaults
</Button>
</div>
@@ -547,7 +547,7 @@ export default function GlobalSettings() {
return (
<div className="space-y-6">
<div className="space-y-1">
- <h3 className="text-lg font-semibold text-foreground">General Information</h3>
+ <h3 className="text-lg font-semibold text-foreground">Sketch information</h3>
<p className="text-sm text-muted-foreground">
Configure the basic details and metadata for your sketch.
</p>
@@ -587,7 +587,7 @@ export default function GlobalSettings() {
<div className="flex gap-3 pt-6">
<SheetClose asChild>
- <Button variant="outline" type="button" className="flex-1">
+ <Button variant="outline" type="button" className="flex-1 shadow-none">
Cancel
</Button>
</SheetClose>
@@ -595,7 +595,7 @@ export default function GlobalSettings() {
type="submit"
disabled={updateMutation.isPending}
onClick={handleSubmit}
- className="flex-1"
+ className="flex-1 shadow-none"
>
{updateMutation.isPending ? 'Saving...' : 'Save changes'}
</Button>
@@ -734,7 +734,7 @@ function TextareaSetting({
onChange={(e) => onValueChange(e.target.value)}
placeholder={placeholder}
rows={rows}
- className="resize-none"
+ className="resize-none shadow-none"
/>
</SettingItem>
)
diff --git a/flowsint-app/src/components/graphs/toolbar.tsx b/flowsint-app/src/components/graphs/toolbar.tsx
index fdef1431..e7d42fc4 100644
--- a/flowsint-app/src/components/graphs/toolbar.tsx
+++ b/flowsint-app/src/components/graphs/toolbar.tsx
@@ -24,7 +24,6 @@ import { Separator } from '../ui/separator'
import { ViewToggle } from './view-toggle'
import { NetworkIcon } from '../icons/network'
import { useKeyboard } from '@/hooks/use-keyboard'
-import { isMac } from '@/lib/utils'
// Tooltip wrapper component to avoid repetition
export const ToolbarButton = memo(function ToolbarButton({
diff --git a/flowsint-app/src/components/map/map-panel.tsx b/flowsint-app/src/components/map/map-panel.tsx
index 069d6854..051eb6ff 100644
--- a/flowsint-app/src/components/map/map-panel.tsx
+++ b/flowsint-app/src/components/map/map-panel.tsx
@@ -12,7 +12,7 @@ const MapPanel = () => {
label: node.data.label || ''
}))
return (
- <div className="w-full grow h-full z-10">
+ <div className="w-full grow h-full">
<MapFromAddress locations={locationNodes as LocationPoint[]} />
</div>
)
diff --git a/flowsint-app/src/components/map/map.tsx b/flowsint-app/src/components/map/map.tsx
index 9bc0cac5..4d3ba3ac 100644
--- a/flowsint-app/src/components/map/map.tsx
+++ b/flowsint-app/src/components/map/map.tsx
@@ -1,5 +1,6 @@
import React from 'react'
import { useQuery } from '@tanstack/react-query'
+// @ts-ignore
import L from 'leaflet'
import 'leaflet/dist/leaflet.css'
import { useTheme } from '../theme-provider'
@@ -187,7 +188,7 @@ export const MapFromAddress: React.FC<MapFromAddressProps> = ({
// Don't render if we don't have any valid coordinates
if (validCoordinates.length === 0) {
return (
- <div className="w-full pt-18 flex items-center justify-center h-full">
+ <div className="w-full flex items-center justify-center h-full">
<div className="text-center space-y-4">
<MapPin className="mx-auto h-12 w-12 text-muted-foreground" />
<div>
@@ -199,5 +200,5 @@ export const MapFromAddress: React.FC<MapFromAddressProps> = ({
)
}
- return <div id={mapId} style={{ minHeight: height, height: '100%', width: '100%' }} />
+ return <div id={mapId} style={{ minHeight: height, height: '100%', width: '100%', zIndex: 0 }} />
}
diff --git a/flowsint-app/src/components/table/relationships-view.tsx b/flowsint-app/src/components/table/relationships-view.tsx
index 923e91ca..f3226e82 100644
--- a/flowsint-app/src/components/table/relationships-view.tsx
+++ b/flowsint-app/src/components/table/relationships-view.tsx
@@ -164,7 +164,7 @@ export default function RelationshipsTable() {
if (isLoading) {
return (
- <div className="w-full grow h-full flex flex-col pt-18 p-4 px-6">
+ <div className="w-full grow h-full flex flex-col p-4 px-6">
{/* Header with stats */}
<div className="flex items-center justify-between">
<div className="space-y-1">
diff --git a/flowsint-app/src/components/ui/button.tsx b/flowsint-app/src/components/ui/button.tsx
index 40e6a245..1f4de9b3 100644
--- a/flowsint-app/src/components/ui/button.tsx
+++ b/flowsint-app/src/components/ui/button.tsx
@@ -9,12 +9,12 @@ const buttonVariants = cva(
{
variants: {
variant: {
- default: 'bg-primary text-white shadow-xs hover:bg-primary/90',
+ default: 'bg-primary text-white hover:bg-primary/90',
destructive:
- 'bg-destructive text-white shadow-xs hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60',
+ 'bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60',
outline:
- 'border shadow-xs hover:bg-accent hover:text-accent-foreground bg-background/80 hover:bg-background/90 backdrop-blur-sm',
- secondary: 'bg-secondary text-secondary-foreground shadow-xs hover:bg-secondary/80',
+ 'border hover:bg-accent hover:text-accent-foreground bg-background/80 hover:bg-background/90 backdrop-blur-sm',
+ secondary: 'bg-secondary text-secondary-foreground hover:bg-secondary/80',
ghost: 'hover:bg-muted hover:text-accent-foreground dark:hover:bg-muted',
link: 'text-primary underline-offset-4 hover:underline'
},
diff --git a/flowsint-app/src/components/ui/dialog.tsx b/flowsint-app/src/components/ui/dialog.tsx
index d9992d13..661bb477 100644
--- a/flowsint-app/src/components/ui/dialog.tsx
+++ b/flowsint-app/src/components/ui/dialog.tsx
@@ -50,7 +50,7 @@ function DialogContent({
<DialogPrimitive.Content
data-slot="dialog-content"
className={cn(
- 'bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg',
+ 'bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-md border p-6 shadow-lg duration-200 sm:max-w-lg',
className
)}
{...props}
diff --git a/flowsint-app/src/hooks/use-events.ts b/flowsint-app/src/hooks/use-events.ts
index 96951278..d9f0e8e7 100644
--- a/flowsint-app/src/hooks/use-events.ts
+++ b/flowsint-app/src/hooks/use-events.ts
@@ -12,6 +12,8 @@ export 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 { data: previousLogs = [], refetch } = useQuery({
queryKey: queryKeys.logs.bySketch(sketch_id as string),
@@ -41,7 +43,15 @@ export function useEvents(sketch_id: string | undefined) {
const raw = JSON.parse(e.data) as any
const event = JSON.parse(raw.data) as Event
if (event.type === EventLevel.COMPLETED) {
+ // Refetch graph data
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) {
@@ -64,7 +74,7 @@ export function useEvents(sketch_id: string | undefined) {
return () => {
eventSource.close()
}
- }, [sketch_id, refetchGraph])
+ }, [sketch_id, refetchGraph, currentLayoutType, regenerateLayout])
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.ts
index 0551601a..e2a60c18 100644
--- a/flowsint-app/src/stores/graph-controls-store.ts
+++ b/flowsint-app/src/stores/graph-controls-store.ts
@@ -2,17 +2,20 @@ import { create } from 'zustand'
import { persist } from 'zustand/middleware'
type ViewType = 'graph' | 'table' | 'map' | 'relationships'
+type LayoutType = 'force' | 'hierarchy'
type GraphControlsStore = {
view: ViewType
isLassoActive: boolean
+ currentLayoutType: LayoutType
zoomToFit: () => void
zoomIn: () => void
zoomOut: () => void
onLayout: (layout: any) => void
setActions: (actions: Partial<GraphControlsStore>) => void
refetchGraph: () => void
- regenerateLayout: (layoutType: 'force' | 'hierarchy') => void
+ regenerateLayout: (layoutType: LayoutType) => void
+ setCurrentLayoutType: (layoutType: LayoutType) => void
setView: (view: 'graph' | 'table' | 'map' | 'relationships') => void
setIsLassoActive: (active: boolean) => void
}
@@ -22,6 +25,7 @@ export const useGraphControls = create<GraphControlsStore>()(
(set) => ({
view: 'graph',
isLassoActive: false,
+ currentLayoutType: 'force',
zoomToFit: () => { },
zoomIn: () => { },
zoomOut: () => { },
@@ -29,12 +33,16 @@ export const useGraphControls = create<GraphControlsStore>()(
setActions: (actions) => set(actions),
refetchGraph: () => { },
regenerateLayout: () => { },
+ setCurrentLayoutType: (layoutType) => set({ currentLayoutType: layoutType }),
setView: (view) => set({ view }),
setIsLassoActive: (active) => set({ isLassoActive: active })
}),
{
name: 'graph-controls-storage',
- partialize: (state) => ({ view: state.view })
+ partialize: (state) => ({
+ view: state.view,
+ currentLayoutType: state.currentLayoutType
+ })
}
)
)
diff --git a/flowsint-app/src/stores/graph-settings-store.ts b/flowsint-app/src/stores/graph-settings-store.ts
index 129b3d63..d72dd5c1 100644
--- a/flowsint-app/src/stores/graph-settings-store.ts
+++ b/flowsint-app/src/stores/graph-settings-store.ts
@@ -91,9 +91,9 @@ const DEFAULT_SETTINGS = {
},
linkDirectionalArrowLength: {
type: 'number',
- value: 3,
+ value: 1,
min: 1,
- max: 100,
+ max: 10,
step: 0.1,
description: 'Length of the arrow heads that indicate link direction'
},
@@ -258,7 +258,7 @@ export const useGraphSettingsStore = create<GraphGeneralSettingsStore>()(
(set, get) => ({
// Settings state
settings: DEFAULT_SETTINGS,
- currentPreset: 'Balanced Layout',
+ currentPreset: 'High Energy',
forceSettings: DEFAULT_SETTINGS.graph,
// UI State
settingsModalOpen: false,