Skip to content

Commit 8edff13

Browse files
committed
WM is not handling error response from submissions-api download endpoint
https://topcoder.atlassian.net/browse/PROD-4355
1 parent 0f840ae commit 8edff13

File tree

2 files changed

+72
-20
lines changed

2 files changed

+72
-20
lines changed

src/components/ChallengeEditor/Submissions/index.js

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import moment from 'moment'
99
import _ from 'lodash'
1010
import { STUDIO_URL, SUBMISSION_REVIEW_APP_URL, getTCMemberURL } from '../../../config/constants'
1111
import { PrimaryButton } from '../../Buttons'
12+
import AlertModal from '../../Modal/AlertModal'
1213
import cn from 'classnames'
1314
import ReactSVG from 'react-svg'
1415
import {
@@ -20,17 +21,23 @@ import {
2021
checkAdmin
2122
} from '../../../util/tc'
2223
import {
23-
getTopcoderReactLib
24+
getTopcoderReactLib,
25+
isValidDownloadFile
2426
} from '../../../util/topcoder-react-lib'
2527
import {
2628
compressFiles
2729
} from '../../../util/files'
2830
import styles from './Submissions.module.scss'
31+
import modalStyles from '../../../styles/modal.module.scss'
2932
const assets = require.context('../../../assets/images', false, /svg/)
3033
const ArrowDown = './arrow-down.svg'
3134
const Lock = './lock.svg'
3235
const Download = './IconSquareDownload.svg'
3336

37+
const theme = {
38+
container: modalStyles.modalContainer
39+
}
40+
3441
class SubmissionsComponent extends React.Component {
3542
constructor (props) {
3643
super(props)
@@ -42,7 +49,8 @@ class SubmissionsComponent extends React.Component {
4249
isShowInformation: false,
4350
memberOfModal: '',
4451
sortedSubmissions: [],
45-
downloadingAll: false
52+
downloadingAll: false,
53+
alertMessage: ''
4654
}
4755
this.getSubmissionsSortParam = this.getSubmissionsSortParam.bind(this)
4856
this.updateSortedSubmissions = this.updateSortedSubmissions.bind(this)
@@ -222,7 +230,7 @@ class SubmissionsComponent extends React.Component {
222230
const { field, sort } = this.getSubmissionsSortParam()
223231
const revertSort = sort === 'desc' ? 'asc' : 'desc'
224232

225-
const { sortedSubmissions, downloadingAll } = this.state
233+
const { sortedSubmissions, downloadingAll, alertMessage } = this.state
226234

227235
const renderSubmission = s => (
228236
<div className={styles.submission} key={s.id}>
@@ -544,19 +552,27 @@ class SubmissionsComponent extends React.Component {
544552
const submissionsService = getService(token)
545553
submissionsService.downloadSubmission(s.id)
546554
.then((blob) => {
547-
// eslint-disable-next-line no-undef
548-
const url = window.URL.createObjectURL(new Blob([blob]))
549-
const link = document.createElement('a')
550-
link.href = url
551-
let fileName = s.legacySubmissionId
552-
if (!fileName) {
553-
fileName = s.id
554-
}
555-
fileName = fileName + '.zip'
556-
link.setAttribute('download', `${fileName}`)
557-
document.body.appendChild(link)
558-
link.click()
559-
link.parentNode.removeChild(link)
555+
isValidDownloadFile(blob).then((isValidFile) => {
556+
if (isValidFile.success) {
557+
// eslint-disable-next-line no-undef
558+
const url = window.URL.createObjectURL(new Blob([blob]))
559+
const link = document.createElement('a')
560+
link.href = url
561+
let fileName = s.legacySubmissionId
562+
if (!fileName) {
563+
fileName = s.id
564+
}
565+
fileName = fileName + '.zip'
566+
link.setAttribute('download', `${fileName}`)
567+
document.body.appendChild(link)
568+
link.click()
569+
link.parentNode.removeChild(link)
570+
} else {
571+
this.setState({
572+
alertMessage: isValidFile.message || 'Can not download this submission.'
573+
})
574+
}
575+
})
560576
})
561577
}}
562578
>
@@ -611,10 +627,14 @@ class SubmissionsComponent extends React.Component {
611627
fileName = fileName + '.zip'
612628
submissionsService.downloadSubmission(submission.id)
613629
.then((blob) => {
614-
const file = new window.File([blob], `${fileName}`)
615-
allFiles.push(file)
616-
downloadedFile += 1
617-
checkToCompressFiles()
630+
isValidDownloadFile(blob).then((isValidFile) => {
631+
if (isValidFile.success) {
632+
const file = new window.File([blob], `${fileName}`)
633+
allFiles.push(file)
634+
}
635+
downloadedFile += 1
636+
checkToCompressFiles()
637+
})
618638
}).catch(() => {
619639
downloadedFile += 1
620640
checkToCompressFiles()
@@ -625,6 +645,20 @@ class SubmissionsComponent extends React.Component {
625645
</div>
626646
</div>) : null}
627647
</div>
648+
649+
{alertMessage ? (
650+
<AlertModal
651+
title=''
652+
message={alertMessage}
653+
theme={theme}
654+
closeText='OK'
655+
onClose={() => {
656+
this.setState({
657+
alertMessage: ''
658+
})
659+
}}
660+
/>
661+
) : null}
628662
</>
629663
)
630664
}

src/util/topcoder-react-lib.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,21 @@ export const getTopcoderReactLib = () => {
1414
const reactLib = require('topcoder-react-lib')
1515
return reactLib
1616
}
17+
18+
export const isValidDownloadFile = async (blobFile) => {
19+
if (!blobFile) {
20+
return {
21+
success: false
22+
}
23+
}
24+
if (blobFile.type.indexOf('json') >= 0) {
25+
const backendResonse = JSON.parse(await blobFile.text())
26+
return {
27+
success: false,
28+
message: backendResonse.message || ''
29+
}
30+
}
31+
return {
32+
success: true
33+
}
34+
}

0 commit comments

Comments
 (0)