Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/ui-components/src/stories/data-table.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ export const WithFetcher: Story = {
},
};

export const MutedBackground: Story = {
args: {
loading: false,
cellClassName: 'bg-muted',
},
};

export const StickyHeader: Story = {
args: {
loading: false,
Expand Down
58 changes: 37 additions & 21 deletions packages/ui-components/src/ui/data-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ interface DataTableProps<
actions?: DataTableAction<TData>[];
stickyHeader?: boolean;
border?: boolean;
cellClassName?: string;
emptyStateComponent?: React.ReactNode;
getRowHref?: (row: RowDataWithActions<TData>) => string | undefined;
navigationExcludedColumns?: string[];
Expand All @@ -122,6 +123,7 @@ export function DataTable<
onSelectedRowsChange,
stickyHeader = false,
border = true,
cellClassName,
emptyStateComponent,
getRowHref,
navigationExcludedColumns,
Expand Down Expand Up @@ -329,8 +331,12 @@ export function DataTable<
{table.getHeaderGroups().map((headerGroup) => (
<TableRow key={headerGroup.id}>
{headerGroup.headers.map((header) => {
const meta = header.column.columnDef.meta as
| { className?: string }
| undefined;
Comment on lines +334 to +336
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code was in the ee version, I didn't add it.


return (
<TableHead key={header.id}>
<TableHead key={header.id} className={meta?.className}>
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only change I've added

{header.isPlaceholder
? null
: flexRender(
Expand Down Expand Up @@ -364,28 +370,38 @@ export function DataTable<
className={onRowClick ? 'cursor-pointer' : ''}
data-state={row.getIsSelected() && 'selected'}
>
{row.getVisibleCells().map((cell) => (
<TableCell key={cell.id}>
{rowHref &&
!navigationExcludedColumns?.includes(cell.column.id) ? (
<Link
to={rowHref}
onClick={(e) => e.stopPropagation()}
rel="noopener noreferrer"
>
{flexRender(
{row.getVisibleCells().map((cell) => {
const meta = cell.column.columnDef.meta as
| { className?: string }
| undefined;
return (
<TableCell
key={cell.id}
className={cn(meta?.className, cellClassName)}
>
{rowHref &&
!navigationExcludedColumns?.includes(
cell.column.id,
) ? (
<Link
to={rowHref}
onClick={(e) => e.stopPropagation()}
rel="noopener noreferrer"
>
{flexRender(
cell.column.columnDef.cell,
cell.getContext(),
)}
</Link>
) : (
flexRender(
cell.column.columnDef.cell,
cell.getContext(),
)}
</Link>
) : (
flexRender(
cell.column.columnDef.cell,
cell.getContext(),
)
)}
</TableCell>
))}
)
)}
</TableCell>
);
})}
</TableRow>
);
})
Expand Down
Loading