Skip to content

Commit 192c0ab

Browse files
Sean PrashadSean Prashad
authored andcommitted
Add Table component
This is a wrapper component for react-table, in order to declutter the project structure.
1 parent c27a121 commit 192c0ab

File tree

5 files changed

+112
-134
lines changed

5 files changed

+112
-134
lines changed

web/src/components/App.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import React from 'react';
33
import './styles.scss';
44

55
import Navigation from './Navigation';
6-
import DataGrid from './DataGrid';
6+
import Table from './Table';
77

88
function App() {
99
return (
1010
<div className="App">
1111
<Navigation />
12-
<DataGrid />
12+
<Table />
1313
</div>
1414
);
1515
}

web/src/components/DataGrid/index.js

Lines changed: 0 additions & 127 deletions
This file was deleted.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import React from 'react';
2+
import { Table } from 'reactstrap';
3+
import { useTable, useSortBy } from 'react-table';
4+
5+
function ReactTable({ columns, data }) {
6+
const {
7+
getTableProps,
8+
getTableBodyProps,
9+
headerGroups,
10+
rows,
11+
prepareRow,
12+
} = useTable(
13+
{
14+
columns,
15+
data,
16+
},
17+
useSortBy,
18+
);
19+
20+
return (
21+
<Table align="center" {...getTableProps()}>
22+
<thead>
23+
{headerGroups.map(headerGroup => (
24+
<tr {...headerGroup.getHeaderGroupProps()}>
25+
{headerGroup.headers.map(column => (
26+
<th {...column.getHeaderProps(column.getSortByToggleProps())}>
27+
{column.render('Header')}
28+
<span>
29+
{column.isSorted ? (column.isSortedDesc ? ' 🔽' : ' 🔼') : ''}
30+
</span>
31+
</th>
32+
))}
33+
</tr>
34+
))}
35+
</thead>
36+
37+
<tbody {...getTableBodyProps()}>
38+
{rows.map(row => {
39+
prepareRow(row);
40+
return (
41+
<tr {...row.getRowProps()}>
42+
{row.cells.map(cell => {
43+
return <td {...cell.getCellProps()}>{cell.render('Cell')}</td>;
44+
})}
45+
</tr>
46+
);
47+
})}
48+
</tbody>
49+
</Table>
50+
);
51+
}
52+
53+
export default ReactTable;

web/src/components/Table/index.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import React from 'react';
2+
import { Container, Row, Col } from 'reactstrap';
3+
import ReactTable from '../ReactTable';
4+
5+
import questionList from '../../data';
6+
7+
import './styles.scss';
8+
9+
const Table = () => {
10+
const data = React.useMemo(() => questionList, []);
11+
12+
const columns = React.useMemo(
13+
() => [
14+
{
15+
Header: 'Name',
16+
columns: [
17+
{
18+
Header: '#',
19+
accessor: 'id',
20+
},
21+
{
22+
Header: 'Question Name',
23+
accessor: 'name',
24+
},
25+
{
26+
Header: 'URL',
27+
accessor: 'url',
28+
},
29+
{
30+
Header: 'Pattern',
31+
accessor: 'pattern',
32+
},
33+
{
34+
Header: 'Companies',
35+
accessor: 'companies',
36+
},
37+
],
38+
},
39+
],
40+
[],
41+
);
42+
43+
return (
44+
<Container className="table">
45+
<Col>
46+
<Row>
47+
<Col>
48+
<ReactTable columns={columns} data={data} />
49+
</Col>
50+
</Row>
51+
</Col>
52+
</Container>
53+
);
54+
};
55+
56+
export default Table;

web/src/components/DataGrid/styles.scss renamed to web/src/components/Table/styles.scss

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
.datagrid {
2-
display: flex;
3-
align-items: center;
4-
justify-content: center;
5-
1+
.table {
62
> .col {
73
padding: 100px 0 100px 0;
84
}

0 commit comments

Comments
 (0)