Skip to content

Commit ebd7933

Browse files
Merge pull request #5129 from topcoder-platform/issue-4212-gets0ul
fix: allow member to download own submission for design challenge
2 parents e903d80 + 5c4a9ea commit ebd7933

File tree

4 files changed

+37
-15
lines changed

4 files changed

+37
-15
lines changed

__tests__/shared/components/SubmissionManagement/Submission.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Submission from 'components/SubmissionManagement/Submission';
44
import TU from 'react-dom/test-utils';
55

66
const mockOnDelete = jest.fn();
7+
const mockOnDownload = jest.fn();
78
const mockOnShowDetails = jest.fn();
89

910
const rnd = new Rnd();
@@ -12,6 +13,7 @@ test('Snapshot match', () => {
1213
rnd.render((
1314
<Submission
1415
onDelete={mockOnDelete}
16+
onDownload={mockOnDownload}
1517
onShowDetails={mockOnShowDetails}
1618
showScreeningDetails
1719
type="develop"
@@ -21,6 +23,7 @@ test('Snapshot match', () => {
2123
rnd.render((
2224
<Submission
2325
onDelete={mockOnDelete}
26+
onDownload={mockOnDownload}
2427
onShowDetails={mockOnShowDetails}
2528
submissionObject={{
2629
id: '12345',
@@ -49,6 +52,7 @@ class Wrapper extends React.Component {
4952
const page = TU.renderIntoDocument((
5053
<Wrapper
5154
onDelete={mockOnDelete}
55+
onDownload={mockOnDownload}
5256
onShowDetails={mockOnShowDetails}
5357
submissionObject={{
5458
id: '12345',

__tests__/shared/components/SubmissionManagement/__snapshots__/Submission.jsx.snap

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@ exports[`Snapshot match 1`] = `
2121
className="src-shared-components-SubmissionManagement-Submission-___styles__action-col___2M1RY"
2222
>
2323
<div>
24-
<a>
24+
<button
25+
onClick={[Function]}
26+
type="button"
27+
>
2528
<DownloadIcon
2629
height="16"
2730
viewBox="0 0 16 16"
2831
width="16"
2932
xmlns="http://www.w3.org/2000/svg"
3033
/>
31-
</a>
34+
</button>
3235
<button
3336
className="src-shared-components-SubmissionManagement-Submission-___styles__delete-icon___2M67z"
3437
disabled={true}
@@ -81,14 +84,17 @@ exports[`Snapshot match 2`] = `
8184
className="src-shared-components-SubmissionManagement-Submission-___styles__action-col___2M1RY"
8285
>
8386
<div>
84-
<a>
87+
<button
88+
onClick={[Function]}
89+
type="button"
90+
>
8591
<DownloadIcon
8692
height="16"
8793
viewBox="0 0 16 16"
8894
width="16"
8995
xmlns="http://www.w3.org/2000/svg"
9096
/>
91-
</a>
97+
</button>
9298
<button
9399
className="src-shared-components-SubmissionManagement-Submission-___styles__delete-icon___2M67z"
94100
disabled={true}

src/shared/components/SubmissionManagement/Submission/index.jsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import _ from 'lodash';
1515
import moment from 'moment';
1616
import React from 'react';
17-
import { config } from 'topcoder-react-utils';
1817
import { COMPETITION_TRACKS, CHALLENGE_STATUS } from 'utils/tc';
1918

2019
import PT from 'prop-types';
@@ -31,12 +30,14 @@ export default function Submission(props) {
3130
submissionObject,
3231
showScreeningDetails,
3332
track,
33+
onDownload,
3434
onDelete,
3535
onShowDetails,
3636
status,
3737
allowDelete,
3838
} = props;
3939
const formatDate = date => moment(+new Date(date)).format('MMM DD, YYYY hh:mm A');
40+
const onDownloadSubmission = onDownload.bind(1, submissionObject.id);
4041

4142
return (
4243
<tr styleName="submission-row">
@@ -66,15 +67,12 @@ export default function Submission(props) {
6667
}
6768
<td styleName="action-col">
6869
<div>
69-
<a
70-
href={
71-
track === COMPETITION_TRACKS.DES
72-
? `${config.URL.ONLINE_REVIEW}/review/actions/DownloadContestSubmission?uid=${submissionObject.id}`
73-
: submissionObject.download
74-
}
70+
<button
71+
onClick={() => onDownloadSubmission(submissionObject.id)}
72+
type="button"
7573
>
7674
<DownloadIcon />
77-
</a>
75+
</button>
7876
{ /*
7977
TODO: At the moment we just fetch downloads from the legacy
8078
Topcoder Studio API, and we don't need any JS code to this.
@@ -132,6 +130,7 @@ Submission.propTypes = {
132130
}),
133131
showScreeningDetails: PT.bool,
134132
track: PT.string.isRequired,
133+
onDownload: PT.func.isRequired,
135134
onDelete: PT.func.isRequired,
136135
onShowDetails: PT.func,
137136
status: PT.string.isRequired,

src/shared/containers/SubmissionManagement/index.jsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ import PT from 'prop-types';
1515
import { connect } from 'react-redux';
1616
import { Modal } from 'topcoder-react-ui-kit';
1717
import { config } from 'topcoder-react-utils';
18-
import { actions } from 'topcoder-react-lib';
18+
import { actions, services } from 'topcoder-react-lib';
1919

2020
import './styles.scss';
2121
import smpActions from '../../actions/page/submission_management';
2222

23+
const { getService } = services.submissions;
24+
2325
// The container component
2426
class SubmissionManagementPageContainer extends React.Component {
2527
componentDidMount() {
@@ -54,7 +56,6 @@ class SubmissionManagementPageContainer extends React.Component {
5456
isLoadingChallenge,
5557
mySubmissions,
5658
onCancelSubmissionDelete,
57-
onDownloadSubmission,
5859
onShowDetails,
5960
onSubmissionDelete,
6061
onSubmissionDeleteConfirmed,
@@ -68,7 +69,19 @@ class SubmissionManagementPageContainer extends React.Component {
6869
const smConfig = {
6970
onShowDetails,
7071
onDelete: onSubmissionDelete,
71-
onDownload: () => onDownloadSubmission(0, authTokens),
72+
onDownload: (challengeType, submissionId) => {
73+
const submissionsService = getService(authTokens.tokenV3);
74+
submissionsService.downloadSubmission(submissionId)
75+
.then((blob) => {
76+
const url = window.URL.createObjectURL(new Blob([blob]));
77+
const link = document.createElement('a');
78+
link.href = url;
79+
link.setAttribute('download', `submission-${challengeType}-${submissionId}.zip`);
80+
document.body.appendChild(link);
81+
link.click();
82+
link.parentNode.removeChild(link);
83+
});
84+
},
7285
onlineReviewUrl: `${config.URL.ONLINE_REVIEW}/review/actions/ViewProjectDetails?pid=${challengeId}`,
7386
challengeUrl: `${challengesUrl}/${challengeId}`,
7487
addSumissionUrl: `${config.URL.BASE}/challenges/${challengeId}/submit`,

0 commit comments

Comments
 (0)