diff --git a/src/actions/challengeSubmissions.js b/src/actions/challengeSubmissions.js index b060c19f..c2122209 100644 --- a/src/actions/challengeSubmissions.js +++ b/src/actions/challengeSubmissions.js @@ -2,12 +2,12 @@ import { fetchSubmissions } from '../services/challenges' import { LOAD_CHALLENGE_SUBMISSIONS } from '../config/constants' -export function loadSubmissions (challengeId) { - return dispatch => { +export function loadSubmissions (challengeId, page) { + return (dispatch) => { if (challengeId) { dispatch({ type: LOAD_CHALLENGE_SUBMISSIONS, - payload: fetchSubmissions(challengeId) + payload: fetchSubmissions(challengeId, page) }) } } diff --git a/src/components/ChallengeEditor/ChallengeViewTabs/index.js b/src/components/ChallengeEditor/ChallengeViewTabs/index.js index 84ee5676..9c7d301f 100644 --- a/src/components/ChallengeEditor/ChallengeViewTabs/index.js +++ b/src/components/ChallengeEditor/ChallengeViewTabs/index.js @@ -55,7 +55,11 @@ const ChallengeViewTabs = ({ loggedInUser, onApproveChallenge, createResource, - deleteResource + deleteResource, + loadSubmissions, + totalSubmissions, + submissionsPerPage, + page }) => { const [selectedTab, setSelectedTab] = useState(0) const [showAddResourceModal, setShowAddResourceModal] = useState(false) @@ -114,7 +118,7 @@ const ChallengeViewTabs = ({ }) return s }) - }, [challengeSubmissions, allResources]) + }, [challengeSubmissions, allResources, page]) const isTask = _.get(challenge, 'task.isTask', false) @@ -298,7 +302,7 @@ const ChallengeViewTabs = ({ > RESOURCES - {challengeSubmissions.length ? ( + {totalSubmissions ? ( - SUBMISSIONS ({submissions.length}) + SUBMISSIONS ({totalSubmissions}) ) : null} @@ -353,6 +357,10 @@ const ChallengeViewTabs = ({ submissions={submissions} token={token} loggedInUserResource={loggedInUserResource} + loadSubmissions={loadSubmissions} + totalSubmissions={totalSubmissions} + submissionsPerPage={submissionsPerPage} + page={page} /> )} {showAddResourceModal ? ( !_.isNil(s.reviewSummation && s.reviewSummation[0].aggregateScore) - ) - } - return sortList(submissions, field, sort, (a, b) => { - let valueA = 0 - let valueB = 0 - let valueIsString = false - switch (field) { - case 'Country': { - valueA = a.registrant ? a.registrant.countryCode : '' - valueB = b.registrant ? b.registrant.countryCode : '' - valueIsString = true - break - } - case 'Rating': { - valueA = a.registrant ? a.registrant.rating : 0 - valueB = b.registrant ? b.registrant.rating : 0 - break - } - case 'Username': { - valueA = _.get(a.registrant, 'memberHandle', '').toLowerCase() - valueB = _.get(b.registrant, 'memberHandle', '').toLowerCase() - valueIsString = true - break - } - case 'Email': { - valueA = _.get(a.registrant, 'email', '').toLowerCase() - valueB = _.get(b.registrant, 'email', '').toLowerCase() - valueIsString = true - break - } - case 'Time': - valueA = new Date(a.submissions && a.submissions[0].submissionTime) - valueB = new Date(b.submissions && b.submissions[0].submissionTime) - break - case 'Submission Date': { - valueA = new Date(a.created) - valueB = new Date(b.created) - break - } - case 'Initial / Final Score': { - if (isHaveFinalScore) { - valueA = getFinalScore(a) - valueB = getFinalScore(b) - } else { - valueA = !_.isEmpty(a.review) && a.review[0].score - valueB = !_.isEmpty(b.review) && b.review[0].score - } - break - } - case 'Final Rank': { - if (this.checkIsReviewPhaseComplete()) { - valueA = a.finalRank ? a.finalRank : 0 - valueB = b.finalRank ? b.finalRank : 0 - } - break - } - case 'Provisional Rank': { - valueA = a.provisionalRank ? a.provisionalRank : 0 - valueB = b.provisionalRank ? b.provisionalRank : 0 - break - } - case 'Final Score': { - valueA = getFinalScore(a) - valueB = getFinalScore(b) - break - } - case 'Provisional Score': { - valueA = getProvisionalScore(a) - valueB = getProvisionalScore(b) - break - } - default: - } - - if (valueIsString === false) { - if (valueA === '-') valueA = 0 - if (valueB === '-') valueB = 0 - } - - return { - valueA, - valueB, - valueIsString - } - }) - } - - onSortChange (sort) { - this.setState({ - submissionsSort: sort - }) - this.updateSortedSubmissions() - } /** * Check if review phase complete */ @@ -267,17 +125,58 @@ class SubmissionsComponent extends React.Component { }) } + /** + * Update filter for getting project by pagination + * @param {Number} perPageNumber per page number + */ + handlePerPageChange (option) { + const perPageNumber = option.value + const { + submissionsPerPage, + loadSubmissions, + challenge: { + id + } + } = this.props + + if (submissionsPerPage !== perPageNumber) { + loadSubmissions(id, { + page: 1, + perPage: perPageNumber + }) + } + } + + /** + * Update filter for getting project by pagination + * @param {Number} pageNumber page number + */ + async handlePageChange (pageNumber) { + const { + page, + submissionsPerPage, + loadSubmissions, + challenge: { + id + } + } = this.props + + if (page !== pageNumber) { + loadSubmissions(id, { + page: pageNumber, + perPage: submissionsPerPage + }) + } + } + render () { - const { challenge, token, loggedInUserResource } = this.props + const { challenge, token, loggedInUserResource, page, submissionsPerPage, totalSubmissions, submissions } = this.props const { checkpoints, track, type, tags } = challenge const canDownloadSubmission = (loggedInUserResource && checkDownloadSubmissionRoles(loggedInUserResource.roles)) || checkAdmin(token) - const { field, sort } = this.getSubmissionsSortParam() - const revertSort = sort === 'desc' ? 'asc' : 'desc' - - const { sortedSubmissions, downloadingAll, alertMessage } = this.state + const { downloadingAll, alertMessage } = this.state const renderSubmission = s => (
@@ -319,7 +218,7 @@ class SubmissionsComponent extends React.Component { const isBugHunt = _.includes(tags, 'Bug Hunt') // copy colorStyle from registrants to submissions - _.forEach(sortedSubmissions, s => { + _.forEach(submissions, s => { if (s.registrant && s.registrant.colorStyle && !s.colorStyle) { const { colorStyle } = s.registrant /* eslint-disable no-param-reassign */ @@ -344,7 +243,7 @@ class SubmissionsComponent extends React.Component {
ROUND 2 (FINAL) SUBMISSIONS
- {sortedSubmissions.map(renderSubmission)} + {submissions.map(renderSubmission)}
{checkpoints.length > 0 && (
@@ -388,117 +287,20 @@ class SubmissionsComponent extends React.Component { {!isF2F && !isBugHunt && ( - + Rating )} - + Username - + Email - + Submission Date - + Initial / Final Score - {sortedSubmissions.map(s => { + {submissions.map(s => { const rating = s.registrant && !_.isNil(s.registrant.rating) ? s.registrant.rating : '-' @@ -679,7 +481,7 @@ class SubmissionsComponent extends React.Component { const allFiles = [] let downloadedFile = 0 const checkToCompressFiles = () => { - if (downloadedFile === sortedSubmissions.length) { + if (downloadedFile === submissions.length) { if (downloadedFile > 0) { compressFiles(allFiles, 'all-submissions.zip', () => { this.setState({ @@ -694,7 +496,7 @@ class SubmissionsComponent extends React.Component { } } checkToCompressFiles() - _.forEach(sortedSubmissions, (submission) => { + _.forEach(submissions, (submission) => { let fileName = submission.legacySubmissionId if (!fileName) { fileName = submission.id @@ -721,6 +523,30 @@ class SubmissionsComponent extends React.Component {
) : null}
+
+
+