Skip to content

Commit

Permalink
feat(webb-ui): Pass table to row click handler, add single row expand…
Browse files Browse the repository at this point in the history
… for vaults table
  • Loading branch information
AtelyPham committed Feb 11, 2025
1 parent e883ce8 commit 91c7508
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
10 changes: 9 additions & 1 deletion apps/tangle-dapp/src/hooks/useVaultTableData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,16 @@ const useVaultTableData = ({

const tableProps = useMemo<ComponentProps<typeof VaultsTable>['tableProps']>(
() => ({
onRowClick(row) {
onRowClick(row, table) {
if (!row.getCanExpand()) return;

// Close all other rows
table.getRowModel().rows.forEach((r) => {
if (r.id !== row.id && r.getIsExpanded()) {
r.toggleExpanded(false);
}
});

return row.toggleExpanded();
},
getExpandedRowContent(row) {
Expand Down
4 changes: 2 additions & 2 deletions libs/webb-ui-components/src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ export const Table = <T extends RowData>({

return (eve: React.MouseEvent<HTMLTableRowElement>) => {
eve.preventDefault();
onRowClick(row);
onRowClick(row, table);
};
},
[onRowClick],
[onRowClick, table],
);

return (
Expand Down
4 changes: 2 additions & 2 deletions libs/webb-ui-components/src/components/Table/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Row, RowData, useReactTable } from '@tanstack/react-table';
import type { Row, RowData, Table, useReactTable } from '@tanstack/react-table';
import type {
IWebbComponentBase,
PropsOf,
Expand Down Expand Up @@ -82,7 +82,7 @@ export interface TableProps<T extends RowData, E extends HTMLElement>
/**
* Handle when the row is clicked
*/
onRowClick?: (row: Row<T>) => void;
onRowClick?: (row: Row<T>, table: Table<T>) => void;

/**
* The optional ref to forward to the table component
Expand Down

0 comments on commit 91c7508

Please sign in to comment.