Skip to content

Commit 0c347e9

Browse files
committed
Update how we get the initial score to support marathon match formatted scores on code challenges (PS-295
1 parent 672cd73 commit 0c347e9

File tree

1 file changed

+30
-5
lines changed
  • src/shared/components/challenge-detail/Submissions

1 file changed

+30
-5
lines changed

src/shared/components/challenge-detail/Submissions/index.jsx

+30-5
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,31 @@ class SubmissionsComponent extends React.Component {
102102
}
103103
}
104104

105+
/**
106+
* Returns the value of the "Initial Score" shown on the submissions tab
107+
* We have to check a couple things because sometimes we're running code challenges that
108+
* likely should be marathon matches (PS-295)
109+
*
110+
* Marathon matches place the initial score in submission.score
111+
*
112+
* Code challenges place the initial score in submission.review[x].score
113+
*
114+
* We need to check both places
115+
* @param {Object} submission The submission to return the score for
116+
*/
117+
getInitialScore(submission) {
118+
let score = 'N/A';
119+
if (!_.isEmpty(submission.review)
120+
&& !_.isEmpty(submission.review[0])
121+
&& submission.review[0].score
122+
&& this.challenge.status === 'Completed') {
123+
score = Number(submission.review[0].score).toFixed(2);
124+
} else if (!_.isEmpty(submission.score)) {
125+
score = Number(submission.score).toFixed(2);
126+
}
127+
return score;
128+
}
129+
105130
/**
106131
* Check if it have flag for first try
107132
* @param {Object} registrant registrant info
@@ -209,6 +234,10 @@ class SubmissionsComponent extends React.Component {
209234
if (isHaveFinalScore) {
210235
valueA = getFinalScore(a);
211236
valueB = getFinalScore(b);
237+
} else if (valueA.score || valueB.score) {
238+
// Handle MM formatted scores in a code challenge (PS-295)
239+
valueA = Number(valueA.score);
240+
valueB = Number(valueB.score);
212241
} else {
213242
valueA = !_.isEmpty(a.review) && a.review[0].score;
214243
valueB = !_.isEmpty(b.review) && b.review[0].score;
@@ -904,11 +933,7 @@ class SubmissionsComponent extends React.Component {
904933
<div styleName="col-5">
905934
<div styleName="mobile-header">INITIAL SCORE</div>
906935
<p>
907-
{
908-
(!_.isEmpty(s.review) && !_.isEmpty(s.review[0]) && s.review[0].score && challenge.status === 'Completed')
909-
? Number(s.review[0].score).toFixed(2)
910-
: 'N/A'
911-
}
936+
{this.getInitialScore(s)}
912937
</p>
913938
</div>
914939
<div styleName="col-6">

0 commit comments

Comments
 (0)