import React from 'react'; import classNames from 'classnames'; import PropTypes from 'prop-types'; const exGrades = [ { assignment_type: 'Exam', total_possible: 6.0, total_earned: 3.0 }, { assignment_type: 'Homework', total_possible: 5.0, }, { assignment_type: 'Homework', total_possible: 11.0, total_earned: 0.0 } ]; class GradeTable extends React.Component { // eslint-disable-next-line no-useless-constructor constructor(props) { super(props); } getTableGroup(type, groupIndex) { const {grades} = this.props; // eslint-disable-next-line array-callback-return const groupData = grades.filter(value => { if (value.assignment_type === type) { return value; } }); const multipleAssignments = groupData.length > 1; const rows = groupData.map(({ assignment_type, total_possible, total_earned, passing_grade }, index) => { const label = multipleAssignments ? `${assignment_type} ${index + 1}` : assignment_type; return ( // eslint-disable-next-line react/no-array-index-key {label} {passing_grade}/{total_possible} {total_earned}/{total_possible} ); }); return rows.length ? {rows} : false; } render() { const {assignmentTypes, passingGrade, percentGrade} = this.props; return ( {assignmentTypes.map((type, index) => this.getTableGroup(type, index))}
Assignment Passing You
Total {passingGrade}% *{percentGrade}%
); } } GradeTable.propTypes = { // eslint-disable-next-line react/forbid-prop-types assignmentTypes: PropTypes.array.isRequired, // eslint-disable-next-line react/forbid-prop-types grades: PropTypes.array.isRequired, passingGrade: PropTypes.number.isRequired, percentGrade: PropTypes.number.isRequired }; export default GradeTable;