diff --git a/ui/components/scans/launch-workflow/launch-scan-workflow-form.tsx b/ui/components/scans/launch-workflow/launch-scan-workflow-form.tsx index 7fb31d7e2a..b0047445c7 100644 --- a/ui/components/scans/launch-workflow/launch-scan-workflow-form.tsx +++ b/ui/components/scans/launch-workflow/launch-scan-workflow-form.tsx @@ -13,6 +13,7 @@ import { Form } from "@/components/ui/form"; import { toast } from "@/components/ui/toast"; import { onDemandScanFormSchema } from "@/types"; +import { SCAN_LAUNCHED_EVENT } from "../table/scans/scans-table-with-polling"; import { SelectScanProvider } from "./select-scan-provider"; type ProviderInfo = { @@ -85,6 +86,8 @@ export const LaunchScanWorkflow = ({ }); // Reset form after successful submission form.reset(); + // Notify the scans table to refresh and pick up the new scan + window.dispatchEvent(new Event(SCAN_LAUNCHED_EVENT)); } }; diff --git a/ui/components/scans/table/scans/scans-table-with-polling.tsx b/ui/components/scans/table/scans/scans-table-with-polling.tsx index 12c18b35d2..5c59a5f267 100644 --- a/ui/components/scans/table/scans/scans-table-with-polling.tsx +++ b/ui/components/scans/table/scans/scans-table-with-polling.tsx @@ -1,6 +1,6 @@ "use client"; -import { useCallback, useState } from "react"; +import { useCallback, useEffect, useState } from "react"; import { getScans } from "@/actions/scans"; import { AutoRefresh } from "@/components/scans"; @@ -9,6 +9,8 @@ import { MetaDataProps, ScanProps, SearchParamsProps } from "@/types"; import { ColumnGetScans } from "./column-get-scans"; +export const SCAN_LAUNCHED_EVENT = "scan-launched"; + interface ScansTableWithPollingProps { initialData: ScanProps[]; initialMeta?: MetaDataProps; @@ -98,6 +100,15 @@ export function ScansTableWithPolling({ } }, [searchParams]); + // Listen for scan launch events to trigger an immediate refresh + useEffect(() => { + const handler = () => { + handleRefresh(); + }; + window.addEventListener(SCAN_LAUNCHED_EVENT, handler); + return () => window.removeEventListener(SCAN_LAUNCHED_EVENT, handler); + }, [handleRefresh]); + return ( <>