Skip to content

Commit

Permalink
feat: add onClickRow prop for B3Table component (#174)
Browse files Browse the repository at this point in the history
* feat: turn product rows into clickable elements

* feat: implement clickable row on orders component

* fix: avoid redeclaration of styles
  • Loading branch information
bc-marco authored Mar 15, 2023
1 parent 1f9c494 commit 5108598
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 29 deletions.
3 changes: 3 additions & 0 deletions apps/storefront/src/components/table/B3PaginationTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ interface B3PaginationTableProps<T> {
labelRowsPerPage?: string,
itemIsMobileSpacing?: number,
disableCheckbox?: boolean,
onClickRow?: (item: any, index?: number) => void,
showRowsPerPageOptions?: boolean,
}

Expand Down Expand Up @@ -85,6 +86,7 @@ const PaginationTable:<T>(props: B3PaginationTableProps<T>) => ReactElement = ({
labelRowsPerPage = '',
itemIsMobileSpacing = 2,
disableCheckbox = false,
onClickRow,
showPagination = true,
showRowsPerPageOptions = true,
}, ref?: Ref<unknown>) => {
Expand Down Expand Up @@ -225,6 +227,7 @@ const PaginationTable:<T>(props: B3PaginationTableProps<T>) => ReactElement = ({
handleSelectOneItem={handleSelectOneItem}
showBorder={showBorder}
labelRowsPerPage={labelRowsPerPage}
onClickRow={onClickRow}
showPagination={showPagination}
showRowsPerPageOptions={showRowsPerPageOptions}
/>
Expand Down
9 changes: 9 additions & 0 deletions apps/storefront/src/components/table/B3Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,14 @@ interface TableProps<T> {
selectCheckbox?: Array<number | string>,
labelRowsPerPage?: string,
disableCheckbox?: boolean,
onClickRow?: (item: any, index?: number) => void,
showRowsPerPageOptions?: boolean,
}

const MOUSE_POINTER_STYLE = {
cursor: 'pointer',
}

export const B3Table:<T>(props: TableProps<T>) => ReactElement = ({
tableFixed = true,
columnItems,
Expand Down Expand Up @@ -102,13 +107,15 @@ export const B3Table:<T>(props: TableProps<T>) => ReactElement = ({
selectCheckbox = [],
labelRowsPerPage = '',
disableCheckbox = false,
onClickRow,
showRowsPerPageOptions = true,
}) => {
const {
offset,
count,
first,
} = pagination
const clickableRowStyles = typeof onClickRow === 'function' ? MOUSE_POINTER_STYLE : undefined

const handlePaginationChange = (pagination: Pagination) => {
if (!isLoading) {
Expand Down Expand Up @@ -298,6 +305,8 @@ export const B3Table:<T>(props: TableProps<T>) => ReactElement = ({
<TableRow
key={node[tableKey || 'id']}
hover={hover}
onClick={() => onClickRow?.(node, index)}
sx={clickableRowStyles}
>
{
showCheckbox && (
Expand Down
21 changes: 6 additions & 15 deletions apps/storefront/src/pages/order/Order.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,21 +182,6 @@ const Order = ({
{
key: 'orderId',
title: 'Order',
render: (item: ListItem, index: number) => (
<Box
component="span"
sx={{
cursor: 'pointer',
'&:hover': {
textDecoration: 'underline',
},
}}
onClick={() => goToDetail(item, index)}
>
{item.orderId}
</Box>
),
width: '10%',
},
{
key: 'poNumber',
Expand Down Expand Up @@ -333,6 +318,12 @@ const Order = ({
isCompanyOrder={isCompanyOrder}
/>
)}
onClickRow={(item: ListItem, index?: number) => {
if (index !== undefined) {
goToDetail(item, index)
}
}}
hover
/>
</Box>
</B3Sping>
Expand Down
18 changes: 4 additions & 14 deletions apps/storefront/src/pages/quote/QuotesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,20 +257,6 @@ const QuotesList = () => {
{
key: 'quoteNumber',
title: 'Quote #',
render: (item: ListItem) => (
<Box
component="span"
sx={{
cursor: 'pointer',
'&:hover': {
textDecoration: 'underline',
},
}}
onClick={() => goToDetail(item, +item.status)}
>
{item.quoteNumber}
</Box>
),
},
{
key: 'quoteTitle',
Expand Down Expand Up @@ -393,6 +379,10 @@ const QuotesList = () => {
goToDetail={goToDetail}
/>
)}
onClickRow={(row: ListItem) => {
goToDetail(row, +row.status)
}}
hover
/>
</Box>
</B3Sping>
Expand Down

0 comments on commit 5108598

Please sign in to comment.