diff --git a/client/src/components/generic/ReusableTable/Table.story.tsx b/client/src/components/generic/ReusableTable/Table.story.tsx index a118e12c6..a87b7a0a0 100644 --- a/client/src/components/generic/ReusableTable/Table.story.tsx +++ b/client/src/components/generic/ReusableTable/Table.story.tsx @@ -13,9 +13,10 @@ type Story = StoryObj export const FullTable: Story = { decorators: [(Story) => ], args: { + onRowClick: (id) => console.log("table row clicked", id), data: [ { - uid: "", + uid: "John", Name: "John Doe", Email: "john.doe@example.com", Status: "Member", @@ -23,7 +24,7 @@ export const FullTable: Story = { "Date Joined": "12-7-22" }, { - uid: "", + uid: "Straight Zhao", Name: "Ray Zhao", Email: "ray.zhao@example.com", Status: "Superior Controller", @@ -31,7 +32,7 @@ export const FullTable: Story = { "Date Joined": "12-7-22" }, { - uid: "", + uid: "Doeshin", Name: "Johnathan Doeshin", Email: "jondoe@gmail.com", Status: "Member", @@ -134,6 +135,7 @@ export const MultipleOperations = () => {

Last deleted id: {deleteMessage}

data={data} + onRowClick={() => alert("Row Callback")} operationType="multiple-operations" rowOperations={[ { diff --git a/client/src/components/generic/ReusableTable/Table.tsx b/client/src/components/generic/ReusableTable/Table.tsx index c1724c232..8cbd58a0a 100644 --- a/client/src/components/generic/ReusableTable/Table.tsx +++ b/client/src/components/generic/ReusableTable/Table.tsx @@ -32,6 +32,14 @@ interface ITable< * Pass in a callback for when the last page of the table is reached (i.e go to the next offset if paginating) */ onPageChange?: (isLastPage: boolean) => void + /** + * **Optional** callback for when a row is clicked. + * + * @param uid the identifier for the row, typically an id associated with a user + * @example + * onRowClick={(uid) => openEditPanelForUid(uid)} + */ + onRowClick?: (uid: string) => void /** * decides if clicking on the row options will give multiple options or a single one */ @@ -154,6 +162,7 @@ const Table = < operationType = "none", rowOperations, onPageChange, + onRowClick, groupSameRows = false }: ITable) => { // Needs to be zero-indexed @@ -220,12 +229,15 @@ const Table = < currentGroup % 2 === 0 ? "" : "text-dark-blue-100 font-bold" return ( - + {dataKeys.map((key) => { return ( { + onRowClick?.(obj[TABLE_ROW_IDENTIFIER_KEY]) + }} className={`break-keep pb-2 pl-4 pt-2 - ${groupSameRows && rowClass}`} + ${groupSameRows && rowClass} ${!!onRowClick && "cursor-pointer"}`} key={key} > {obj[key] || ""} @@ -240,7 +252,14 @@ const Table = < ) }) - }, [operationType, rowOperations, dataKeys, currentDataSlice, groupSameRows]) + }, [ + operationType, + rowOperations, + dataKeys, + currentDataSlice, + groupSameRows, + onRowClick + ]) return (