Skip to content

Commit 0cc5dd8

Browse files
Merge pull request #6625 from topcoder-platform/develop
Release v1.17.17
2 parents 31ec364 + 771ae5f commit 0cc5dd8

File tree

5 files changed

+117
-25
lines changed

5 files changed

+117
-25
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ workflows:
398398
branches:
399399
ignore:
400400
- develop
401+
- submission_delete_button
401402

402403
Smoke Testing:
403404
when: << pipeline.parameters.run_smoketesting >>

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

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@
1414
import _ from 'lodash';
1515
import moment from 'moment';
1616
import React from 'react';
17-
// CHALLENGE_STATUS
18-
import { COMPETITION_TRACKS, safeForDownload } from 'utils/tc';
17+
import { COMPETITION_TRACKS, CHALLENGE_STATUS, safeForDownload } from 'utils/tc';
1918

2019
import PT from 'prop-types';
2120

22-
// import DeleteIcon from '../Icons/IconTrashSimple.svg';
21+
import DeleteIcon from '../Icons/IconTrashSimple.svg';
2322
import DownloadIcon from '../Icons/IconSquareDownload.svg';
2423
import ExpandIcon from '../Icons/IconMinimalDown.svg';
2524
import ScreeningStatus from '../ScreeningStatus';
@@ -32,10 +31,10 @@ export default function Submission(props) {
3231
showScreeningDetails,
3332
track,
3433
onDownload,
35-
// onDelete,
34+
onDelete,
3635
onShowDetails,
37-
// status,
38-
// allowDelete,
36+
status,
37+
allowDelete,
3938
} = props;
4039
const formatDate = date => moment(+new Date(date)).format('MMM DD, YYYY hh:mm A');
4140
const onDownloadSubmission = onDownload.bind(1, submissionObject.id);
@@ -89,19 +88,19 @@ export default function Submission(props) {
8988
onClick={() => onDownload(submissionObject.id)}
9089
><DownloadIcon /></button>
9190
*/ }
92-
{/* {status !== CHALLENGE_STATUS.COMPLETED */}
93-
{/* && track !== COMPETITION_TRACKS.DES */}
94-
{/* && ( */}
95-
{/* <button */}
96-
{/* styleName="delete-icon" */}
97-
{/* onClick={() => onDelete(submissionObject.id)} */}
98-
{/* disabled={!allowDelete} */}
99-
{/* type="button" */}
100-
{/* > */}
101-
{/* <DeleteIcon /> */}
102-
{/* </button> */}
103-
{/* ) */}
104-
{/* } */}
91+
{status !== CHALLENGE_STATUS.COMPLETED
92+
&& track === COMPETITION_TRACKS.DES
93+
&& safeForDownloadCheck === true && (
94+
<button
95+
styleName="delete-icon"
96+
onClick={() => onDelete(submissionObject.id)}
97+
disabled={!allowDelete}
98+
type="button"
99+
>
100+
<DeleteIcon />
101+
</button>
102+
)
103+
}
105104
<button
106105
styleName={`expand-icon ${(showScreeningDetails ? 'expanded' : '')}`}
107106
onClick={() => onShowDetails(submissionObject.id)}
@@ -138,8 +137,8 @@ Submission.propTypes = {
138137
showScreeningDetails: PT.bool,
139138
track: PT.string.isRequired,
140139
onDownload: PT.func.isRequired,
141-
// onDelete: PT.func.isRequired,
140+
onDelete: PT.func.isRequired,
142141
onShowDetails: PT.func,
143-
// status: PT.string.isRequired,
144-
// allowDelete: PT.bool.isRequired,
142+
status: PT.string.isRequired,
143+
allowDelete: PT.bool.isRequired,
145144
};

src/shared/containers/SubmissionManagement/index.jsx

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import LoadingIndicator from 'components/LoadingIndicator';
1111
import SubmissionManagement from 'components/SubmissionManagement/SubmissionManagement';
1212
import React from 'react';
1313
import PT from 'prop-types';
14+
import { safeForDownload } from 'utils/tc';
1415
import { connect } from 'react-redux';
1516
import { Modal, PrimaryButton } from 'topcoder-react-ui-kit';
1617
import { config } from 'topcoder-react-utils';
@@ -21,8 +22,22 @@ import smpActions from '../../actions/page/submission_management';
2122

2223
const { getService } = services.submissions;
2324

25+
const theme = {
26+
container: style.modalContainer,
27+
};
28+
2429
// The container component
2530
class SubmissionManagementPageContainer extends React.Component {
31+
constructor(props) {
32+
super(props);
33+
34+
this.state = {
35+
needReload: false,
36+
initialState: true,
37+
submissions: [],
38+
};
39+
}
40+
2641
componentDidMount() {
2742
const {
2843
authTokens,
@@ -43,6 +58,52 @@ class SubmissionManagementPageContainer extends React.Component {
4358
}
4459
}
4560

61+
componentWillReceiveProps(nextProps) {
62+
const {
63+
loadMySubmissions, authTokens, challengeId, mySubmissions,
64+
} = nextProps;
65+
const { needReload } = this.state;
66+
67+
if (needReload === false && mySubmissions) {
68+
if (mySubmissions.find(item => safeForDownload(item.url) !== true)) {
69+
this.setState({ needReload: true });
70+
setTimeout(() => {
71+
loadMySubmissions(authTokens, challengeId);
72+
this.setState({ needReload: false });
73+
}, 2000);
74+
}
75+
}
76+
}
77+
78+
componentDidUpdate(prevProps) {
79+
const {
80+
deletionSucceed,
81+
toBeDeletedId,
82+
mySubmissions,
83+
} = this.props;
84+
const { initialState } = this.state;
85+
86+
if (initialState && mySubmissions) {
87+
// eslint-disable-next-line react/no-did-update-set-state
88+
this.setState({
89+
submissions: [...mySubmissions],
90+
initialState: false,
91+
});
92+
return;
93+
}
94+
const { submissions } = this.state;
95+
96+
if (deletionSucceed !== prevProps.deletionSucceed) {
97+
_.remove(submissions, submission => (
98+
submission.id === toBeDeletedId
99+
));
100+
// eslint-disable-next-line react/no-did-update-set-state
101+
this.setState({
102+
submissions,
103+
});
104+
}
105+
}
106+
46107
render() {
47108
const {
48109
authTokens,
@@ -53,7 +114,6 @@ class SubmissionManagementPageContainer extends React.Component {
53114
loadingSubmissionsForChallengeId,
54115
submissionPhaseStartDate,
55116
isLoadingChallenge,
56-
mySubmissions,
57117
onCancelSubmissionDelete,
58118
onShowDetails,
59119
onSubmissionDelete,
@@ -62,6 +122,9 @@ class SubmissionManagementPageContainer extends React.Component {
62122
showModal,
63123
toBeDeletedId,
64124
} = this.props;
125+
126+
const { submissions } = this.state;
127+
65128
if (!challenge.isRegistered) return <AccessDenied redirectLink={`${challengesUrl}/${challenge.id}`} cause={ACCESS_DENIED_REASON.HAVE_NOT_SUBMITTED_TO_THE_CHALLENGE} />;
66129

67130
const isEmpty = _.isEmpty(challenge);
@@ -96,7 +159,7 @@ class SubmissionManagementPageContainer extends React.Component {
96159
challenge={challenge}
97160
challengesUrl={challengesUrl}
98161
loadingSubmissions={Boolean(loadingSubmissionsForChallengeId)}
99-
submissions={mySubmissions}
162+
submissions={submissions}
100163
showDetails={showDetails}
101164
submissionPhaseStartDate={submissionPhaseStartDate}
102165
{...smConfig}
@@ -108,6 +171,7 @@ class SubmissionManagementPageContainer extends React.Component {
108171
{showModal && (
109172
<Modal
110173
onCancel={deleting ? _.noop : onCancelSubmissionDelete}
174+
theme={theme}
111175
>
112176
<div styleName="modal-content">
113177
<p styleName="are-you-sure">
@@ -123,6 +187,8 @@ class SubmissionManagementPageContainer extends React.Component {
123187
This will permanently remove all
124188
files from our servers and can’t be undone.
125189
You’ll have to upload all the files again in order to restore it.
190+
Note that deleting the file may take a few minutes to propagate
191+
through the Topcoder platform.
126192
</p>
127193
<div
128194
/* NOTE: Current implementation of the loading indicator is
@@ -179,6 +245,7 @@ SubmissionManagementPageContainer.defaultProps = {
179245
showModal: false,
180246
toBeDeletedId: '',
181247
challenge: null,
248+
deletionSucceed: false,
182249
};
183250

184251
SubmissionManagementPageContainer.propTypes = {
@@ -199,6 +266,7 @@ SubmissionManagementPageContainer.propTypes = {
199266
showModal: PT.bool,
200267
onCancelSubmissionDelete: PT.func.isRequired,
201268
toBeDeletedId: PT.string,
269+
deletionSucceed: PT.bool,
202270
onSubmissionDeleteConfirmed: PT.func.isRequired,
203271
submissionPhaseStartDate: PT.string.isRequired,
204272
};
@@ -232,6 +300,7 @@ function mapStateToProps(state, props) {
232300

233301
showModal: state.page.submissionManagement.showModal,
234302
toBeDeletedId: state.page.submissionManagement.toBeDeletedId,
303+
deletionSucceed: state.page.submissionManagement.deletionSucceed,
235304

236305
authTokens: state.auth,
237306
registrants: state.challenge.details.registrants,

src/shared/containers/SubmissionManagement/styles.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,7 @@ $sm-space-40: $base-unit * 8;
103103
}
104104
}
105105
}
106+
107+
.modalContainer {
108+
border-radius: 8px;
109+
}

src/shared/reducers/page/submission_management.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,38 @@ function create(initialState = {}) {
2929
...state,
3030
showModal: false,
3131
toBeDeletedId: '',
32+
deletionSucceed: false,
3233
}),
3334

34-
'SMP/DELETE_SUBMISSION_DONE': state => ({
35+
'SMP/DELETE_SUBMISSION_INIT': (state, { payload }) => ({
36+
...state,
37+
deletingSubmission: false,
38+
deletionSucceed: false,
39+
showModal: false,
40+
toBeDeletedId: payload,
41+
}),
42+
43+
'SMP/DELETE_SUBMISSION_FAIL': state => ({
3544
...state,
3645
deletingSubmission: false,
3746
showModal: false,
3847
toBeDeletedId: '',
48+
deletionSucceed: true,
49+
}),
50+
51+
'SMP/DELETE_SUBMISSION_DONE': (state, { payload }) => ({
52+
...state,
53+
deletingSubmission: false,
54+
showModal: false,
55+
toBeDeletedId: payload,
56+
deletionSucceed: true,
3957
}),
4058

4159
}, _.defaults(initialState, {
4260
showDetails: {},
4361
showModal: false,
4462
toBeDeletedId: '',
63+
deletionSucceed: false,
4564
}));
4665
}
4766

0 commit comments

Comments
 (0)