forked from nikhilpim/Radio
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFeedbackTable.js
More file actions
81 lines (72 loc) · 2.67 KB
/
FeedbackTable.js
File metadata and controls
81 lines (72 loc) · 2.67 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
import React, {Component} from 'react';
import {SimpleTable, Styles} from '../../common/SimpleTable'
import ModalBox from './ModalBox';
import './styles.css';
class FeedbackTable extends Component {
constructor(props) {
super(props);
this.state = {
displayModal: false,
feedbackData: null,
}
this.hideModalBox = this.hideModalBox.bind(this);
}
displayModalBox() {
this.setState({displayModal: true});
}
hideModalBox() {
this.setState({displayModal: false});
}
render () {
const columns = [
{Header: 'Delegation', accessor: 'country',},
{Header: 'Times Spoken', accessor: 'times',},
{Header: 'Feedback', accessor: 'feedback',},
];
const tableData = this.props.feedback.map(f => {
return {
country: f['country'],
times: f['feedback'].length,
feedback: f['feedback'] ? f['feedback'][0]['comments'] : '',
};
});
return (<div>
{this.state.displayModal && this.state.feedbackData ?
<ModalBox
feedback={this.state.feedbackData}
onClose={this.hideModalBox}
/>
: null
}
<Styles>
<SimpleTable
columns={columns}
data={tableData}
getTdProps={(state, rowInfo, column, instance) => {
return {
onClick: (e, handleOriginal) => {
if (rowInfo && 'row' in rowInfo && !this.state.displayModal) {
const country = rowInfo['row']['country'];
const filteredFeedback = this.props.feedback.filter(f => f['country'] === country);
if (filteredFeedback === []) {
return;
}
const feedbackData = filteredFeedback[0];
console.log(feedbackData);
this.setState({feedbackData: feedbackData});
this.displayModalBox();
if (handleOriginal) {
handleOriginal()
}
} else if (this.state.displayModal) {
this.hideModalBox();
}
}
}
}}
/>
</Styles>
</div>)
}
}
export default FeedbackTable;