Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Revert "Assessments: Add color to multiple choice assessments table"" #23553

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 20 additions & 5 deletions apps/src/templates/sectionAssessments/MultipleChoiceAnswerCell.jsx
Expand Up @@ -9,30 +9,45 @@ const styles = {
justifyContent: 'space-between',
flexDirection: 'row',
alignItems: 'center',
height: '100%',
},
overviewMain: {
padding: 10,
},
icon: {
color: color.level_perfect,
},
text: {
value: {
color: color.charcoal,
fontFamily: '"Gotham 5r", sans-serif',
marginRight: 10,
},
};

function calculateOpacity(answered) {
return (answered + 10)/100;
}

class MultipleChoiceAnswerCell extends Component {
static propTypes = {
percentValue: PropTypes.number.isRequired,
isCorrectAnswer: PropTypes.bool,
displayAnswer: PropTypes.string,
isSurvey: PropTypes.bool,
};

render() {
const {percentValue, isCorrectAnswer, displayAnswer} = this.props;
const {percentValue, isCorrectAnswer, displayAnswer, isSurvey} = this.props;

const opacity = calculateOpacity(percentValue);

const backgroundCSS = (isCorrectAnswer || isSurvey) ? {backgroundColor: `rgba(159, 212, 159, ${opacity})`} :
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could pull the logic on lines 42-45 into a function like this:

getBackgroundColor = (percentValue) => {
  const {isCorrectAnswer, isSurvey} = this.props;
  const opacity = calculateOpacity(percentValue);
  return (isCorrectAnswer || isSurvey) ? `rgba(159, 212, 159, ${opacity})` : `rgba(255, 99, 71, ${opacity})`;
};

then plug that into: const backgroundCSS = {backgroundColor: getBackgroundColor(percentValue}; to clarify the logic here a little. not a blocker, but something to consider

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea, will follow up.

{backgroundColor: `rgba(255, 99, 71, ${opacity})`};

if (displayAnswer) {
return (
<div style={styles.main}>
<div style={styles.text}>
<div style={styles.value}>
{displayAnswer}
</div>
<div style={styles.icon}>
Expand All @@ -45,8 +60,8 @@ class MultipleChoiceAnswerCell extends Component {
}

return (
<div style={styles.main}>
<div style={styles.text}>
<div style={{...styles.main, ...backgroundCSS, ...styles.overviewMain}}>
<div style={styles.value}>
{(percentValue >= 0) &&
<span>{`${percentValue}%`}</span>
}
Expand Down
Expand Up @@ -22,6 +22,12 @@ const styles = {
},
answerColumnCell: {
width: ANSWER_COLUMN_WIDTH,
padding: 0,
height: 40,
},
notAnsweredCell: {
padding: 0,
height: 40,
},
questionCell: {
overflow: 'hidden',
Expand Down Expand Up @@ -107,7 +113,12 @@ class MultipleChoiceAssessmentsOverviewTable extends Component {
},
cell: {
format: answerColumnsFormatter,
props: {style: tableLayoutStyles.cell},
props: {
style: {
...tableLayoutStyles.cell,
...styles.notAnsweredCell,
}
},
}
}
);
Expand Down
Expand Up @@ -21,12 +21,18 @@ const styles = {
},
answerColumnCell: {
width: ANSWER_COLUMN_WIDTH,
padding: 0,
height: 40,
},
questionCell: {
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
}
},
notAnsweredCell: {
padding: 0,
height: 40,
},
};

const NOT_ANSWERED = 'notAnswered';
Expand All @@ -46,6 +52,7 @@ const answerColumnsFormatter = (percentAnswered, {rowData, columnIndex, rowIndex
<MultipleChoiceAnswerCell
id={rowData.id}
percentValue={percentValue}
isSurvey={true}
/>
);
};
Expand Down Expand Up @@ -118,7 +125,12 @@ class MultipleChoiceSurveyOverviewTable extends Component {
},
cell: {
format: answerColumnsFormatter,
props: {style: tableLayoutStyles.cell},
props: {
style: {
...tableLayoutStyles.cell,
...styles.notAnsweredCell,
}
},
}
}
);
Expand Down
Expand Up @@ -89,7 +89,7 @@ class SingleStudentAssessmentsMCTable extends Component {
return (
<MultipleChoiceAnswerCell
id={rowData.id}
displayAnswer={studentAnswer.responses}
displayAnswer={studentAnswer.responses || '-'}
isCorrectAnswer={studentAnswer.isCorrect}
/>
);
Expand Down