From 698d7a55ba3e114771f29077af7ee9d8dbfe06e5 Mon Sep 17 00:00:00 2001 From: prosfus Date: Sun, 24 Nov 2024 17:21:59 +0100 Subject: [PATCH] feat: go to service view on row click --- src/components/Table/index.tsx | 17 ++++++++++++++--- .../services/components/ServicesList/index.tsx | 4 ++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/components/Table/index.tsx b/src/components/Table/index.tsx index 4a6cd37..6c9d938 100644 --- a/src/components/Table/index.tsx +++ b/src/components/Table/index.tsx @@ -39,6 +39,7 @@ type ActionButton = { type GenericTableProps = { data: T[]; columns: ColumnDef[]; + onRowClick?: (item: T) => void; actions?: ActionButton[]; bulkActions?: ActionButton[]; globalActions?: ActionButton[]; @@ -51,6 +52,7 @@ function GenericTable({ actions, bulkActions, globalActions, + onRowClick, idKey, }: GenericTableProps) { const [selectedRows, setSelectedRows] = useState>( @@ -175,11 +177,18 @@ function GenericTable({ {paginatedData?.map((item, rowIndex) => ( - + onRowClick?.(item)} + className="cursor-pointer" + > toggleRow(item[idKey])} + onClick={(e) => { + e.stopPropagation(); + toggleRow(item[idKey]); + }} /> {columns.map((column, colIndex) => ( @@ -193,7 +202,9 @@ function GenericTable({
{actions.map((action, index) => ( -
{action.button(item)}
+
e.stopPropagation()}> + {action.button(item)} +
))}
diff --git a/src/pages/ui/services/components/ServicesList/index.tsx b/src/pages/ui/services/components/ServicesList/index.tsx index 117d938..c4dfd96 100644 --- a/src/pages/ui/services/components/ServicesList/index.tsx +++ b/src/pages/ui/services/components/ServicesList/index.tsx @@ -95,6 +95,10 @@ function ServicesList() { data={filteredServices} idKey="name" + onRowClick={(item) => { + setFormService(item); + navigate(`/ui/services/${item.name}/settings`); + }} columns={[ { header: "Name", accessor: "name" }, { header: "Image", accessor: "image" },