Skip to content

Commit

Permalink
feat: go to service view on row click
Browse files Browse the repository at this point in the history
  • Loading branch information
prosfus committed Nov 24, 2024
1 parent 9e2c01f commit 698d7a5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/components/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type ActionButton<T> = {
type GenericTableProps<T> = {
data: T[];
columns: ColumnDef<T>[];
onRowClick?: (item: T) => void;
actions?: ActionButton<T>[];
bulkActions?: ActionButton<T[]>[];
globalActions?: ActionButton<T[]>[];
Expand All @@ -51,6 +52,7 @@ function GenericTable<T extends object>({
actions,
bulkActions,
globalActions,
onRowClick,
idKey,
}: GenericTableProps<T>) {
const [selectedRows, setSelectedRows] = useState<Set<T[typeof idKey]>>(
Expand Down Expand Up @@ -175,11 +177,18 @@ function GenericTable<T extends object>({
</TableHeader>
<TableBody>
{paginatedData?.map((item, rowIndex) => (
<TableRow key={rowIndex}>
<TableRow
key={rowIndex}
onClick={() => onRowClick?.(item)}
className="cursor-pointer"
>
<TableCell>
<Checkbox
checked={selectedRows.has(item[idKey])}
onCheckedChange={() => toggleRow(item[idKey])}
onClick={(e) => {
e.stopPropagation();
toggleRow(item[idKey]);
}}
/>
</TableCell>
{columns.map((column, colIndex) => (
Expand All @@ -193,7 +202,9 @@ function GenericTable<T extends object>({
<TableCell>
<div className="flex justify-end items-center">
{actions.map((action, index) => (
<div key={index}>{action.button(item)}</div>
<div key={index} onClick={(e) => e.stopPropagation()}>
{action.button(item)}
</div>
))}
</div>
</TableCell>
Expand Down
4 changes: 4 additions & 0 deletions src/pages/ui/services/components/ServicesList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ function ServicesList() {
<GenericTable<Service>
data={filteredServices}
idKey="name"
onRowClick={(item) => {
setFormService(item);
navigate(`/ui/services/${item.name}/settings`);
}}
columns={[
{ header: "Name", accessor: "name" },
{ header: "Image", accessor: "image" },
Expand Down

0 comments on commit 698d7a5

Please sign in to comment.