diff --git a/ui/app/(prowler)/findings/page.tsx b/ui/app/(prowler)/findings/page.tsx index 39d2ad7846..059438fd3f 100644 --- a/ui/app/(prowler)/findings/page.tsx +++ b/ui/app/(prowler)/findings/page.tsx @@ -1,4 +1,5 @@ import { Spacer } from "@nextui-org/react"; +import { format, subDays } from "date-fns"; import React, { Suspense } from "react"; import { getFindings, getMetadataInfo } from "@/actions/findings"; @@ -31,7 +32,21 @@ export default async function Findings({ // Make sure the sort is correctly encoded const encodedSort = sort?.replace(/^\+/, ""); + const twoDaysAgo = format(subDays(new Date(), 2), "yyyy-MM-dd"); + + // Check if the searchParams contain any date or scan filter + const hasDateOrScanFilter = Object.keys(searchParams).some( + (key) => key.includes("inserted_at") || key.includes("scan__in"), + ); + + // Default filters for getMetadataInfo + const defaultFilters: Record = hasDateOrScanFilter + ? {} // Do not apply default filters if there are date or scan filters + : { "filter[inserted_at__gte]": twoDaysAgo }; + + // Extract all filter parameters and combine with default filters const filters: Record = { + ...defaultFilters, ...Object.fromEntries( Object.entries(searchParams) .filter(([key]) => key.startsWith("filter[")) @@ -44,11 +59,15 @@ export default async function Findings({ const query = filters["filter[search]"] || ""; - const metadataInfoData = await getMetadataInfo({ - query, - sort: encodedSort, - filters, - }); + const [metadataInfoData, providersData, scansData] = await Promise.all([ + getMetadataInfo({ + query, + sort: encodedSort, + filters, + }), + getProviders({}), + getScans({}), + ]); // Extract unique regions and services from the new endpoint const uniqueRegions = metadataInfoData?.data?.attributes?.regions || []; @@ -56,8 +75,6 @@ export default async function Findings({ const uniqueResourceTypes = metadataInfoData?.data?.attributes?.resource_types || []; // Get findings data - const providersData = await getProviders({}); - const scansData = await getScans({}); // Extract provider UIDs const providerUIDs = Array.from( @@ -141,7 +158,20 @@ const SSRDataTable = async ({ // Make sure the sort is correctly encoded const encodedSort = sort.replace(/^\+/, ""); + const twoDaysAgo = format(subDays(new Date(), 2), "yyyy-MM-dd"); + + // Check if the searchParams contain any date or scan filter + const hasDateOrScanFilter = Object.keys(searchParams).some( + (key) => key.includes("inserted_at") || key.includes("scan__in"), + ); + + // Default filters for getFindings + const defaultFilters: Record = hasDateOrScanFilter + ? {} // Do not apply default filters if there are date or scan filters + : { "filter[inserted_at__gte]": twoDaysAgo }; + const filters: Record = { + ...defaultFilters, ...Object.fromEntries( Object.entries(searchParams) .filter(([key]) => key.startsWith("filter[")) @@ -190,10 +220,18 @@ const SSRDataTable = async ({ }; return ( - + <> + {findingsData?.errors && ( +
+

Error:

+

{findingsData.errors[0].detail}

+
+ )} + + ); }; diff --git a/ui/app/(prowler)/page.tsx b/ui/app/(prowler)/page.tsx index c6e0748362..e1b02c2bbe 100644 --- a/ui/app/(prowler)/page.tsx +++ b/ui/app/(prowler)/page.tsx @@ -1,4 +1,5 @@ import { Spacer } from "@nextui-org/react"; +import { format, subDays } from "date-fns"; import { Suspense } from "react"; import { getFindings } from "@/actions/findings/findings"; @@ -131,9 +132,12 @@ const SSRDataNewFindingsTable = async () => { const page = 1; const sort = "severity,-inserted_at"; + const twoDaysAgo = format(subDays(new Date(), 2), "yyyy-MM-dd"); + const defaultFilters = { "filter[status__in]": "FAIL", "filter[delta__in]": "new", + "filter[inserted_at__gte]": twoDaysAgo, }; const findingsData = await getFindings({ @@ -172,14 +176,21 @@ const SSRDataNewFindingsTable = async () => { return ( <> -
-

- Latest 10 failing findings to date by Severity -

+
+
+

+ Latest 10 failing findings to date by Severity +

+

+ Showing the latest 10 failing findings by severity from the last 2 + days. +

+
+ { const searchParams = useSearchParams(); const [value, setValue] = React.useState(() => { - const dateParam = searchParams.get("filter[updated_at]"); + const dateParam = searchParams.get("filter[inserted_at]"); return dateParam ? today(getLocalTimeZone()) : null; }); @@ -30,9 +30,9 @@ export const CustomDatePicker = () => { (date: any) => { const params = new URLSearchParams(searchParams.toString()); if (date) { - params.set("filter[updated_at]", date.toString()); + params.set("filter[inserted_at]", date.toString()); } else { - params.delete("filter[updated_at]"); + params.delete("filter[inserted_at]"); } router.push(`?${params.toString()}`, { scroll: false }); }, diff --git a/ui/components/overview/new-findings-table/link-to-findings/link-to-findings.tsx b/ui/components/overview/new-findings-table/link-to-findings/link-to-findings.tsx index 2c86db8fd3..e5766db634 100644 --- a/ui/components/overview/new-findings-table/link-to-findings/link-to-findings.tsx +++ b/ui/components/overview/new-findings-table/link-to-findings/link-to-findings.tsx @@ -6,7 +6,7 @@ export const LinkToFindings = () => { return (