Skip to content

Commit

Permalink
Allow custom css in table rows (#1410)
Browse files Browse the repository at this point in the history
* Allow custom css classes for table rows

* Add custom classname for table rows in ExecutionResults
  • Loading branch information
nelsonkopliku authored May 15, 2023
1 parent 2e40964 commit bee8a43
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
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 @@ -65,6 +65,7 @@ function Table({
const {
columns,
collapsibleDetailRenderer = undefined,
rowClassName = '',
pagination,
usePadding = true,
} = config;
Expand Down Expand Up @@ -187,6 +188,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

0 comments on commit bee8a43

Please sign in to comment.