diff --git a/__tests__/shared/components/SubmissionManagement/Submission.jsx b/__tests__/shared/components/SubmissionManagement/Submission.jsx index db738bc760..3f593267e3 100644 --- a/__tests__/shared/components/SubmissionManagement/Submission.jsx +++ b/__tests__/shared/components/SubmissionManagement/Submission.jsx @@ -4,6 +4,7 @@ import Submission from 'components/SubmissionManagement/Submission'; import TU from 'react-dom/test-utils'; const mockOnDelete = jest.fn(); +const mockOnDownload = jest.fn(); const mockOnShowDetails = jest.fn(); const rnd = new Rnd(); @@ -12,6 +13,7 @@ test('Snapshot match', () => { rnd.render(( { rnd.render((
- + { /* TODO: At the moment we just fetch downloads from the legacy Topcoder Studio API, and we don't need any JS code to this. @@ -132,6 +130,7 @@ Submission.propTypes = { }), showScreeningDetails: PT.bool, track: PT.string.isRequired, + onDownload: PT.func.isRequired, onDelete: PT.func.isRequired, onShowDetails: PT.func, status: PT.string.isRequired, diff --git a/src/shared/containers/SubmissionManagement/index.jsx b/src/shared/containers/SubmissionManagement/index.jsx index 383c2d1050..0e7869781d 100644 --- a/src/shared/containers/SubmissionManagement/index.jsx +++ b/src/shared/containers/SubmissionManagement/index.jsx @@ -15,11 +15,13 @@ import PT from 'prop-types'; import { connect } from 'react-redux'; import { Modal } from 'topcoder-react-ui-kit'; import { config } from 'topcoder-react-utils'; -import { actions } from 'topcoder-react-lib'; +import { actions, services } from 'topcoder-react-lib'; import './styles.scss'; import smpActions from '../../actions/page/submission_management'; +const { getService } = services.submissions; + // The container component class SubmissionManagementPageContainer extends React.Component { componentDidMount() { @@ -54,7 +56,6 @@ class SubmissionManagementPageContainer extends React.Component { isLoadingChallenge, mySubmissions, onCancelSubmissionDelete, - onDownloadSubmission, onShowDetails, onSubmissionDelete, onSubmissionDeleteConfirmed, @@ -68,7 +69,19 @@ class SubmissionManagementPageContainer extends React.Component { const smConfig = { onShowDetails, onDelete: onSubmissionDelete, - onDownload: () => onDownloadSubmission(0, authTokens), + onDownload: (challengeType, submissionId) => { + const submissionsService = getService(authTokens.tokenV3); + submissionsService.downloadSubmission(submissionId) + .then((blob) => { + const url = window.URL.createObjectURL(new Blob([blob])); + const link = document.createElement('a'); + link.href = url; + link.setAttribute('download', `submission-${challengeType}-${submissionId}.zip`); + document.body.appendChild(link); + link.click(); + link.parentNode.removeChild(link); + }); + }, onlineReviewUrl: `${config.URL.ONLINE_REVIEW}/review/actions/ViewProjectDetails?pid=${challengeId}`, challengeUrl: `${challengesUrl}/${challengeId}`, addSumissionUrl: `${config.URL.BASE}/challenges/${challengeId}/submit`,