-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
77 lines (66 loc) · 1.63 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import React, { Component, PropTypes } from "react";
import {
Table,
TableBody,
TableFooter,
TableHeader,
TableRow
} from "material-ui/Table";
import {
generateColumns,
generateRows
} from "../../../utilities/datatable-utilities";
import { dataTableStyles } from "../../../constants/mui-theme";
import {
fetchDatatableData,
fetchDatatableColumns
} from "../../../actions/datatable-actions";
import { connect } from "react-redux";
class DataTable extends Component {
constructor(props) {
super(props);
this.state = {};
}
componentWillMount() {
const { dataType } = this.props;
this.props.fetchDatatableData(dataType);
this.props.fetchDatatableColumns(dataType);
}
render() {
const rows = this.props.rows[this.props.dataType];
const cols = this.props.columns[this.props.dataType];
return (
<Table {...this.props.tableStyles}>
<TableHeader>
<TableRow>
{generateColumns(cols)}
</TableRow>
</TableHeader>
<TableBody>
{generateRows(cols, rows)}
</TableBody>
<TableFooter />
</Table>
);
}
}
DataTable.propTypes = {
dataType: PropTypes.string,
tableStyles: PropTypes.object,
rows: PropTypes.object,
columns: PropTypes.object,
fetchDatatableData: PropTypes.func,
fetchDatatableColumns: PropTypes.func
};
DataTable.defaultProps = {
tableStyles: dataTableStyles
};
const mapStateToProps = state => {
const { dataTables } = state;
return dataTables;
};
export default connect(mapStateToProps, {
fetchDatatableData,
fetchDatatableColumns
})(DataTable);
export { DataTable as PureDataTable};