Skip to content

Issue#4583 : Fix mySubmissions of MM challenges #4622

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

Merged
merged 4 commits into from
Jul 2, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default function ChallengeViewSelector(props) {
const {
isLoggedIn,
challenge,
isMM,
checkpointCount,
numOfRegistrants,
numOfSubmissions,
Expand All @@ -32,8 +33,6 @@ export default function ChallengeViewSelector(props) {
mySubmissions,
} = props;

const challengeSubTrack = challenge.subTrack;
const isMM = challengeSubTrack && challengeSubTrack.indexOf('MARATHON_MATCH') > -1;
const forumId = _.get(challenge, 'forumId') || 0;
const roles = _.get(challenge, 'userDetails.roles') || [];

Expand Down Expand Up @@ -189,6 +188,7 @@ export default function ChallengeViewSelector(props) {
ChallengeViewSelector.defaultProps = {
isLoggedIn: false,
challenge: {},
isMM: false,
checkpointCount: 0,
numOfRegistrants: 0,
numOfSubmissions: 0,
Expand All @@ -206,6 +206,7 @@ ChallengeViewSelector.propTypes = {
roles: PT.arrayOf(PT.string),
}),
}),
isMM: PT.bool,
checkpointCount: PT.number,
numOfRegistrants: PT.number,
numOfSubmissions: PT.number,
Expand Down
1 change: 1 addition & 0 deletions src/shared/components/challenge-detail/Header/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ export default function ChallengeHeader(props) {
<TabSelector
isLoggedIn={isLoggedIn}
challenge={challenge}
isMM={isMM(challenge)}
onSelectorClicked={onSelectorClicked}
trackLower={trackLower}
selectedView={selectedView}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,10 @@ SubmissionsListView.propTypes = {
checkpoints: PT.arrayOf(PT.object),
submissions: PT.arrayOf(PT.object),
submissionViewable: PT.string,
track: PT.string.isRequired,
legacy: {
track: PT.string.isRequired,
}.isRequired,
registrants: PT.any,
subTrack: PT.any,
}).isRequired,
hasRegistered: PT.bool.isRequired,
unregistering: PT.bool.isRequired,
Expand Down
16 changes: 12 additions & 4 deletions src/shared/components/challenge-detail/MySubmissions/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ class MySubmissionsView extends React.Component {
}

componentDidMount() {
const { challenge, loadMMSubmissions, auth } = this.props;
const isMM = challenge.subTrack.indexOf('MARATHON_MATCH') > -1;
const {
challenge,
isMM,
loadMMSubmissions,
auth,
} = this.props;

// Check auth token, go to login page if invalid
if (isMM && (_.isEmpty(auth) || _.isEmpty(auth.tokenV3) || isTokenExpired(auth.tokenV3))) {
Expand All @@ -45,6 +49,7 @@ class MySubmissionsView extends React.Component {
const {
challengesUrl,
challenge,
isMM,
hasRegistered,
unregistering,
submissionEnded,
Expand Down Expand Up @@ -81,6 +86,7 @@ class MySubmissionsView extends React.Component {
hasRegistered={hasRegistered}
unregistering={unregistering}
submissionEnded={submissionEnded}
isMM={isMM}
isLegacyMM={isLegacyMM}
mySubmissions={mySubmissions}
auth={auth}
Expand All @@ -105,13 +111,15 @@ MySubmissionsView.propTypes = {
checkpoints: PT.arrayOf(PT.object),
submissions: PT.arrayOf(PT.object),
submissionViewable: PT.string,
track: PT.string.isRequired,
legacy: {
track: PT.string.isRequired,
},
registrants: PT.any,
subTrack: PT.any,
}).isRequired,
hasRegistered: PT.bool.isRequired,
unregistering: PT.bool.isRequired,
submissionEnded: PT.bool.isRequired,
isMM: PT.bool.isRequired,
isLegacyMM: PT.bool.isRequired,
loadingMMSubmissionsForChallengeId: PT.string.isRequired,
auth: PT.shape().isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,15 @@ SubmissionHistoryRow.propTypes = {
member: PT.string.isRequired,
isMM: PT.bool.isRequired,
submission: PT.number.isRequired,
finalScore: PT.number,
finalScore: PT.oneOfType([
PT.number,
PT.string,
]),
status: PT.string.isRequired,
provisionalScore: PT.number,
provisionalScore: PT.oneOfType([
PT.number,
PT.string,
]),
submissionTime: PT.string.isRequired,
isReviewPhaseComplete: PT.bool,
submissionId: PT.string.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,31 @@ SubmissionRow.propTypes = {
openHistory: PT.bool.isRequired,
member: PT.string.isRequired,
submissions: PT.arrayOf(PT.shape({
provisionalScore: PT.number,
finalScore: PT.number,
initialScore: PT.number,
provisionalScore: PT.oneOfType([
PT.number,
PT.string,
]),
finalScore: PT.oneOfType([
PT.number,
PT.string,
]),
initialScore: PT.oneOfType([
PT.number,
PT.string,
]),
status: PT.string.isRequired,
submissionId: PT.string.isRequired,
submissionTime: PT.string.isRequired,
})).isRequired,
score: PT.shape({
final: PT.number,
provisional: PT.number,
final: PT.oneOfType([
PT.number,
PT.string,
]),
provisional: PT.oneOfType([
PT.number,
PT.string,
]),
}),
rating: PT.number,
toggleHistory: PT.func,
Expand Down
18 changes: 10 additions & 8 deletions src/shared/containers/challenge-detail/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import _ from 'lodash';
import communityActions from 'actions/tc-communities';
import { isMM } from 'utils/challenge';
import { isMM as checkIsMM } from 'utils/challenge';
import LoadingPagePlaceholder from 'components/LoadingPagePlaceholder';
import pageActions from 'actions/page';
import ChallengeHeader from 'components/challenge-detail/Header';
Expand Down Expand Up @@ -387,7 +387,8 @@ class ChallengeDetailPageContainer extends React.Component {
? results : null;

const isEmpty = _.isEmpty(challenge);
const isLegacyMM = isMM(challenge) && Boolean(challenge.roundId);
const isMM = checkIsMM(challenge);
const isLegacyMM = isMM && Boolean(challenge.roundId);

if (isLoadingChallenge || isLoadingTerms) {
return <LoadingPagePlaceholder />;
Expand Down Expand Up @@ -556,7 +557,8 @@ class ChallengeDetailPageContainer extends React.Component {
hasRegistered={challenge.isRegistered}
unregistering={unregistering}
submissionEnded={submissionEnded}
isLegacyMM={isLegacyMM}
isMM
isLegacyMM
loadingMMSubmissionsForChallengeId={loadingMMSubmissionsForChallengeId}
auth={auth}
loadMMSubmissions={loadMMSubmissions}
Expand Down Expand Up @@ -722,16 +724,14 @@ function mapStateToProps(state, props) {
}));
}

if (mmSubmissions) {
if (!_.isEmpty(mmSubmissions)) {
mmSubmissions = mmSubmissions.map((submission) => {
let registrant;
let { member } = submission;
if (auth.user.handle === submission.member) {
mySubmissions = submission.submissions || [];
mySubmissions = mySubmissions.map((mySubmission, index) => {
// eslint-disable-next-line no-param-reassign
mySubmission.id = mySubmissions.length - index;
return mySubmission;
mySubmissions.forEach((mySubmission, index) => {
mySubmissions[index].id = mySubmissions.length - index;
});
}
let submissionDetail = _.find(challenge.submissions, { createdBy: submission.createdBy });
Expand Down Expand Up @@ -760,6 +760,8 @@ function mapStateToProps(state, props) {
member,
});
});
} else {
mySubmissions = _.filter(challenge.submissions, s => (`${s.memberId}` === `${auth.user.userId}`));
}
}
return {
Expand Down
4 changes: 2 additions & 2 deletions src/shared/utils/challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import _ from 'lodash';
* @param {Object} challenge challenge object
*/
export function isMM(challenge) {
return challenge.challengeType && challenge.challengeType.name === 'Marathon Match';
return challenge.type === 'Marathon Match';
}

/**
* check if is develop marathon match challenge
* @param {Object} challenge challenge object
*/
export function isDevelopMM(challenge) {
return challenge.challengeType && challenge.challengeType.name === 'Develop Marathon Match';
return challenge.type === 'Develop Marathon Match';
}

/**
Expand Down