Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom css in table rows #1410

Merged
merged 2 commits into from
May 15, 2023
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
1 change: 1 addition & 0 deletions assets/js/components/ExecutionResults/ExecutionResults.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import ExecutionContainer from './ExecutionContainer';

const resultsTableConfig = {
usePadding: false,
rowClassName: 'tn-check-result-row',
columns: [
{
title: 'Id',
Expand Down
6 changes: 5 additions & 1 deletion assets/js/components/Table/CollapsibleTableRow.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import React, { Fragment, useState } from 'react';
import classNames from 'classnames';

function CollapsibleTableRow({
columns,
item,
collapsibleDetailRenderer,
renderCells = () => {},
colSpan = 1,
className,
}) {
const [rowExpanded, toggleRow] = useState(false);

return (
<>
<tr
className={collapsibleDetailRenderer ? 'cursor-pointer' : ''}
className={classNames(className, {
'cursor-pointer': !!collapsibleDetailRenderer,
})}
onClick={() => {
if (collapsibleDetailRenderer) {
toggleRow(!rowExpanded);
Expand Down
2 changes: 2 additions & 0 deletions assets/js/components/Table/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ function Table({
const {
columns,
collapsibleDetailRenderer = undefined,
rowClassName = '',
pagination,
usePadding = true,
} = config;
Expand Down Expand Up @@ -182,6 +183,7 @@ function Table({
renderCells={renderCells}
columns={columns}
colSpan={columns.length}
className={rowClassName}
/>
))
)}
Expand Down
18 changes: 18 additions & 0 deletions assets/js/components/Table/Table.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@ describe('Table component', () => {
column3: faker.animal.dog(),
}));

it('should allow custom classes for table rows', () => {
const data = tableDataFactory.buildList(10);
const customRowClassName = 'custom-row-classname';

render(
<Table
config={{ rowClassName: customRowClassName, ...tableConfig }}
data={data}
setSearchParams={() => {}}
/>
);

screen
.getByRole('table')
.querySelectorAll('tbody > tr')
.forEach((tableRow) => expect(tableRow).toHaveClass(customRowClassName));
});

describe('filtering', () => {
it('should filter by the chosen filter option with default filter', async () => {
const data = tableDataFactory.buildList(10);
Expand Down