A modern platform for visual, flexible, and extensible graph-based investigations. For cybersecurity analysts and investigators.
feat: save simulations
dextmorgn6c625bc3e6f8
diff --git a/flowsint-web/src/app/dashboard/transforms/[transform_id]/page.tsx b/flowsint-web/src/app/dashboard/transforms/[transform_id]/page.tsxnew file mode 100644index 00000000..510a5c1b--- /dev/null+++ b/flowsint-web/src/app/dashboard/transforms/[transform_id]/page.tsx@@ -0,0 +1,25 @@+import TransformEditor from "@/components/templates/editor"+import { createClient } from "@/lib/supabase/server"+import { notFound } from "next/navigation"++async function fetchNodes() {+ const res = await fetch(`${process.env.NEXT_PUBLIC_DOCKER_FLOWSINT_API}/transforms/nodes`, {+ next: { revalidate: 3600 }+ })+ if (!res.ok) {+ notFound()+ }+ return res.json()+}+export default async function EditorCustom({+ params+}: {+ children: React.ReactNode;+ params: Promise<{ transform_id: string }>+}) {+ const { transform_id } = await (params)+ const supabase = await createClient()+ const nodesData = await fetchNodes()+ const { data: transform } = await supabase.from("transforms").select("*").eq("id", transform_id as string).single()+ return <TransformEditor nodesData={nodesData} initialNodes={transform?.transform_schema?.nodes} initialEdges={transform?.transform_schema?.edges} />+}\ No newline at end of filediff --git a/flowsint-web/src/app/dashboard/templates/editor/page.tsx b/flowsint-web/src/app/dashboard/transforms/editor/page.tsxsimilarity index 100%rename from flowsint-web/src/app/dashboard/templates/editor/page.tsxrename to flowsint-web/src/app/dashboard/transforms/editor/page.tsxdiff --git a/flowsint-web/src/app/dashboard/transforms/page.tsx b/flowsint-web/src/app/dashboard/transforms/page.tsxnew file mode 100644index 00000000..b99314b6--- /dev/null+++ b/flowsint-web/src/app/dashboard/transforms/page.tsx@@ -0,0 +1,45 @@+import { Button } from '@/components/ui/button'+import { createClient } from '@/lib/supabase/server'+import Link from 'next/link'+import React from 'react'++const TransformsPage = async () => {+ const supabase = await createClient()+ const { data: transforms } = await supabase.from("transforms").select("*")++ return (+ <div className="w-full space-y-8 container mx-auto py-12 px-8">+ <div>+ <div>+ <h1 className="font-semibold text-2xl">Transforms</h1>+ <p className="opacity-60 mt-3">Here are the transforms used to gather informations.</p>+ </div>+ <div className="flex justify-end">+ <Link href="/dashboard/transforms/editor">+ <Button>New transform</Button>+ </Link>+ </div>+ </div>+ <div className='w-full grid lg:grid-cols-3 md:grid-cols-2 grid-cols-1 xl:grid-cols-4 gap-4'>+ {transforms?.map((transform) => (+ <TransformItem key={transform.id} transform={transform} />+ ))}+ </div>+ </div>+ )+}++export const TransformItem = ({ transform }: { transform: any }) => {+ return (+ <Link href={`/dashboard/transforms/${transform.id}`} className="w-full">+ <div className="bg-card rounded-lg shadow-md p-4">+ <h2 className="text-lg font-semibold">{transform.name}</h2>+ <p className="text-sm text-muted-foreground">{transform.description}</p>+ <span rel="noopener noreferrer" className="text-blue-500 hover:underline">+ {transform?.transform_schema?.edges?.length} steps+ </span>+ </div>+ </Link>+ )+}+export default TransformsPage\ No newline at end of filediff --git a/flowsint-web/src/components/dashboard/main-nav.tsx b/flowsint-web/src/components/dashboard/main-nav.tsxindex e35c99ee..45078d2a 100644--- a/flowsint-web/src/components/dashboard/main-nav.tsx+++ b/flowsint-web/src/components/dashboard/main-nav.tsx@@ -60,13 +60,13 @@ export function MainNav({ className, ...props }: React.HTMLAttributes<HTMLElemenAnalyses</Link><Link- href="/dashboard/templates"+ href="/dashboard/transforms"className={cn("text-sm font-medium transition-colors hover:text-primary px-3 py-1.5 rounded-md",- isActive("/dashboard/templates") ? "bg-muted/50" : "text-muted-foreground",+ isActive("/dashboard/transforms") ? "bg-muted/50" : "text-muted-foreground",)}>- Templates+ Transforms</Link></nav>)diff --git a/flowsint-web/src/components/templates/editor.tsx b/flowsint-web/src/components/templates/editor.tsxindex 20aa3553..46d85949 100644--- a/flowsint-web/src/components/templates/editor.tsx+++ b/flowsint-web/src/components/templates/editor.tsx@@ -32,16 +32,16 @@ import { FlowControls } from "./controls"import { getDagreLayoutedElements } from "@/lib/utils"import { supabase } from "@/lib/supabase/client"import { toast } from "sonner"-import { useRouter } from "next/navigation"+import { useParams, useRouter } from "next/navigation"const nodeTypes: NodeTypes = {scanner: ScannerNode,}-const FlowEditor = memo(({ nodesData, theme }: { nodesData: { items: any[] }, theme: any }) => {+const FlowEditor = memo(({ nodesData, initialEdges, initialNodes, theme }: { nodesData: { items: any[] }, theme: any, initialEdges: Edge[], initialNodes: Node[] }) => {const { fitView, zoomIn, zoomOut, setCenter } = useReactFlow()- const [nodes, setNodes, onNodesChange] = useNodesState<any>([])- const [edges, setEdges, onEdgesChange] = useEdgesState<Edge<Record<string, unknown>>>([])+ const [nodes, setNodes, onNodesChange] = useNodesState<any>(initialNodes)+ const [edges, setEdges, onEdgesChange] = useEdgesState<Edge<Record<string, unknown>>>(initialEdges)const [selectedNode, setSelectedNode] = useState<Node<any> | null>(null)const [loading, setLoading] = useState<boolean>(false)const [mounted, setMounted] = useState(false)@@ -49,6 +49,7 @@ const FlowEditor = memo(({ nodesData, theme }: { nodesData: { items: any[] }, thconst reactFlowWrapper = useRef<HTMLDivElement>(null)const [reactFlowInstance, setReactFlowInstance] = useState<any>(null)const router = useRouter()+ const { transform_id } = useParams()useEffect(() => {setMounted(true)@@ -171,14 +172,15 @@ const FlowEditor = memo(({ nodesData, theme }: { nodesData: { items: any[] }, thconst handleSaveSimulation = useCallback(async () => {setLoading(true)try {- const { data: newTransfrorm } = await supabase.from("transforms").insert({+ const { data: newTransfrorm } = await supabase.from("transforms").upsert({+ id: transform_id,name: "My Simulation",transform_schema: {nodes, edges}}).select("id").single()toast.success("Simulation saved successfully.")- newTransfrorm && router.push(`/transform/${newTransfrorm.id}`)+ newTransfrorm && !transform_id && router.push(`/dashboard/transforms/${newTransfrorm.id}`)} catch (error) {toast.error("Error saving simulation")} finally {@@ -294,7 +296,7 @@ const FlowEditor = memo(({ nodesData, theme }: { nodesData: { items: any[] }, thFlowEditor.displayName = "FlowEditor"-function TransformEditor({ nodesData }: { nodesData: { items: any[] } }) {+function TransformEditor({ nodesData, initialEdges = [], initialNodes = [] }: { nodesData: { items: any[] }, initialEdges?: Edge[], initialNodes?: Node[] }) {const [mounted, setMounted] = useState(false);const { resolvedTheme } = useTheme();@@ -312,7 +314,7 @@ function TransformEditor({ nodesData }: { nodesData: { items: any[] } }) {return (<ReactFlowProvider>- <FlowEditor nodesData={nodesData} theme={resolvedTheme || "light"} />+ <FlowEditor nodesData={nodesData} initialEdges={initialEdges} initialNodes={initialNodes} theme={resolvedTheme || "light"} /></ReactFlowProvider>);}