forked from MarkUsProject/Markus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstructor_table.jsx
More file actions
119 lines (111 loc) · 3.25 KB
/
instructor_table.jsx
File metadata and controls
119 lines (111 loc) · 3.25 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import React from "react";
import {createRoot} from "react-dom/client";
import PropTypes from "prop-types";
import ReactTable from "react-table";
import {selectFilter} from "./Helpers/table_helpers";
import {tableNoDataComponent} from "./table_no_data";
class InstructorTable extends React.Component {
constructor() {
super();
this.state = {
data: [],
counts: {all: 0, active: 0, inactive: 0},
loading: true,
};
this.fetchData = this.fetchData.bind(this);
}
componentDidMount() {
this.fetchData();
}
fetchData() {
fetch(Routes.course_instructors_path(this.props.course_id), {
headers: {
Accept: "application/json",
},
})
.then(response => {
if (response.ok) {
return response.json();
}
})
.then(res => {
this.setState({data: res.data, counts: res.counts, loading: false});
});
}
render() {
const {data} = this.state;
return (
<ReactTable
data={data}
columns={[
{
Header: I18n.t("activerecord.attributes.user.user_name"),
accessor: "user_name",
},
{
Header: I18n.t("activerecord.attributes.user.first_name"),
accessor: "first_name",
},
{
Header: I18n.t("activerecord.attributes.user.last_name"),
accessor: "last_name",
},
{
Header: I18n.t("activerecord.attributes.user.email"),
accessor: "email",
},
{
Header: I18n.t("roles.active") + "?",
accessor: "hidden",
Cell: ({value}) => (value ? I18n.t("roles.inactive") : I18n.t("roles.active")),
filterMethod: (filter, row) => {
if (filter.value === "all") {
return true;
} else {
return (
(filter.value === "active" && !row[filter.id]) ||
(filter.value === "inactive" && row[filter.id])
);
}
},
Filter: selectFilter,
filterOptions: [
{
value: "active",
text: `${I18n.t("roles.active")} (${this.state.counts.active})`,
},
{
value: "inactive",
text: `${I18n.t("roles.inactive")} (${this.state.counts.inactive})`,
},
],
filterAllOptionText: `${I18n.t("all")} (${this.state.counts.all})`,
},
{
Header: I18n.t("actions"),
accessor: "id",
Cell: data => (
<span>
<a href={Routes.edit_course_instructor_path(this.props.course_id, data.value)}>
{I18n.t("edit")}
</a>
</span>
),
sortable: false,
},
]}
filterable
loading={this.state.loading}
NoDataComponent={() => tableNoDataComponent(I18n.t("instructors.empty_table"))}
/>
);
}
}
InstructorTable.propTypes = {
course_id: PropTypes.number,
};
function makeInstructorTable(elem, props) {
const root = createRoot(elem);
root.render(<InstructorTable {...props} />);
}
export {makeInstructorTable, InstructorTable};