Skip to content
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

PROD - hide download buttons on submissions for Topcrowd / Phoenix challenges #6974

Merged
merged 7 commits into from
Apr 8, 2024
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
27 changes: 21 additions & 6 deletions src/shared/components/SubmissionManagement/Submission/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import './styles.scss';

export default function Submission(props) {
const {
challenge,
submissionObject,
showScreeningDetails,
track,
Expand All @@ -40,6 +41,15 @@ export default function Submission(props) {
const onDownloadSubmission = onDownload.bind(1, submissionObject.id);
const safeForDownloadCheck = safeForDownload(submissionObject.url);

// Determine if a challenge is for Topcrowd so we can edit the UI accordingly
let isTopCrowdChallenge = false;
if (challenge) {
const isTopCrowdChallengeData = _.find(challenge.metadata, { name: 'is_platform' });
if (isTopCrowdChallengeData) {
isTopCrowdChallenge = isTopCrowdChallengeData.value;
}
}

return (
<tr styleName="submission-row">
<td styleName="id-col">
Expand Down Expand Up @@ -72,12 +82,16 @@ export default function Submission(props) {
}
<td styleName="action-col">
<div>
<button
onClick={() => onDownloadSubmission(submissionObject.id)}
type="button"
>
{ safeForDownloadCheck === true && <DownloadIcon /> }
</button>
{ !isTopCrowdChallenge
? (
<button
onClick={() => onDownloadSubmission(submissionObject.id)}
type="button"
>
{ safeForDownloadCheck === true && <DownloadIcon /> }
</button>
)
: <span /> }
{ /*
TODO: At the moment we just fetch downloads from the legacy
Topcoder Studio API, and we don't need any JS code to this.
Expand Down Expand Up @@ -121,6 +135,7 @@ Submission.defaultProps = {
};

Submission.propTypes = {
challenge: PT.shape().isRequired,
submissionObject: PT.shape({
id: PT.string,
legacySubmissionId: PT.string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export default function SubmissionManagement(props) {
{!loadingSubmissions
&& (
<SubmissionsTable
challenge={challenge}
submissionObjects={submissions}
showDetails={showDetails}
track={track}
Expand Down Expand Up @@ -212,13 +213,13 @@ SubmissionManagement.defaultProps = {
};

SubmissionManagement.propTypes = {
challenge: PT.shape().isRequired,
showDetails: PT.shape().isRequired,
onDelete: PT.func,
onlineReviewUrl: PT.string,
helpPageUrl: PT.string,
onDownload: PT.func,
onShowDetails: PT.func,
challenge: PT.shape().isRequired,
submissions: PT.arrayOf(PT.shape()),
loadingSubmissions: PT.bool,
challengeUrl: PT.string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import './styles.scss';

export default function SubmissionsTable(props) {
const {
challenge,
submissionObjects,
showDetails,
track,
Expand Down Expand Up @@ -56,6 +57,7 @@ export default function SubmissionsTable(props) {

const submission = (
<Submission
challenge={challenge}
submissionObject={subObject}
showScreeningDetails={showDetails[subObject.id]}
track={track}
Expand Down Expand Up @@ -140,6 +142,7 @@ SubmissionsTable.defaultProps = {
};

SubmissionsTable.propTypes = {
challenge: PT.shape().isRequired,
submissionObjects: PT.arrayOf(SubShape),
showDetails: PT.shape().isRequired,
track: PT.string.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,15 @@ class SubmissionsListView extends React.Component {
timeClicked: false,
};

// Determine if a challenge is for Topcrowd so we can edit the UI accordingly
let isTopCrowdChallenge = false;
const isTopCrowdChallengeData = _.find(challenge.metadata, { name: 'is_platform' });
if (isTopCrowdChallengeData) {
isTopCrowdChallenge = isTopCrowdChallengeData.value;
} else {
isTopCrowdChallenge = false;
}

return (
<div styleName="wrapper">
<div styleName="submission-table">
Expand Down Expand Up @@ -432,25 +441,29 @@ class SubmissionsListView extends React.Component {
<span>{moment(mySubmission.submissionTime).format('MMM DD, YYYY HH:mm:ss')}</span>
</div>
<div styleName="submission-table-column column-2-4">
<button
onClick={() => {
// download submission
const submissionsService = getService(auth.tokenV3);
submissionsService.downloadSubmission(mySubmission.submissionId)
.then((blob) => {
const url = window.URL.createObjectURL(new Blob([blob]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', `submission-${mySubmission.submissionId}.zip`);
document.body.appendChild(link);
link.click();
link.parentNode.removeChild(link);
});
}}
type="button"
>
<DownloadIcon />
</button>
{ !isTopCrowdChallenge
? (
<button
onClick={() => {
// download submission
const submissionsService = getService(auth.tokenV3);
submissionsService.downloadSubmission(mySubmission.submissionId)
.then((blob) => {
const url = window.URL.createObjectURL(new Blob([blob]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', `submission-${mySubmission.submissionId}.zip`);
document.body.appendChild(link);
link.click();
link.parentNode.removeChild(link);
});
}}
type="button"
>
<DownloadIcon />
</button>
)
: <span /> }

<button onClick={() => selectSubmission(mySubmission)} type="button">
<ZoomIcon styleName="icon-zoom" />
Expand Down Expand Up @@ -523,13 +536,7 @@ SubmissionsListView.defaultProps = {
SubmissionsListView.propTypes = {
selectSubmission: PT.func,
challengesUrl: PT.string.isRequired,
challenge: PT.shape({
id: PT.any,
checkpoints: PT.arrayOf(PT.object),
submissions: PT.arrayOf(PT.object),
submissionViewable: PT.string,
registrants: PT.any,
}).isRequired,
challenge: PT.shape().isRequired,
hasRegistered: PT.bool.isRequired,
unregistering: PT.bool.isRequired,
submissionEnded: PT.bool.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,7 @@ MySubmissionsView.defaultProps = {

MySubmissionsView.propTypes = {
challengesUrl: PT.string.isRequired,
challenge: PT.shape({
id: PT.any,
checkpoints: PT.arrayOf(PT.object),
submissions: PT.arrayOf(PT.object),
submissionViewable: PT.string,
registrants: PT.any,
}).isRequired,
challenge: PT.shape().isRequired,
hasRegistered: PT.bool.isRequired,
unregistering: PT.bool.isRequired,
submissionEnded: PT.bool.isRequired,
Expand Down
24 changes: 23 additions & 1 deletion src/shared/components/challenge-detail/Registrants/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export default class Registrants extends React.Component {

this.getCheckPoint = this.getCheckPoint.bind(this);
this.getCheckPointDate = this.getCheckPointDate.bind(this);
this.getSubmissionDate = this.getSubmissionDate.bind(this);
this.getFlagFirstTry = this.getFlagFirstTry.bind(this);
this.sortRegistrants = this.sortRegistrants.bind(this);
this.getRegistrantsSortParam = this.getRegistrantsSortParam.bind(this);
Expand Down Expand Up @@ -128,6 +129,23 @@ export default class Registrants extends React.Component {
return final;
}

/**
* Get the submission date of a registrant (used when viewing the registrants tab anonymously)
* @param {Object} registrant the registrant to return the submission date for
*/
getSubmissionDate(registrant) {
const {
statisticsData,
} = this.props;
console.log(JSON.stringify(statisticsData, null, 4));
let submissionDate;
const statistic = (statisticsData || []).find(x => x.handle === registrant.memberHandle);
if (statistic && statistic.submissions && statistic.submissions.length > 0) {
submissionDate = statistic.submissions.sort()[0].created;
}
return submissionDate;
}

/**
* Check if it have flag for first try
* @param {Object} registrant registrant info
Expand Down Expand Up @@ -413,7 +431,10 @@ export default class Registrants extends React.Component {
if (checkpoint) {
checkpoint = formatDate(checkpoint);
}
const final = this.getFinal(r);
let final = this.getFinal(r);
if (!final) {
final = this.getSubmissionDate(r);
}

return (
<div styleName="row" key={r.memberHandle} role="row">
Expand Down Expand Up @@ -523,6 +544,7 @@ Registrants.propTypes = {
type: PT.string,
track: PT.string,
}).isRequired,
statisticsData: PT.arrayOf(PT.shape()).isRequired,
results: PT.arrayOf(PT.shape()),
checkpointResults: PT.shape(),
registrants: PT.arrayOf(PT.shape()),
Expand Down
1 change: 1 addition & 0 deletions src/shared/containers/challenge-detail/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ class ChallengeDetailPageContainer extends React.Component {
)
}
results={results2}
statisticsData={statisticsData}
registrantsSort={registrantsSort}
notFoundCountryFlagUrl={notFoundCountryFlagUrl}
onGetFlagImageFail={(countryInfo) => {
Expand Down
Loading