forked from expertiza/reimplementation-front-end
/
ReviewTable.tsx
191 lines (179 loc) · 6.79 KB
/
ReviewTable.tsx
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import React, { useState } from 'react';
import ReviewTableRow from './ReviewTableRow';
import RoundSelector from './RoundSelector';
import dummyDataRounds from './Data/heatMapData.json'; // Ensure this import aligns with actual data structure
import dummyData from './Data/dummyData.json';
import { calculateAverages, getColorClass } from './utils';
import './grades.scss';
import { Link } from 'react-router-dom';
import ShowSubmission from './ShowSubmission';
import { ReviewData } from './App'; // Adjust the import path as necessary
const ReviewTable: React.FC = () => {
const [currentRound, setCurrentRound] = useState<number>(0);
const [sortOrderRow, setSortOrderRow] = useState<'asc' | 'desc' | 'none'>('none');
const [showWordCount10, setShowWordCount10] = useState(false);
const [showWordCount20, setShowWordCount20] = useState(false);
const [showFullQuestion, setShowFullQuestion] = useState(false);
const [showAll, setShowAll] = useState<boolean>(false);
const toggleSortOrderRow = () => {
setSortOrderRow((prevSortOrder) => {
if (prevSortOrder === 'asc') return 'desc';
if (prevSortOrder === 'desc') return 'none';
return 'asc';
});
};
// const currentRoundData = dummyDataRounds[currentRound];
const { averagePeerReviewScore } = showAll
? calculateAverages(dummyDataRounds, 'none')
: calculateAverages([dummyDataRounds[currentRound]], 'none');
const handleRoundChange = (roundIndex: number) => {
setCurrentRound(roundIndex);
setShowAll(false);
};
const showAllRounds = () => {
setShowAll(true);
};
const colorLegend = [
{ color: 'Red', description: 'Poor', className: 'c1' },
{ color: 'Orange', description: 'Fair', className: 'c2' },
{ color: 'Yellow', description: 'Average', className: 'c3' },
{ color: 'LightGreen', description: 'Good', className: 'c4' },
{ color: 'DarkGreen', description: 'Excellent', className: 'c5' },
];
const renderTableForRound = (roundData: ReviewData[], roundIndex: number) => {
const { columnAverages, sortedData } = calculateAverages([roundData], sortOrderRow);
return (
<>
<h4 className="text-xl font-semibold mb-1">Review (Round: {roundIndex + 1} of {dummyDataRounds.length})</h4>
<div className="table-container">
<table className="tbl_heat">
<thead>
<tr className="bg-gray-200">
<th className="py-2 px-4">Question No.</th>
{Array.from({ length: roundData[0].reviews.length }, (_, i) => (
<th key={i} className="py-2 px-4 text-center">{`Review ${i + 1}`}</th>
))}
<th className="py-2 px-4" onClick={toggleSortOrderRow}>
Avg
{sortOrderRow === "none" && <span>▲▼</span>}
{sortOrderRow === "asc" && <span>▲</span>}
{sortOrderRow === "desc" && <span>▼</span>}
</th>
{showWordCount10 && <th className="py-2 px-4 text-center">10+ Words</th>}
{showWordCount20 && <th className="py-2 px-4 text-center">20+ Words</th>}
</tr>
</thead>
<tbody>
{sortedData.map((row, index) => (
<ReviewTableRow
key={index}
row={row}
showWordCount10={showWordCount10}
showWordCount20={showWordCount20}
showFullQuestion={showFullQuestion}
/>
))}
<tr className="no-bg">
<td className="py-2 px-4">Avg</td>
{columnAverages.map((avg, index) => (
<td key={index} className="py-2 px-4 text-center">
{avg.toFixed(2)}
</td>
))}
</tr>
</tbody>
</table>
<br></br>
</div>
</>
);
};
return (
<div className="p-4">
<div className="review-container">
<div className="color-legend-container">
<span className="color-legend">
Color Legend
</span>
<div className="color-legend-table">
<table>
<thead>
<tr>
<th>Color</th>
<th>Rating</th>
</tr>
</thead>
<tbody>
{colorLegend.map((item) => (
<tr key={item.color}>
<td className={item.className}></td>
<td>{item.description}</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
</div>
<h2 className="text-2xl font-bold mb-2">Summary Report for assignment: Program 2</h2>
<h5 className="text-xl font-semibold mb-1">Team: {dummyData.team}</h5>
<h5 className="mb-4">
Average peer review score:{" "}
<span className={getColorClass(parseFloat(averagePeerReviewScore), 100)}>{averagePeerReviewScore}</span>
</h5>
<ShowSubmission />
<br></br>
<br></br>
<form>
<input
type="checkbox"
id="wordCount10"
name="wordCount10"
checked={showWordCount10}
onChange={(e) => setShowWordCount10(e.target.checked)}
/>
<label htmlFor="wordCount10"> Reviews with more than 10 words </label>
<input
type="checkbox"
id="wordCount20"
name="wordCount20"
checked={showWordCount20}
onChange={(e) => setShowWordCount20(e.target.checked)}
/>
<label htmlFor="wordCount20"> Reviews with more than 20 words</label>
<span> </span>
<input
type="checkbox"
id="viewQuestions"
name="viewQuestions"
checked={showFullQuestion}
onChange={(e) => setShowFullQuestion(e.target.checked)}
/>
<label htmlFor="showQuestions"> Show Review Questions</label>
</form>
<br></br>
{showAll ? (
<>
{dummyDataRounds.map((roundData, index) => (
<div key={index} className="mb-8">
{renderTableForRound(roundData, index)}
</div>
))}
</>
) : (
<div>
{renderTableForRound(dummyDataRounds[currentRound], currentRound)}
</div>
)}
<RoundSelector currentRound={currentRound} handleRoundChange={handleRoundChange} showAllRounds={showAllRounds} />
<p className="mt-4">
<h3>Grade and comment for submission</h3>
Grade: {dummyData.grade}<br></br>
Comment: {dummyData.comment}<br></br>
Late Penalty: {dummyData.late_penalty}<br></br>
</p>
<Link to="/">Back</Link>
</div>
);
};
export default ReviewTable;