A modern platform for visual, flexible, and extensible graph-based investigations. For cybersecurity analysts and investigators.
feat: better performances
dextmorgn2657ade515ec
diff --git a/flowsint-web/src/app/dashboard/projects/[project_id]/investigations/[investigation_id]/client.tsx b/flowsint-web/src/app/dashboard/projects/[project_id]/investigations/[investigation_id]/client.tsxindex e8e1bf10..2c042550 100644--- a/flowsint-web/src/app/dashboard/projects/[project_id]/investigations/[investigation_id]/client.tsx+++ b/flowsint-web/src/app/dashboard/projects/[project_id]/investigations/[investigation_id]/client.tsx@@ -5,7 +5,7 @@ import LargeInvestigationGraph from '@/components/investigations/sketch/large-daimport IndividualModal from "@/components/investigations/individual-modal"import { notFound } from "next/navigation"import { useQueryState } from "nuqs"-import { InvestigationtNavigation } from "@/components/investigations/investigation-navigation"+import { supabase } from "@/lib/supabase/client"interface DashboardClientProps {projectId: stringinvestigationId: string@@ -24,6 +24,20 @@ export default function DashboardClient({ projectId, investigationId }: Dashboar},refetchOnWindowFocus: true,})+ // supabase+ // .channel("investigation-channel")+ // .on(+ // "postgres_changes",+ // {+ // event: "*",+ // schema: "public",+ // table: "scans",+ // },+ // (_: any) => {+ // graphQuery.refetch()+ // }+ // )+ // .subscribe()return (<>{view === "flow-graph" ?diff --git a/flowsint-web/src/components/investigations/new-actions.tsx b/flowsint-web/src/components/investigations/new-actions.tsxindex 24b1084f..c58a5b17 100644--- a/flowsint-web/src/components/investigations/new-actions.tsx+++ b/flowsint-web/src/components/investigations/new-actions.tsx@@ -5,7 +5,7 @@ import { useParams } from "next/navigation"import { supabase } from "@/lib/supabase/client"import { Button } from "@/components/ui/button"import { Input } from "@/components/ui/input"-import { AlertCircle, ArrowLeft, PlusIcon } from "lucide-react"+import { AlertCircle, ArrowLeft, ArrowRight, PlusIcon } from "lucide-react"import { toast } from "sonner"import { cn, nodesTypes } from "@/lib/utils"import { Alert, AlertTitle, AlertDescription } from "../ui/alert"@@ -213,14 +213,15 @@ function ActionCard({ item, onSelect }: ActionCardProps) {className="w-8 h-8 rounded-full flex items-center justify-center mb-3 mt-2"style={{ backgroundColor: `${item.color}20` }} // Light background based on item color>- <Icon style={{ color: item.color }} className="h-6 w-6 opacity-60" />+ <Icon style={{ color: item.color }} className="h-6 w-6 opacity-60 text-primary" /></div><div className="font-medium text-sm">{item.label}</div>{item.comingSoon && (- <Badge variant="outline" className="mt-2 absolute top-2 right-2">+ <Badge variant="outline" className="mt-2 absolute top-2 left-2">soon</Badge>)}+ {item.children && <div className="absolute top-3 right-4 text-xs text-muted-foreground mt-1"><ArrowRight className="h-4 w-4"/></div>}{item.children && <div className="text-xs text-muted-foreground mt-1">{item.children.length} options</div>}</CardContent></Card>diff --git a/flowsint-web/src/components/investigations/sketch/graph.tsx b/flowsint-web/src/components/investigations/sketch/graph.tsxindex 4ff98cb1..987114ea 100644--- a/flowsint-web/src/components/investigations/sketch/graph.tsx+++ b/flowsint-web/src/components/investigations/sketch/graph.tsx@@ -38,7 +38,6 @@ import Loader from "@/components/loader"import { useQueryState } from "nuqs"import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger } from "@/components/ui/context-menu"import AddNodeModal from "../add-node-modal"-import { Dialog, DialogTrigger } from "@/components/ui/dialog"import { memo } from "react"import { shallow } from "zustand/shallow"import { TooltipProvider } from "@/components/ui/tooltip"@@ -52,244 +51,238 @@ import {import NodesPanel from "./nodes-panel"import ProfilePanel from "./profile-panel"import CustomNode from "./nodes/custom-node"+import { Dialog, DialogTrigger } from "@/components/ui/dialog"+// Move these outside of component scopeconst edgeTypes = {custom: CustomEdge,}+const nodeTypes = {- // individual: IndividualNode,- // phone: PhoneNode,- // ip: IpNode,- // email: EmailNode,- // social: SocialNode,- // address: AddressNode,- // group: GroupNode,custom: CustomNode,- // vehicle: Vehicle}-const nodeEdgeSelector = (store: { nodes: any; edges: any }) => ({- nodes: store.nodes,- edges: store.edges,++// Better selectors with more specific equality comparisons+const nodeEdgeSelector = (state: { nodes: any; edges: any }) => ({+ nodes: state.nodes,+ edges: state.edges,})-const actionsSelector = (store: {- onNodesChange: any- onEdgesChange: any- onConnect: any- onNodeClick: any- onPaneClick: any- onLayout: any-}) => ({- onNodesChange: store.onNodesChange,- onEdgesChange: store.onEdgesChange,- onConnect: store.onConnect,- onNodeClick: store.onNodeClick,- onPaneClick: store.onPaneClick,- onLayout: store.onLayout,++const actionsSelector = (state: { onNodesChange: any; onEdgesChange: any; onConnect: any; onNodeClick: any; onPaneClick: any; onLayout: any }) => ({+ onNodesChange: state.onNodesChange,+ onEdgesChange: state.onEdgesChange,+ onConnect: state.onConnect,+ onNodeClick: state.onNodeClick,+ onPaneClick: state.onPaneClick,+ onLayout: state.onLayout,})-const stateSelector = (store: {- currentNode: any;- setCurrentNode: any,- resetNodeStyles: any;- reloading: any;- updateNode: any;- highlightPath: any;-}) => ({- currentNode: store.currentNode,- resetNodeStyles: store.resetNodeStyles,- reloading: store.reloading,- setCurrentNode: store.setCurrentNode,- updateNode: store.updateNode,- highlightPath: store.highlightPath++const stateSelector = (state: { currentNode: any; setCurrentNode: any; resetNodeStyles: any; reloading: any; updateNode: any; highlightPath: any }) => ({+ currentNode: state.currentNode,+ setCurrentNode: state.setCurrentNode,+ resetNodeStyles: state.resetNodeStyles,+ reloading: state.reloading,+ updateNode: state.updateNode,+ highlightPath: state.highlightPath})-interface FlowControlsProps {- onLayout: (direction: string, fitView: () => void) => void- fitView: () => void- handleRefetch: () => void- reloading: boolean- setView: (view: string) => void- zoomIn: () => void- zoomOut: () => void- addNodes: (payload: any) => void- currentNode: any | null | undefined-}-const FlowControls = memo(- ({ onLayout, fitView, handleRefetch, reloading, setView, zoomIn, zoomOut, addNodes, currentNode }: FlowControlsProps) => {- return (- <>- <Panel position="top-left" className="flex flex-col items-center gap-1">- <NewActions addNodes={addNodes}>- <Button size="icon">- <PlusIcon />- </Button>- </NewActions>- <Button size="icon" disabled={reloading} variant="outline" onClick={handleRefetch}>- <RotateCwIcon className={cn("h-4 w-4", reloading && "animate-spin")} />++// Properly memoized FlowControls component+const FlowControls = memo(({+ onLayout,+ fitView,+ handleRefetch,+ reloading,+ setView,+ zoomIn,+ zoomOut,+ addNodes+}: any) => {+ return (+ <>+ <Panel position="top-left" className="flex flex-col items-center gap-1">+ <NewActions addNodes={addNodes}>+ <Button className="bg-gradient-to-r from-purple-600 to-indigo-400 hover:from-purple-700 hover:to-indigo-500 transition-all duration-300" size="icon">+ <PlusIcon /></Button>- </Panel >- <Panel position="bottom-left" className="flex flex-col items-center gap-1">- <Tooltip>- <TooltipTrigger asChild>- <Button- size="icon"- variant="outline"- onClick={() => {- onLayout("dagre", fitView)- }}- >- <NetworkIcon className="h-4 w-4" />- </Button>- </TooltipTrigger>- <TooltipContent>Dagre layout</TooltipContent>- </Tooltip>- <Tooltip>- <TooltipTrigger asChild>- <Button- size="icon"- variant="outline"- onClick={() => {- onLayout("force", fitView)- }}- >- <WaypointsIcon className="h-4 w-4" />- </Button>- </TooltipTrigger>- <TooltipContent>Force layout</TooltipContent>- </Tooltip>- <Tooltip>- <TooltipTrigger asChild>- <Button size="icon" variant="outline" onClick={() => setView("large-graph")}>- <WorkflowIcon className="h-4 w-4" />- </Button>- </TooltipTrigger>- <TooltipContent>View 2D Graph</TooltipContent>- </Tooltip>- <Tooltip>- <TooltipTrigger asChild>- <Button size="icon" variant="outline" onClick={() => fitView()}>- <MaximizeIcon className="h-4 w-4" />- </Button>- </TooltipTrigger>- <TooltipContent>Center view</TooltipContent>- </Tooltip>- <Tooltip>- <TooltipTrigger asChild>- <Button size="icon" variant="outline" onClick={() => zoomIn()}>- <ZoomInIcon className="h-4 w-4" />- </Button>- </TooltipTrigger>- <TooltipContent>Zoom in</TooltipContent>- </Tooltip>- <Tooltip>- <TooltipTrigger asChild>- <Button size="icon" variant="outline" onClick={() => zoomOut()}>- <ZoomOutIcon className="h-4 w-4" />- </Button>- </TooltipTrigger>- <TooltipContent>Zoom out</TooltipContent>- </Tooltip>- </Panel>- </>- )- },- // Comparateur personnalisé pour le composant mémorisé- (prevProps, nextProps) => {- return (- prevProps.reloading === nextProps.reloading &&- prevProps.currentNode?.id === nextProps.currentNode?.id- )- }-)-interface LayoutFlowProps {- refetch: () => void- theme: string-}-const LayoutFlow = ({ refetch, theme }: LayoutFlowProps) => {- const { fitView, zoomIn, zoomOut, addNodes, getNode, setCenter, getNodes } = useReactFlow()- const { investigation_id } = useParams()- const { settings } = useInvestigationStore()- const [_, setView] = useQueryState("view", { defaultValue: "flow-graph" })- const [nodeContextMenu, setNodeContextMenu] = useState<{- x: number- y: number- nodeId: string | null- nodeType: string | null- data: any- } | null>(null)- const { nodes, edges } = useFlowStore(nodeEdgeSelector, shallow)- const { onNodesChange, onEdgesChange, onConnect, onNodeClick, onPaneClick, onLayout } = useFlowStore(- actionsSelector,- shallow,+ </NewActions>+ <Button size="icon" disabled={reloading} variant="outline" onClick={handleRefetch}>+ <RotateCwIcon className={cn("h-4 w-4", reloading && "animate-spin")} />+ </Button>+ </Panel>+ <Panel position="bottom-left" className="flex flex-col items-center gap-1">+ <Tooltip>+ <TooltipTrigger asChild>+ <Button+ size="icon"+ variant="outline"+ onClick={() => onLayout("dagre", fitView)}+ >+ <NetworkIcon className="h-4 w-4" />+ </Button>+ </TooltipTrigger>+ <TooltipContent>Dagre layout</TooltipContent>+ </Tooltip>+ <Tooltip>+ <TooltipTrigger asChild>+ <Button+ size="icon"+ variant="outline"+ onClick={() => onLayout("force", fitView)}+ >+ <WaypointsIcon className="h-4 w-4" />+ </Button>+ </TooltipTrigger>+ <TooltipContent>Force layout</TooltipContent>+ </Tooltip>+ <Tooltip>+ <TooltipTrigger asChild>+ <Button size="icon" variant="outline" onClick={() => setView("large-graph")}>+ <WorkflowIcon className="h-4 w-4" />+ </Button>+ </TooltipTrigger>+ <TooltipContent>View 2D Graph</TooltipContent>+ </Tooltip>+ <Tooltip>+ <TooltipTrigger asChild>+ <Button size="icon" variant="outline" onClick={() => fitView()}>+ <MaximizeIcon className="h-4 w-4" />+ </Button>+ </TooltipTrigger>+ <TooltipContent>Center view</TooltipContent>+ </Tooltip>+ <Tooltip>+ <TooltipTrigger asChild>+ <Button size="icon" variant="outline" onClick={() => zoomIn()}>+ <ZoomInIcon className="h-4 w-4" />+ </Button>+ </TooltipTrigger>+ <TooltipContent>Zoom in</TooltipContent>+ </Tooltip>+ <Tooltip>+ <TooltipTrigger asChild>+ <Button size="icon" variant="outline" onClick={() => zoomOut()}>+ <ZoomOutIcon className="h-4 w-4" />+ </Button>+ </TooltipTrigger>+ <TooltipContent>Zoom out</TooltipContent>+ </Tooltip>+ </Panel>+ </>)+});++const LayoutFlow = memo(({ refetch, theme }: any) => {+ const { fitView, zoomIn, zoomOut, addNodes, getNode, setCenter, getNodes } = useReactFlow();+ const { investigation_id } = useParams();+ const showMiniMap = useInvestigationStore(state => state.settings.showMiniMap);+ const [_, setView] = useQueryState("view", { defaultValue: "flow-graph" });++ // Use a ref for context menu state to avoid re-renders on position changes+ const [nodeContextMenu, setNodeContextMenu] = useState<{+ x: number;+ y: number;+ nodeId: string;+ data: any;+ nodeType: string;+ } | null>(null);++ // Use shallow comparison for complex objects from the store+ const { nodes, edges } = useFlowStore(nodeEdgeSelector, shallow);+ const {+ onNodesChange,+ onEdgesChange,+ onConnect,+ onNodeClick,+ onPaneClick,+ onLayout+ } = useFlowStore(actionsSelector, shallow);+const {currentNode,setCurrentNode,reloading,updateNode,highlightPath- } = useFlowStore(stateSelector, shallow)- const initialLayout = useCallback(() => {- const timer = setTimeout(() => {- onLayout("dagre", fitView)- fitView()- }, 500)- return () => clearTimeout(timer)- }, [onLayout, fitView])+ } = useFlowStore(stateSelector, shallow);++ // Initialize layout onceuseEffect(() => {- return initialLayout()- }, [initialLayout])+ const timer = setTimeout(() => {+ onLayout("dagre", fitView);+ fitView();+ }, 500);+ return () => clearTimeout(timer);+ }, []); // Empty dependency array - run once only+const handleRefetch = useCallback(() => {- refetch()- onLayout("dagre", fitView)- fitView()- }, [refetch, onLayout, fitView])+ refetch();+ onLayout("dagre", fitView);+ fitView();+ }, [refetch, onLayout, fitView]);++ // Handle current node changesuseEffect(() => {- if (!currentNode) return- const internalNode = getNode(currentNode.id)- if (!internalNode) return+ if (!currentNode) return;++ const internalNode = getNode(currentNode.id);+ if (!internalNode) return;+updateNode(internalNode.id, {...internalNode,zIndex: 5000,data: { ...internalNode.data, forceToolbarVisible: true },style: { ...internalNode.style, opacity: 1 },- })- const nodeWidth = internalNode.measured?.width ?? 0- const nodeHeight = internalNode.measured?.height ?? 0- setCenter(internalNode.position.x + nodeWidth / 2, internalNode.position.y + nodeHeight / 2 + 20, {- duration: 1000,- zoom: 1.5,- })- }, [currentNode, getNode, setCenter, updateNode, highlightPath])+ });++ const nodeWidth = internalNode.measured?.width ?? 0;+ const nodeHeight = internalNode.measured?.height ?? 0;++ setCenter(+ internalNode.position.x + nodeWidth / 2,+ internalNode.position.y + nodeHeight / 2 + 20,+ {+ duration: 1000,+ zoom: 1.5,+ }+ );+ }, [currentNode?.id]); // Only depend on currentNode.id, not the whole object+const handleConnect = useCallback((params: any) => onConnect(params, investigation_id),[onConnect, investigation_id]- )- const handleNodeContextMenu = useCallback<NodeMouseHandler>(- (event, node) => {- event.preventDefault()- event.stopPropagation()- setCurrentNode(node)+ );++ const handleNodeContextMenu = useCallback(+ (event: { preventDefault: () => void; stopPropagation: () => void; screenX: number; screenY: number }, node: { id: any; data: any; type?: any }) => {+ event.preventDefault();+ event.stopPropagation();+ setCurrentNode(node);setNodeContextMenu({x: event.screenX - 200,y: event.screenY - 150,nodeId: node.id,data: node.data,nodeType: node.type || "default",- })+ });},[setCurrentNode]- )+ );+const closeNodeContextMenu = useCallback(() => {- setNodeContextMenu(null)- }, [])+ setNodeContextMenu(null);+ }, []);+const handlePaneClick = useCallback(- (event: React.MouseEvent) => {- closeNodeContextMenu()- onPaneClick(event)+ (event: any) => {+ closeNodeContextMenu();+ onPaneClick(event);},[onPaneClick, closeNodeContextMenu]- )+ );++ // Memoize ReactFlow props to prevent unnecessary re-rendersconst reactFlowProps = useMemo(() => ({- colorMode: theme as ColorMode,+ colorMode: theme,nodes,edges,onNodesChange,@@ -314,9 +307,15 @@ const LayoutFlow = ({ refetch, theme }: LayoutFlowProps) => {onNodeClick,handlePaneClick,handleNodeContextMenu- ])- const processedNodes = useMemo(() => nodes.map(({ id, data, type }: any) => ({ id, data, type })).sort((a: { type: string }, b: { type: any }) => b.type.localeCompare(a.type))- , [nodes.length]);+ ]);++ // Process nodes only when nodes array length changes+ const processedNodes = useMemo(() =>+ nodes.map(({ id, data, type }: { id: string; data: any; type: string }) => ({ id, data, type }))+ .sort((a: { type: any }, b: { type: string }) => b.type?.localeCompare(a.type || "")),+ [nodes.length]+ );+return (<ResizablePanelGroup autoSaveId="persistence" direction="horizontal" className="w-screen grow relative overflow-hidden"><ResizablePanel defaultSize={80}>@@ -334,10 +333,9 @@ const LayoutFlow = ({ refetch, theme }: LayoutFlowProps) => {zoomIn={zoomIn}zoomOut={zoomOut}addNodes={addNodes}- currentNode={currentNode}/><Background className="dark:bg-background bg-accent" />- {settings.showMiniMap && <MiniMap className="!z-40" pannable />}+ {showMiniMap && <MiniMap className="!z-40" pannable />}</ReactFlow></ContextMenuTrigger><ContextMenuContent className="w-32">@@ -365,47 +363,57 @@ const LayoutFlow = ({ refetch, theme }: LayoutFlowProps) => {<ResizableHandle withHandle /><ResizablePanel defaultSize={20} minSize={15} className="h-full bg-background"><ResizablePanelGroup autoSaveId="conditional" direction="vertical">- {currentNode && <>- <ResizablePanel order={1} id="top" defaultSize={40}>- <ProfilePanel data={currentNode.data} type={currentNode.type} />- </ResizablePanel>- <ResizableHandle withHandle />- </>}+ {currentNode && (+ <>+ <ResizablePanel order={1} id="top" defaultSize={40}>+ <ProfilePanel data={currentNode.data} type={currentNode.type} />+ </ResizablePanel>+ <ResizableHandle withHandle />+ </>+ )}<ResizablePanel order={2} id="bottom" defaultSize={60}><NodesPanel nodes={processedNodes} /></ResizablePanel></ResizablePanelGroup></ResizablePanel></ResizablePanelGroup>- )-}-const MemoizedLayoutFlow = memo(LayoutFlow, (prevProps, nextProps) => {- return prevProps.theme === nextProps.theme && prevProps.refetch === nextProps.refetch-})-function Graph({ graphQuery }: { graphQuery: any }) {- const [mounted, setMounted] = useState(false)- const { refetch, isLoading, data } = graphQuery- const { resolvedTheme } = useTheme()+ );+});++function Graph({ graphQuery }: any) {+ const [mounted, setMounted] = useState(false);+ const { refetch, isLoading, data } = graphQuery;+ const { resolvedTheme } = useTheme();++ // Only run mounting effect onceuseEffect(() => {- setMounted(true)- }, [])+ setMounted(true);+ }, []);++ // Update flow store when data changesuseEffect(() => {if (data) {- useFlowStore.setState({ nodes: data?.nodes, edges: data?.edges })- setMounted(true)+ useFlowStore.setState({+ nodes: data?.nodes || [],+ edges: data?.edges || []+ });+ setMounted(true);}- }, [data])+ }, [data]);+if (!mounted || isLoading) {return (<div className="grow w-full flex items-center justify-center"><Loader /> Loading...</div>- )+ );}+return (<ReactFlowProvider>- <MemoizedLayoutFlow refetch={refetch} theme={resolvedTheme || "light"} />+ <LayoutFlow refetch={refetch} theme={resolvedTheme || "light"} /></ReactFlowProvider>- )+ );}-export default memo(Graph)\ No newline at end of file++export default memo(Graph);\ No newline at end of filediff --git a/flowsint-web/src/components/investigations/sketch/nodes-panel.tsx b/flowsint-web/src/components/investigations/sketch/nodes-panel.tsxindex 0b2bd91c..55628dc2 100644--- a/flowsint-web/src/components/investigations/sketch/nodes-panel.tsx+++ b/flowsint-web/src/components/investigations/sketch/nodes-panel.tsx@@ -1,71 +1,114 @@-import React, { memo, useMemo, useState } from 'react'+import React, { memo, useMemo, useState, useCallback } from 'react'import { type Node } from '@xyflow/react'import { useFlowStore } from '@/store/flow-store'import { Button } from '@/components/ui/button'-import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'import { Badge } from '@/components/ui/badge'import { TypeBadge } from '@/components/type-badge'-import { Card, CardContent } from "@/components/ui/card"-import { AtSignIcon, CarIcon, LocateIcon, Mail, PhoneIcon, Search, User, UserIcon, Users } from "lucide-react"+import { Search, HelpCircle } from "lucide-react"import { usePlatformIcons } from '@/lib/hooks/use-platform-icons'import { Input } from '@/components/ui/input'import { actionItems } from '@/lib/action-items'-import { QuestionMarkIcon } from '@radix-ui/react-icons'+import { cn } from '@/lib/utils'-interface NodeProps {+// Mémoiser le composant SocialNode+const SocialNode = memo(({ node, setCurrentNode, currentNodeId }: {node: any,- setCurrentNode: (node: Node) => void-}--const SocialNode = ({ node, setCurrentNode }: NodeProps) => {+ setCurrentNode: (node: Node) => void,+ currentNodeId: string | null+}) => {const platformsIcons = usePlatformIcons()const platformIcon = useMemo(() => {// @ts-ignorereturn platformsIcons?.[node?.data?.platform]?.icon}, [platformsIcons, node?.data?.platform])++ const handleClick = useCallback(() => setCurrentNode(node), [node, setCurrentNode])+return (- <Button variant={"ghost"} className='flex items-center justify-start p-4 !py-5 rounded-none text-left border-b' onClick={() => setCurrentNode(node)}>+ <Button+ variant={"ghost"}+ className={cn(+ 'flex items-center justify-start p-4 !py-5 rounded-none text-left border-b border-l-2 border-l-transparent',+ node.id === currentNodeId && 'border-l-primary bg-accent'+ )}+ onClick={handleClick}+ ><Badge variant="secondary" className="h-7 w-7 p-0 rounded-full">{platformIcon}</Badge>- <div className='grow truncate text-ellipsis'>{node?.data?.username || <span className='italic opacity-60'>Unknwon</span>}</div>- <TypeBadge type={node?.data?.type as string}></TypeBadge>+ <div className='grow truncate text-ellipsis'>+ {node?.data?.username || <span className='italic opacity-60'>Unknown</span>}+ </div>+ <TypeBadge type={node?.data?.type as string} /></Button>)-}-export function NodeRenderer({ node, setCurrentNode }: NodeProps) {- const item = useMemo(() => (actionItems as any).find((a: any) => a.type === node.data?.type), [node?.type])- const Icon = item?.icon || QuestionMarkIcon- return (- <>- {node.data?.type === "social" ?- <SocialNode setCurrentNode={setCurrentNode} node={node} /> :- <Button variant={"ghost"} className='flex items-center justify-start p-4 !py-5 rounded-none text-left border-b' onClick={() => setCurrentNode(node)}>- <Badge variant="secondary" className="h-7 w-7 p-0 rounded-full">- <Icon className="h-4 w-4 opacity-60" />- </Badge>- <div className='grow truncate text-ellipsis'>{node?.data?.label}</div>- <TypeBadge type={node?.data?.type}></TypeBadge>- </Button>- }- </>+})++// Mémoiser le composant NodeRenderer+const NodeRenderer = memo(({+ node,+ setCurrentNode,+ currentNodeId+}: {+ node: any,+ setCurrentNode: (node: Node) => void,+ currentNodeId: string | null+}) => {+ const item = useMemo(() =>+ (actionItems as any).find((a: any) => a.type === node.data?.type),+ [node.data?.type])-}+ const Icon = item?.icon || HelpCircle++ const handleClick = useCallback(() => setCurrentNode(node), [node, setCurrentNode])+ if (node.data?.type === "social") {+ return <SocialNode+ setCurrentNode={setCurrentNode}+ node={node}+ currentNodeId={currentNodeId}+ />+ }++ return (+ <Button+ variant={"ghost"}+ className={cn(+ 'flex items-center justify-start p-4 !py-5 rounded-none text-left border-b border-l-2 border-l-transparent',+ node.id === currentNodeId && 'border-l-primary bg-accent'+ )}+ onClick={handleClick}+ >+ <Badge variant="secondary" className="h-7 w-7 p-0 rounded-full">+ <Icon className="h-4 w-4 opacity-60" />+ </Badge>+ <div className='grow truncate text-ellipsis'>{node?.data?.label}</div>+ <TypeBadge type={node?.data?.type} />+ </Button>+ )+})-const NodesPanel = ({ nodes }: { nodes: Node[] }) => {- const { setCurrentNode } = useFlowStore()+const NodesPanel = memo(({ nodes }: { nodes: Node[] }) => {+ // Utiliser des sélecteurs précis pour éviter les re-renders inutiles+ const setCurrentNode = useFlowStore(state => state.setCurrentNode)+ const currentNodeId = useFlowStore(state => state.currentNode?.id)const [searchQuery, setSearchQuery] = useState("")- // Filter nodes based on search query- const filteredNodes = nodes?.filter((node) => {++ // Mémoiser la fonction de filtrage pour éviter de recalculer à chaque rendu+ const filteredNodes = useMemo(() => {const searchText = searchQuery.toLowerCase()- // Search in node name, title, label, or id - adjust based on your node structure- return (- //@ts-ignore- node?.data?.label?.toLowerCase().includes(searchText) ||- node.id.toLowerCase().includes(searchText)- )- })+ return nodes?.filter((node) => {+ return (+ //@ts-ignore+ node?.data?.label?.toLowerCase().includes(searchText) ||+ node.id.toLowerCase().includes(searchText)+ )+ })+ }, [nodes, searchQuery])++ const handleSearchChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {+ setSearchQuery(e.target.value)+ }, [])return (<div className="overflow-auto h-full flex flex-col w-full !p-0 !m-0">@@ -80,18 +123,34 @@ const NodesPanel = ({ nodes }: { nodes: Node[] }) => {placeholder="Search nodes..."className="pl-8 h-7"value={searchQuery}- onChange={(e) => setSearchQuery(e.target.value)}+ onChange={handleSearchChange}/></div></div></div>- {filteredNodes?.length === 0 && searchQuery === "" && <div className='text-sm p-4 text-center'><p className='border rounded-md border-dashed p-4 text-center'>Right click on the panel to add your first investigation item.</p></div>}+ {filteredNodes?.length === 0 && searchQuery === "" && (+ <div className='text-sm p-4 text-center'>+ <p className='border rounded-md border-dashed p-4 text-center'>+ Right click on the panel to add your first investigation item.+ </p>+ </div>+ )}{filteredNodes?.length === 0 && searchQuery ? (- <div className="p-4 text-center text-muted-foreground">No nodes match your search</div>+ <div className="p-4 text-center text-muted-foreground">+ No nodes match your search+ </div>) : (- filteredNodes?.map((node: any) => <NodeRenderer node={node} setCurrentNode={setCurrentNode} key={node.id} />)+ filteredNodes?.map((node: any) => (+ <NodeRenderer+ node={node}+ currentNodeId={currentNodeId || null}+ setCurrentNode={setCurrentNode}+ key={node.id}+ />+ )))}- </div>)-}+ </div>+ )+})-export default memo(NodesPanel)\ No newline at end of file+export default NodesPanel\ No newline at end of filediff --git a/flowsint-web/src/components/investigations/sketch/nodes/button-edge.tsx b/flowsint-web/src/components/investigations/sketch/nodes/button-edge.tsxindex 0d30f4ec..df5d4a5c 100644--- a/flowsint-web/src/components/investigations/sketch/nodes/button-edge.tsx+++ b/flowsint-web/src/components/investigations/sketch/nodes/button-edge.tsx@@ -29,12 +29,12 @@ export const ButtonEdge = memo(({});const showContent = useStore(zoomSelector);- const { settings } = useInvestigationStore(state => state)+ const showNodeLabel = useInvestigationStore(state => state.settings.showNodeLabel);return (<><BaseEdge className="opacity-30" path={edgePath} markerEnd={markerEnd} style={style} /><EdgeLabelRenderer>- {settings.showEdgeLabel && showContent &&+ {showNodeLabel && showContent &&<divclassName="nodrag nopan pointer-events-auto absolute"style={{diff --git a/flowsint-web/src/components/investigations/sketch/nodes/custom-node.tsx b/flowsint-web/src/components/investigations/sketch/nodes/custom-node.tsxindex 8c6bcc9b..3951cf53 100644--- a/flowsint-web/src/components/investigations/sketch/nodes/custom-node.tsx+++ b/flowsint-web/src/components/investigations/sketch/nodes/custom-node.tsx@@ -1,8 +1,8 @@-import React, { memo, useMemo } from 'react';+import React, { memo, useMemo, useCallback } from 'react';import { CopyButton } from '@/components/copy';import { Badge } from '@/components/ui/badge';-import { Handle, Position, useStore } from '@xyflow/react';-import { cn, typeColorMap, zoomSelector } from '@/lib/utils';+import { Handle, Position } from '@xyflow/react';+import { cn, typeColorMap } from '@/lib/utils';import { actionItems } from '@/lib/action-items';import { QuestionMarkIcon } from '@radix-ui/react-icons';import {@@ -11,26 +11,32 @@ import {TooltipTrigger,} from "@/components/ui/tooltip-node";import { useInvestigationStore } from '@/store/investigation-store';+import { useFlowStore } from '@/store/flow-store';export default memo(({ data, selected }: any) => {- const item = useMemo(() => (actionItems as any).find((a: any) => a.type === data.type), [data?.type])- const Icon = item?.icon || QuestionMarkIcon- const { settings } = useInvestigationStore(state => state)+ const item = useMemo(() => (actionItems as any).find((a: any) => a.type === data.type), [data?.type]);+ const Icon = item?.icon || QuestionMarkIcon;+ const showNodeLabel = useInvestigationStore(state => state.settings.showNodeLabel);+ const currentNodeId = useFlowStore(state => state.currentNode?.id,+ (prev, next) => prev === next);++ const active = currentNodeId === data.id;+return (- <TooltipNode className={cn('p-.5 rounded-full', typeColorMap[data.type])} selected={selected}>+ <TooltipNode className={cn('p-.5 rounded-full', typeColorMap[data.type])} selected={active}><TooltipTrigger><div className="inline-flex items-center gap-2 p-1 w-auto"><Badge variant="secondary" className={cn("p-0 rounded-full", item?.size || "h-5 w-5")}><Icon className="h-4 w-4" /></Badge>- {settings.showNodeLabel && <div className="flex items-center gap-1">+ {showNodeLabel && <div className="flex items-center gap-1"><span className="text-sm">{data.label}</span><CopyButton className="rounded-full h-7 w-7 text-xs" content={data.label} /></div>}</div></TooltipTrigger>- {!settings.showNodeLabel &&- <TooltipContent position={Position.Top}>{data.label}</TooltipContent>+ {!showNodeLabel &&+ <TooltipContent selected={active} position={Position.Top}>{data.label}</TooltipContent>}<Handletype="target"diff --git a/flowsint-web/src/components/investigations/sketch/profile-panel.tsx b/flowsint-web/src/components/investigations/sketch/profile-panel.tsxindex 8a0bcaa2..822dbab9 100644--- a/flowsint-web/src/components/investigations/sketch/profile-panel.tsx+++ b/flowsint-web/src/components/investigations/sketch/profile-panel.tsx@@ -50,8 +50,8 @@ export default function ProfilePanel({ data, type }: { data: any, type: string }<div className="flex items-center gap-2"><ButtononClick={handleCheckEmail}- disabled={type !== "email"}- className="relative min-w-[80px] h-8 overflow-hidden bg-gradient-to-r from-purple-600 to-pink-600 hover:from-purple-700 hover:to-pink-700 transition-all duration-300 px-6 py-2 text-white border-none font-medium rounded-full"+ disabled={data?.type !== "email"}+ className="relative min-w-[80px] h-8 overflow-hidden bg-gradient-to-r from-purple-600 to-indigo-400 hover:from-purple-700 hover:to-indigo-500 transition-all duration-300 px-6 py-2 text-white border-none font-medium rounded-full"><span className="flex items-center gap-2"><Sparkles className={'h-4 w-4 transition-transform duration-300'} />diff --git a/flowsint-web/src/components/ui/tooltip-node.tsx b/flowsint-web/src/components/ui/tooltip-node.tsxindex c47198e5..87e17183 100644--- a/flowsint-web/src/components/ui/tooltip-node.tsx+++ b/flowsint-web/src/components/ui/tooltip-node.tsx@@ -18,16 +18,12 @@ const TooltipContext = createContext(false);export type TooltipNodeProps = Partial<NodeProps> & {children?: ReactNode;- className: string+ className: string;+ selected?: boolean;};--/**- * A component that wraps a node and provides tooltip visibility context.- */export const TooltipNode = forwardRef<HTMLDivElement, TooltipNodeProps>(({ selected, children, className }, ref) => {const [isTooltipVisible, setTooltipVisible] = useState(false);-const showTooltip = useCallback(() => setTooltipVisible(true), []);const hideTooltip = useCallback(() => setTooltipVisible(false), []);@@ -59,14 +55,14 @@ export type TooltipContentProps = NodeToolbarProps;/*** A component that displays the tooltip content based on visibility context.*/-export const TooltipContent = forwardRef<HTMLDivElement, TooltipContentProps>(- ({ position, children }, ref) => {+export const TooltipContent = forwardRef<HTMLDivElement, TooltipContentProps & { selected: boolean }>(+ ({ position, children, selected }, ref) => {const isTooltipVisible = useContext(TooltipContext);return (<div ref={ref}><NodeToolbar- isVisible={isTooltipVisible}+ isVisible={isTooltipVisible || selected}className="rounded-sm bg-background p-2 shadow-md"tabIndex={1}position={position}