Skip to content

Commit

Permalink
Simplify table
Browse files Browse the repository at this point in the history
  • Loading branch information
csillag committed Jan 22, 2025
1 parent 2d15e22 commit 7dfabb1
Showing 1 changed file with 47 additions and 51 deletions.
98 changes: 47 additions & 51 deletions src/app/components/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,73 +113,69 @@ export const Table: FC<TableProps> = ({
}) => {
const { isMobile } = useScreenSize()

const isEmpty = !isLoading && !rows?.length

if (isEmpty && !emptyMessage) {
return null
}

return (
return !isLoading && !rows?.length ? ( // This is known to be empty
emptyMessage ? ( // If we have a message, show it
<CardEmptyState label={emptyMessage} />
) : null // otherwise just show nothing
) : (
<>
{!isEmpty && (
<TableContainer>
<MuiTable aria-label={name}>
<TableHead>
<TableRow>
{columns.map((column, index) => {
if (column.hide) {
<TableContainer>
<MuiTable aria-label={name}>
<TableHead>
<TableRow>
{columns.map((column, index) => {
if (column.hide) {
return null
}
return (
<TableCell
key={column.key}
align={column.align}
sx={{
width: column.width || 'auto',
...(stickyColumn && !index && isMobile ? stickyColumnStyles : {}),
}}
>
{column.content}
</TableCell>
)
})}
</TableRow>
</TableHead>
<TableBody>
{(alwaysWaitWhileLoading || !rows) && isLoading && (
<SkeletonTableRows rowsNumber={rowsNumber} columnsNumber={columns.length} />
)}
{rows?.map(row => (
<StyledTableRow key={row.key} highlight={row.highlight}>
{row.data.map((cell, index) => {
if (cell.hide) {
return null
}
return (
<TableCell
key={column.key}
align={column.align}
key={cell.key}
align={cell.align}
sx={{
width: column.width || 'auto',
...(stickyColumn && !index && isMobile ? stickyColumnStyles : {}),
...(extraHorizontalSpaceOnMobile && isMobile ? extraHorizontalPaddingStyles : {}),
}}
>
{column.content}
{cell.content}
</TableCell>
)
})}
</TableRow>
</TableHead>
<TableBody>
{(alwaysWaitWhileLoading || !rows) && isLoading && (
<SkeletonTableRows rowsNumber={rowsNumber} columnsNumber={columns.length} />
)}
{rows?.map(row => (
<StyledTableRow key={row.key} highlight={row.highlight}>
{row.data.map((cell, index) => {
if (cell.hide) {
return null
}
return (
<TableCell
key={cell.key}
align={cell.align}
sx={{
...(stickyColumn && !index && isMobile ? stickyColumnStyles : {}),
...(extraHorizontalSpaceOnMobile && isMobile ? extraHorizontalPaddingStyles : {}),
}}
>
{cell.content}
</TableCell>
)
})}
</StyledTableRow>
))}
</TableBody>
</MuiTable>
</TableContainer>
)}
{!isEmpty && pagination && (
</StyledTableRow>
))}
</TableBody>
</MuiTable>
</TableContainer>

{pagination && (
<Box sx={{ display: 'flex', justifyContent: 'center' }}>
<TablePagination {...pagination} />
</Box>
)}
{isEmpty && emptyMessage && <CardEmptyState label={emptyMessage} />}
</>
)
}

0 comments on commit 7dfabb1

Please sign in to comment.