From 87fb26d2719cf0343efcb49eba9ab6b2baf13a0e Mon Sep 17 00:00:00 2001 From: Pablo Lara Date: Wed, 6 Nov 2024 15:54:15 +0100 Subject: [PATCH] chore: twaks for scan page --- app/(prowler)/scans/page.tsx | 72 ++-------------- .../column-get-scans-schedule.tsx | 83 ------------------- .../schedule-scans/data-table-row-details.tsx | 37 --------- .../scans/table/schedule-scans/index.ts | 2 - 4 files changed, 9 insertions(+), 185 deletions(-) delete mode 100644 components/scans/table/schedule-scans/column-get-scans-schedule.tsx delete mode 100644 components/scans/table/schedule-scans/data-table-row-details.tsx delete mode 100644 components/scans/table/schedule-scans/index.ts diff --git a/app/(prowler)/scans/page.tsx b/app/(prowler)/scans/page.tsx index d696bdc9a0..c93ea87ad8 100644 --- a/app/(prowler)/scans/page.tsx +++ b/app/(prowler)/scans/page.tsx @@ -3,15 +3,10 @@ import { Suspense } from "react"; import { getProviders } from "@/actions/providers"; import { getScans } from "@/actions/scans"; -import { - FilterControls, - filterProviders, - filterScans, -} from "@/components/filters"; +import { FilterControls, filterScans } from "@/components/filters"; import { SkeletonTableScans } from "@/components/scans/table"; import { ColumnProviderScans } from "@/components/scans/table/provider-scans"; import { ColumnGetScans } from "@/components/scans/table/scans"; -import { ColumnGetScansSchedule } from "@/components/scans/table/schedule-scans"; import { Header } from "@/components/ui"; import { DataTable } from "@/components/ui/table"; import { SearchParamsProps } from "@/types"; @@ -32,75 +27,26 @@ export default async function Scans({
-
- }> - - -
-
- }> - - -
}>
+
+ }> + + +
); } const SSRDataTableProviders = async () => { - // const page = parseInt(searchParams.page?.toString() || "1", 10); - // const sort = searchParams.sort?.toString(); - - // Extract all filter parameters - // const filters = Object.fromEntries( - // Object.entries(searchParams).filter(([key]) => key.startsWith("filter[")), - // ); - - // Extract query from filters - // const query = (filters["filter[search]"] as string) || ""; - - const providersData = await getProviders({ page: 1 }); - + const filters = { "filter[connected]": "true" }; + const providersData = await getProviders({ page: 1, filters }); return ( - - ); -}; - -const SSRDataTableScansSchedule = async ({ - searchParams, -}: { - searchParams: SearchParamsProps; -}) => { - const page = parseInt(searchParams.page?.toString() || "1", 10); - const sort = searchParams.sort?.toString(); - - // Extract all filter parameters - const filters = Object.fromEntries( - Object.entries(searchParams).filter(([key]) => key.startsWith("filter[")), - ); - - // Extract query from filters - const query = (filters["filter[search]"] as string) || ""; - - const scansData = await getScans({ query, page, sort, filters }); - - return ( - + ); }; diff --git a/components/scans/table/schedule-scans/column-get-scans-schedule.tsx b/components/scans/table/schedule-scans/column-get-scans-schedule.tsx deleted file mode 100644 index 69bb478ecc..0000000000 --- a/components/scans/table/schedule-scans/column-get-scans-schedule.tsx +++ /dev/null @@ -1,83 +0,0 @@ -"use client"; - -import { ColumnDef } from "@tanstack/react-table"; - -import { PlusIcon } from "@/components/icons"; -import { DateWithTime, EntityInfoShort } from "@/components/ui/entities"; -import { TriggerSheet } from "@/components/ui/sheet"; -import { DataTableColumnHeader, StatusBadge } from "@/components/ui/table"; -import { ScanProps } from "@/types"; - -import { DataTableRowActions } from "../scans/data-table-row-actions"; -import { DataTableRowDetails } from "."; - -const getScanData = (row: { original: ScanProps }) => { - return row.original; -}; - -export const ColumnGetScansSchedule: ColumnDef[] = [ - { - accessorKey: "name", - header: ({ column }) => ( - - ), - cell: ({ row }) => { - const { - attributes: { name }, - } = getScanData(row); - return ; - }, - }, - - { - accessorKey: "status", - header: ({ column }) => ( - - ), - cell: ({ row }) => { - const { - attributes: { state }, - } = getScanData(row); - return ; - }, - }, - { - accessorKey: "scheduled_at", - header: ({ column }) => ( - - ), - cell: ({ row }) => { - const { - attributes: { scheduled_at }, - } = getScanData(row); - return ; - }, - }, - - { - id: "moreInfo", - header: "Details", - cell: ({ row }) => { - return ( - } - title="Scan Details" - description="View the scan details" - > - - - ); - }, - }, - - { - id: "actions", - cell: ({ row }) => { - return ; - }, - }, -]; diff --git a/components/scans/table/schedule-scans/data-table-row-details.tsx b/components/scans/table/schedule-scans/data-table-row-details.tsx deleted file mode 100644 index 997fa0e5d9..0000000000 --- a/components/scans/table/schedule-scans/data-table-row-details.tsx +++ /dev/null @@ -1,37 +0,0 @@ -"use client"; - -import { useEffect, useState } from "react"; - -import { getScan } from "@/actions/scans"; -import { ScanDetail, SkeletonTableScans } from "@/components/scans/table"; -import { ScanProps } from "@/types"; - -export const DataTableRowDetails = ({ entityId }: { entityId: string }) => { - const [scanDetails, setScanDetails] = useState(null); - const [isLoading, setIsLoading] = useState(true); - - useEffect(() => { - const fetchScanDetails = async () => { - try { - const result = await getScan(entityId); - setScanDetails(result?.data); - } catch (error) { - console.error("Error fetching scan details:", error); - } finally { - setIsLoading(false); - } - }; - - fetchScanDetails(); - }, [entityId]); - - if (isLoading) { - return ; - } - - if (!scanDetails) { - return
No scan details available
; - } - - return ; -}; diff --git a/components/scans/table/schedule-scans/index.ts b/components/scans/table/schedule-scans/index.ts deleted file mode 100644 index e93f00f4c5..0000000000 --- a/components/scans/table/schedule-scans/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from "./column-get-scans-schedule"; -export * from "./data-table-row-details";