From 69a1468c1897dafd5417486d18375837d8ab63f2 Mon Sep 17 00:00:00 2001 From: Pablo Lara Date: Fri, 11 Oct 2024 06:49:14 +0200 Subject: [PATCH] Wrap CustomButton component with React.forwardRef --- app/(prowler)/scans/page.tsx | 4 +- components/scans/table/index.ts | 1 - .../column-provider-scans.tsx | 20 +-- .../provider-scans/data-table-row-actions.tsx | 128 +++++++++++++++++ .../scans/table/provider-scans/index.ts | 2 + components/ui/custom/custom-button.tsx | 129 ++++++++++-------- 6 files changed, 206 insertions(+), 78 deletions(-) rename components/scans/table/{ => provider-scans}/column-provider-scans.tsx (63%) create mode 100644 components/scans/table/provider-scans/data-table-row-actions.tsx create mode 100644 components/scans/table/provider-scans/index.ts diff --git a/app/(prowler)/scans/page.tsx b/app/(prowler)/scans/page.tsx index 811f547412..d31a641a0e 100644 --- a/app/(prowler)/scans/page.tsx +++ b/app/(prowler)/scans/page.tsx @@ -11,9 +11,9 @@ import { import { ColumnGetScans, ColumnGetScansSchedule, - ColumnProviderScans, SkeletonTableScans, } from "@/components/scans/table"; +import { ColumnProviderScans } from "@/components/scans/table/provider-scans"; import { Header } from "@/components/ui"; import { DataTable } from "@/components/ui/table"; import { SearchParamsProps } from "@/types"; @@ -33,7 +33,7 @@ export default async function Scans({ -
+
}> diff --git a/components/scans/table/index.ts b/components/scans/table/index.ts index 9015ed3651..45b74533b4 100644 --- a/components/scans/table/index.ts +++ b/components/scans/table/index.ts @@ -1,5 +1,4 @@ export * from "./column-get-scans"; export * from "./column-get-scans-schedule"; -export * from "./column-provider-scans"; export * from "./data-table-row-actions"; export * from "./skeleton-table-scans"; diff --git a/components/scans/table/column-provider-scans.tsx b/components/scans/table/provider-scans/column-provider-scans.tsx similarity index 63% rename from components/scans/table/column-provider-scans.tsx rename to components/scans/table/provider-scans/column-provider-scans.tsx index c86fd0f434..938c3c1681 100644 --- a/components/scans/table/column-provider-scans.tsx +++ b/components/scans/table/provider-scans/column-provider-scans.tsx @@ -2,11 +2,11 @@ import { ColumnDef } from "@tanstack/react-table"; -import { AddIcon } from "@/components/icons/Icons"; -import { CustomButton } from "@/components/ui/custom"; import { EntityInfoShort } from "@/components/ui/entities"; import { ProviderProps } from "@/types"; +import { DataTableRowActions } from "./data-table-row-actions"; + const getProviderData = (row: { original: ProviderProps }) => { return row.original; }; @@ -33,21 +33,7 @@ export const ColumnProviderScans: ColumnDef[] = [ accessorKey: "launchScan", header: "Launch Scan", cell: ({ row }) => { - return ( - } - onPress={() => { - console.log(row.original.id); - }} - > - Start - - ); + return ; }, }, ]; diff --git a/components/scans/table/provider-scans/data-table-row-actions.tsx b/components/scans/table/provider-scans/data-table-row-actions.tsx new file mode 100644 index 0000000000..954a197e7d --- /dev/null +++ b/components/scans/table/provider-scans/data-table-row-actions.tsx @@ -0,0 +1,128 @@ +"use client"; + +import { + Button, + Dropdown, + DropdownItem, + DropdownMenu, + DropdownSection, + DropdownTrigger, +} from "@nextui-org/react"; +import { + AddNoteBulkIcon, + DeleteDocumentBulkIcon, + EditDocumentBulkIcon, +} from "@nextui-org/shared-icons"; +import { Row } from "@tanstack/react-table"; +import clsx from "clsx"; +import { useState } from "react"; + +import { AddIcon } from "@/components/icons"; +import { CustomAlertModal, CustomButton } from "@/components/ui/custom"; + +// import { EditForm } from "../forms"; +// import { DeleteForm } from "../forms/delete-form"; + +interface DataTableRowActionsProps { + row: Row; +} +const iconClasses = + "text-2xl text-default-500 pointer-events-none flex-shrink-0"; + +export function DataTableRowActions({ + row, +}: DataTableRowActionsProps) { + const [isEditOpen, setIsEditOpen] = useState(false); + const [isDeleteOpen, setIsDeleteOpen] = useState(false); + const providerId = (row.original as { id: string }).id; + return ( + <> + {/* + + */} + {/* + + */} + +
+ + + } + > + Start + + {/* */} + + + + } + > + {/* */} + + } + onClick={() => setIsEditOpen(true)} + > + Edit Provider + + + + + } + onClick={() => setIsDeleteOpen(true)} + > + Delete Provider + + + + +
+ + ); +} diff --git a/components/scans/table/provider-scans/index.ts b/components/scans/table/provider-scans/index.ts new file mode 100644 index 0000000000..415bafad0d --- /dev/null +++ b/components/scans/table/provider-scans/index.ts @@ -0,0 +1,2 @@ +export * from "./column-provider-scans"; +export * from "./data-table-row-actions"; diff --git a/components/ui/custom/custom-button.tsx b/components/ui/custom/custom-button.tsx index a74751801a..f5e408173c 100644 --- a/components/ui/custom/custom-button.tsx +++ b/components/ui/custom/custom-button.tsx @@ -1,6 +1,7 @@ import { Button, CircularProgress } from "@nextui-org/react"; import type { PressEvent } from "@react-types/shared"; import clsx from "clsx"; +import React from "react"; import { NextUIColors, NextUIVariants } from "@/types"; @@ -16,7 +17,7 @@ export const buttonClasses = { hover: "hover:shadow-md", }; -interface ButtonProps { +interface CustomButtonProps { type?: "button" | "submit" | "reset"; ariaLabel: string; ariaDisabled?: boolean; @@ -48,64 +49,76 @@ interface ButtonProps { disabled?: boolean; isLoading?: boolean; isIconOnly?: boolean; + ref?: React.RefObject; } -export const CustomButton = ({ - type = "button", - ariaLabel, - ariaDisabled, - className, - variant = "solid", - color = "primary", - onPress, - children, - startContent, - endContent, - size = "md", - radius = "sm", - disabled = false, - isLoading = false, - isIconOnly, - ...props -}: ButtonProps) => ( - + variant = "solid", + color = "primary", + onPress, + children, + startContent, + endContent, + size = "md", + radius = "sm", + disabled = false, + isLoading = false, + isIconOnly, + ...props + }, + ref, + ) => ( + + ), ); + +CustomButton.displayName = "CustomButton";