A modern platform for visual, flexible, and extensible graph-based investigations. For cybersecurity analysts and investigators.
feat: editable relation
dextmorgn9dab0a65c54d
diff --git a/flowsint-web/src/app/api/projects/[project_id]/investigations/[investigation_id]/data/route.ts b/flowsint-web/src/app/api/projects/[project_id]/investigations/[investigation_id]/data/route.tsindex 3c59630e..42b9d4ac 100644--- a/flowsint-web/src/app/api/projects/[project_id]/investigations/[investigation_id]/data/route.ts+++ b/flowsint-web/src/app/api/projects/[project_id]/investigations/[investigation_id]/data/route.ts@@ -34,7 +34,7 @@ export async function GET(_: Request, { params }: { params: Promise<{ investigat// Récupérer les relationsconst { data: relations, error: relError } = await supabase.from("relationships")- .select("individual_a, individual_b, relation_type, confidence_level")+ .select("id, individual_a, individual_b, relation_type, confidence_level").in("individual_a", individualIds).in("individual_b", individualIds)if (relError) {@@ -145,12 +145,12 @@ export async function GET(_: Request, { params }: { params: Promise<{ investigat})})// Ajouter les relations entre individus- relations?.forEach(({ individual_a, individual_b, relation_type, confidence_level }) => {+ relations?.forEach(({ id, individual_a, individual_b, relation_type, confidence_level }) => {edges.push({source: individual_a.toString(),target: individual_b.toString(),type: "custom",- id: `${individual_a}-${individual_b}`.toString(),+ id: id.toString(),label: relation_type,confidence_level,})diff --git a/flowsint-web/src/components/investigations/sketch/graph.tsx b/flowsint-web/src/components/investigations/sketch/graph.tsxindex fe729769..4371fe6c 100644--- a/flowsint-web/src/components/investigations/sketch/graph.tsx+++ b/flowsint-web/src/components/investigations/sketch/graph.tsx@@ -53,8 +53,9 @@ import NodeContextMenu from "./nodes/node-context-menu"import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs"import ProfilePanel from "./profile-panel"import GroupNode from "./nodes/group"+import CustomEdge from "./nodes/custom-edge"const edgeTypes = {- custom: FloatingEdge,+ custom: CustomEdge,}const nodeTypes = {diff --git a/flowsint-web/src/components/investigations/sketch/nodes/button-edge.tsx b/flowsint-web/src/components/investigations/sketch/nodes/button-edge.tsxnew file mode 100644index 00000000..cdc94ecd--- /dev/null+++ b/flowsint-web/src/components/investigations/sketch/nodes/button-edge.tsx@@ -0,0 +1,46 @@+import { ReactNode } from "react";++import {+ BaseEdge,+ EdgeLabelRenderer,+ EdgeProps,+ getBezierPath,+} from "@xyflow/react";++export const ButtonEdge = ({+ sourceX,+ sourceY,+ targetX,+ targetY,+ sourcePosition,+ targetPosition,+ style = {},+ markerEnd,+ children,+}: EdgeProps & { children: ReactNode }) => {+ const [edgePath, labelX, labelY] = getBezierPath({+ sourceX,+ sourceY,+ sourcePosition,+ targetX,+ targetY,+ targetPosition,+ });++ return (+ <>+ <BaseEdge path={edgePath} markerEnd={markerEnd} style={style} />+ <EdgeLabelRenderer>+ <div+ className="nodrag nopan pointer-events-auto absolute"+ style={{+ ...style,+ transform: `translate(-50%, -50%) translate(${labelX}px,${labelY}px)`,+ }}+ >+ {children}+ </div>+ </EdgeLabelRenderer>+ </>+ );+};\ No newline at end of filediff --git a/flowsint-web/src/components/investigations/sketch/nodes/custom-edge.tsx b/flowsint-web/src/components/investigations/sketch/nodes/custom-edge.tsxnew file mode 100644index 00000000..5a1311a6--- /dev/null+++ b/flowsint-web/src/components/investigations/sketch/nodes/custom-edge.tsx@@ -0,0 +1,106 @@+"use client"++import type React from "react"++import type { EdgeProps } from "@xyflow/react"+import { memo, useCallback, useState, useRef } from "react"+import { supabase } from "@/lib/supabase/client"+import { Check, Loader2 } from "lucide-react"+import { Button } from "@/components/ui/button"+import { Input } from "@/components/ui/input"+import { cn } from "@/lib/utils"+import { ButtonEdge } from "./button-edge"+import { toast } from "sonner"++const EditableEdge = memo((props: EdgeProps) => {+ const { id, label } = props+ const [isEditing, setIsEditing] = useState(false)+ const [isLoading, setIsLoading] = useState(false)+ const [editValue, setEditValue] = useState((label as string) || "")+ const submitButtonRef = useRef<HTMLButtonElement>(null)++ const handleEditClick = useCallback(() => {+ setIsEditing(true)+ }, [])++ const handleInputBlur = useCallback((e: React.FocusEvent) => {+ // Check if the related target (where focus is going) is the submit button+ if (submitButtonRef.current && submitButtonRef.current.contains(e.relatedTarget as Node)) {+ // Don't close the edit mode if clicking on the submit button+ return+ }+ setIsEditing(false)+ }, [])++ const handleSave = useCallback(+ async (e: React.FormEvent) => {+ e.preventDefault()+ e.stopPropagation()+ if (!id) return+ setIsLoading(true)+ try {+ const { error } = await supabase+ .from("relationships")+ .update({ relation_type: editValue })+ .eq("id", id.toString())+ if (error) {+ toast.error("An error occurred: " + error.message)+ } else {+ toast.success("Relation updated.")+ }+ } catch (err) {+ toast.error("An error occurred.")+ } finally {+ setIsLoading(false)+ setIsEditing(false)+ }+ },+ [id, editValue],+ )++ const handleInputChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {+ setEditValue(e.target.value)+ }, [])++ return (+ <ButtonEdge {...props}>+ <form onSubmit={handleSave} className="flex items-center justify-center h-full">+ {isEditing ? (+ <div className="flex items-center gap-1 bg-background border rounded-md p-1 shadow-sm">+ <Input+ autoFocus+ value={editValue}+ onChange={handleInputChange}+ onBlur={handleInputBlur}+ className="h-7 w-24"+ />+ <Button+ ref={submitButtonRef}+ size="icon"+ variant="ghost"+ className="h-7 w-7"+ type="submit"+ disabled={isLoading}+ >+ {isLoading ? <Loader2 className="h-3.5 w-3.5 animate-spin" /> : <Check className="h-3.5 w-3.5" />}+ </Button>+ </div>+ ) : (+ <Button+ onClick={handleEditClick}+ size="sm"+ variant="secondary"+ className={cn("text-xs px-1 py-.5 h-auto", !label && "opacity-70")}+ >+ {editValue || ""}+ </Button>+ )}+ </form>+ </ButtonEdge>+ )+})++EditableEdge.displayName = "EditableEdge"++export default EditableEdge+