Skip to content

Commit 2782d8b

Browse files
committed
see changelog.md [0.1.0] - 05-07-2019
1 parent c6d584c commit 2782d8b

16 files changed

Lines changed: 724 additions & 27 deletions

docs/CHANGELOG.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
- __Fixed__ for any bug fixes.
1212
- __Security__ in case of vulnerabilities.
1313

14-
## [0.1.0] - 03-06-2019
14+
## [0.1.0] - 05-07-2019
1515
###Changed
16-
-
16+
- from form to table I will eventually add react-route-dom and have linking pages
17+
- datatable has been broken up into smaller components
18+
19+
### Added
20+
- new components to work on changing to a hook style compnonent
21+
- Table component only sorts one way at the moment
22+
- css style and responsive styles
23+
- usewindowwidth hook
1724

1825
### Added
1926
- Ability to test components

package-lock.json

Lines changed: 18 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6+
"eslint-plugin-react-hooks": "^1.6.1",
67
"react": "^16.8.6",
78
"react-dom": "^16.8.6",
89
"react-scripts": "3.0.1"
@@ -29,12 +30,20 @@
2930
]
3031
},
3132
"jest": {
32-
"snapshotSerializers": ["enzyme-to-json/serializer"]
33+
"snapshotSerializers": [
34+
"enzyme-to-json/serializer"
35+
]
3336
},
3437
"devDependencies": {
35-
"enzyme": "^3.9.0",
36-
"enzyme-adapter-react-16": "^1.13.2",
38+
"enzyme": "^3.10.0",
39+
"enzyme-adapter-react-16": "^1.14.0",
3740
"enzyme-to-json": "^3.3.5"
41+
},
42+
"plugins": [
43+
"react-hooks"
44+
],
45+
"rules": {
46+
"react-hooks/rules-of-hooks": "error"
3847
},
3948
"author": {
4049
"name": "Rory Fairweather-Neylan",

src/App.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import React from 'react';
22

33
//Components
44
import Form from "./Components/form";
5+
import Table from "./Components/Data-Table/dataTable";
56

67
function App() {
78
return (
89
<div className="App">
9-
<Form />
10+
<Table />
1011
</div>
1112
);
1213
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import React, { useState, useMemo } from "react";
2+
3+
//Hooks
4+
import useFetch from "../../Hooks/useFetch";
5+
6+
//Components
7+
import TableHeaders from "./table-headers";
8+
import TableRows from "./table-row";
9+
10+
const Table = () => {
11+
const [error, data, loading] = useFetch("https://jsonplaceholder.typicode.com/comments");// <- initialValue
12+
const [key, setKey] = useState(null);
13+
const [order, setOrder] = useState({key: "asc"});
14+
15+
const columnSort = useMemo(() => {
16+
if (!key) {
17+
return data;
18+
}
19+
let newData = data.sort((a, b) => (order[key] === "asc" ? a[key] > b[key] : b[key] > a[key]));
20+
console.log("TCL: columnSort -> order[key]", order[key])
21+
22+
//setOrder(order[key] === "asc" ? "desc" : "asc");
23+
return newData;
24+
}, [data, key]);
25+
26+
if (error) {
27+
return (
28+
<div>
29+
{error}
30+
</div>
31+
);
32+
}
33+
if (loading) {
34+
return (
35+
<div id="preload-wrapper">
36+
<div id="loader"></div>
37+
</div>
38+
);
39+
}
40+
41+
const TableContent = data && columnSort.map((item, key) => {
42+
return (
43+
<TableRows
44+
key={key}
45+
columns={columns}
46+
data={item}
47+
/>
48+
);
49+
})
50+
51+
return (
52+
<table className="dataTable">
53+
<TableHeaders columns={columns} columnSort={setKey} />
54+
{TableContent}
55+
</table>
56+
);
57+
}
58+
59+
export default Table;
60+
61+
62+
const columns = [
63+
{
64+
Header: "Id",
65+
Value: "id",
66+
sortOn: "id",
67+
childItem: null,
68+
}, {
69+
Header: "Name",
70+
Value: "name",
71+
sortOn: "name",
72+
childItem: null,
73+
}, {
74+
Header: "Email",
75+
Value: "email",
76+
sortOn: "email",
77+
childItem: null,
78+
}, {
79+
Header: "postId",
80+
Value: "postId",
81+
sortOn: "postId",
82+
childItem: null,
83+
}, {
84+
Header: "Comment",
85+
Value: "body",
86+
sortOn: "bodys",
87+
childItem: [
88+
{
89+
Value: "body",
90+
},
91+
]
92+
},
93+
]
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React from "react";
2+
3+
//Hooks
4+
import useWindowWidth from "../../Hooks/useWindowWidth";
5+
6+
const TableHeaders = ({ columns, columnSort }) => {
7+
const width = useWindowWidth();
8+
9+
if (width > 760) {
10+
return (
11+
<tbody>
12+
<tr className="header-tr">
13+
{
14+
columns.map((column, key) => {
15+
return (
16+
<th key={key} className={column.Value} onClick={() => columnSort(column.sortOn)}>
17+
{column.Header}
18+
</th>
19+
);
20+
})
21+
}
22+
</tr>
23+
</tbody>
24+
);
25+
} else {
26+
return (<div />);
27+
}
28+
}
29+
30+
export default TableHeaders;
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import React from 'react';
2+
3+
//Hooks
4+
import useFetch from "../../Hooks/useFetch";
5+
//Components
6+
import TreeItem from "./tree-item";
7+
8+
const TableRows = ({ data, columns }) => {
9+
10+
/*const IsInternalIcon = data.Icon.IsInternalIcon;
11+
12+
let linkVal;
13+
if (IsInternalIcon) {
14+
linkVal = <img src={"/Content/icons/" + data.IconText + "_x16.png"} />;
15+
} else {
16+
linkVal = <img src={"/Content/icons/" + data.Icon.FileType + "_x16.png"} />;
17+
}
18+
19+
let expandVal;
20+
if (data.IsContainer && data.Collapse) {
21+
expandVal = " + ";
22+
} else if (data.IsContainer && !data.Collapse) {
23+
expandVal = " - ";
24+
} else {
25+
expandVal = null;
26+
}
27+
const treeItems = !data.Items ? loading && !data.Collapse : treeData.Items !== null && data.IsContainer !== null && !data.Collapse ? data.Items.map((record, key) => {
28+
return (
29+
<TreeItem columns={columns} data={record} IsInternalIcon={IsInternalIcon} linkVal={linkVal} key={key} getDescendantProp={getDescendantProp}>
30+
{
31+
columns.map((column, key) => {
32+
return (
33+
<td className="treeitem" key={key}>
34+
{getDescendantProp(record, column.Value)}
35+
</td>
36+
);
37+
})
38+
}
39+
</TreeItem>
40+
);
41+
}) : null*/
42+
return (
43+
<tbody>
44+
<tr className="tableRow">
45+
{
46+
columns.map((column, key) => {
47+
return (
48+
<td className="treeitem" key={key} >
49+
{getDescendantProp(data, column.Value)}
50+
</td>
51+
);
52+
})
53+
}
54+
</tr>
55+
</tbody>
56+
);
57+
}
58+
59+
export default TableRows;
60+
61+
const getDescendantProp = (obj, desc) => {
62+
var arr = desc.split('.');
63+
while (arr.length && (obj = obj[arr.shift()]));
64+
return obj;
65+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from 'react';
2+
3+
const TreeItem = ({ columns, data, linkVal, getDescendantProp }) => {
4+
return (
5+
<tr>
6+
<td>
7+
<div className="expand">
8+
{linkVal}
9+
</div>
10+
</td>
11+
{
12+
columns.map((column, key) => {
13+
return (
14+
<td className="treeitem" key={key} >
15+
{getDescendantProp(data, column.Value )}
16+
</td>
17+
);
18+
})
19+
}
20+
</tr>
21+
);
22+
}
23+
24+
export default TreeItem;

0 commit comments

Comments
 (0)