Skip to content

Commit

Permalink
Add current phase to the challenge table and other fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgasper committed Feb 20, 2023
1 parent 4e3757f commit 8be49cf
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 49 deletions.
20 changes: 19 additions & 1 deletion src/components/Buttons/PrimaryButton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,26 @@ import styles from './PrimaryButton.module.scss'

const PrimaryButton = React.forwardRef(
(
{ type, text, link, onClick, submit, disabled, onMouseEnter, onMouseLeave },
{ type, text, link, onClick, submit, disabled, onMouseEnter, onMouseLeave, href },
ref
) => {
if (!_.isEmpty(href)) {
return (
<a
type={submit ? 'submit' : 'button'}
className={cn(styles.container, styles[type])}
onClick={submit ? null : onClick}
disabled={disabled}
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
ref={ref}
href={href}
target='_blank'
>
<span>{text}</span>
</a>
)
}
if (_.isEmpty(link)) {
return (
<button
Expand Down Expand Up @@ -44,6 +61,7 @@ PrimaryButton.propTypes = {
type: PropTypes.string.isRequired,
text: PropTypes.string.isRequired,
link: PropTypes.string,
href: PropTypes.string,
onClick: PropTypes.func,
submit: PropTypes.bool,
disabled: PropTypes.bool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ $base-unit: 5px;
margin-right: auto;

.top-title {
margin-top: -50px;
margin-top: -30px;
margin-bottom: 20px;
text-align: center;
display: flex;
justify-content: center;
gap: 20px;
gap: 40px;
}

div {
Expand Down Expand Up @@ -412,6 +413,10 @@ $base-unit: 5px;
color: $member-red !important;
}

.btnManageSubmissions {
height: 40px;
}

.btnDownloadAll {
text-decoration: none;
background-color: transparent;
Expand Down
95 changes: 52 additions & 43 deletions src/components/ChallengeEditor/Submissions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import PT from 'prop-types'
import moment from 'moment'
import _ from 'lodash'
import { STUDIO_URL, SUBMISSION_REVIEW_APP_URL, getTCMemberURL } from '../../../config/constants'
import { PrimaryButton } from '../../Buttons'
import cn from 'classnames'
import ReactSVG from 'react-svg'
import {
Expand Down Expand Up @@ -306,54 +307,62 @@ class SubmissionsComponent extends React.Component {
return (
<div className={cn(styles.container, styles.dev, styles['non-mm'])}>
<div className={styles['top-title']} >
<a href={`${SUBMISSION_REVIEW_APP_URL}/${challenge.legacyId}`} target='_blank'>
Manage Submissions
</a>
<button
className={styles.btnDownloadAll}
disabled={downloadingAll}
onClick={async () => {
const reactLib = getTopcoderReactLib()
const { getService } = reactLib.services.submissions
// download submission
this.setState({
downloadingAll: true
})
const submissionsService = getService(token)
const allFiles = []
let downloadedFile = 0
const checkToCompressFiles = () => {
if (downloadedFile === sortedSubmissions.length) {
if (downloadedFile > 0) {
compressFiles(allFiles, 'all-submissions.zip', () => {

<div className={styles.btnManageSubmissions} >
<PrimaryButton
text='Manage Submissions'
type='info'
href={`${SUBMISSION_REVIEW_APP_URL}/${challenge.legacyId}`}
/>
</div>

<div className={styles.btnManageSubmissions} >
<PrimaryButton
text='Download All'
type='info'
disabled={downloadingAll}
onClick={async () => {
const reactLib = getTopcoderReactLib()
const { getService } = reactLib.services.submissions
// download submission
this.setState({
downloadingAll: true
})
const submissionsService = getService(token)
const allFiles = []
let downloadedFile = 0
const checkToCompressFiles = () => {
if (downloadedFile === sortedSubmissions.length) {
if (downloadedFile > 0) {
compressFiles(allFiles, 'all-submissions.zip', () => {
this.setState({
downloadingAll: false
})
})
} else {
this.setState({
downloadingAll: false
})
})
} else {
this.setState({
downloadingAll: false
})
}
}
}
}
checkToCompressFiles()
_.forEach(sortedSubmissions, (submission) => {
const mmSubmissionId = submission.id
submissionsService.downloadSubmission(mmSubmissionId)
.then((blob) => {
const file = new window.File([blob], `submission-${mmSubmissionId}.zip`)
allFiles.push(file)
downloadedFile += 1
checkToCompressFiles()
}).catch(() => {
downloadedFile += 1
checkToCompressFiles()
})
})
}}>
Download All
</button>
checkToCompressFiles()
_.forEach(sortedSubmissions, (submission) => {
const mmSubmissionId = submission.id
submissionsService.downloadSubmission(mmSubmissionId)
.then((blob) => {
const file = new window.File([blob], `submission-${mmSubmissionId}.zip`)
allFiles.push(file)
downloadedFile += 1
checkToCompressFiles()
}).catch(() => {
downloadedFile += 1
checkToCompressFiles()
})
})
}}
/>
</div>
</div>
<div className={styles.head}>
{!isF2F && !isBugHunt && (
Expand Down
7 changes: 6 additions & 1 deletion src/components/ChallengeEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -837,10 +837,15 @@ class ChallengeEditor extends Component {
if (this.state && this.state) {
const { phases } = this.state.challenge
let newChallenge = _.cloneDeep(this.state.challenge)
const isDesignChallenge = newChallenge.trackId === DES_TRACK_ID
const is2RoundChallenge =
newChallenge.timelineTemplateId === MULTI_ROUND_CHALLENGE_TEMPLATE_ID
const is2RoundDesignChallenge = isDesignChallenge && is2RoundChallenge

for (let index = 0; index < phases.length; ++index) {
newChallenge.phases[index].isDurationActive =
moment(newChallenge.phases[index]['scheduledEndDate']).isAfter()
if (newChallenge.phases[index].name === 'Submission' || newChallenge.phases[index].name === 'Checkpoint Submission') {
if ((newChallenge.phases[index].name === 'Submission' && !is2RoundDesignChallenge) || newChallenge.phases[index].name === 'Checkpoint Submission') {
newChallenge.phases[index].isStartTimeActive = true
} else {
newChallenge.phases[index].isStartTimeActive = index <= 0
Expand Down
38 changes: 36 additions & 2 deletions src/components/ChallengesComponent/ChallengeCard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ class ChallengeCard extends React.Component {
isSaving: false,
isCheckChalengePermission: false,
hasEditChallengePermission: false,
loginUserRoleInProject: ''
loginUserRoleInProject: '',
currentPhase: this.getCurrentPhase(props.challenge),
forumLink: this.getForumLink(props.challenge)
}
this.onUpdateConfirm = this.onUpdateConfirm.bind(this)
this.onUpdateLaunch = this.onUpdateLaunch.bind(this)
Expand All @@ -130,6 +132,31 @@ class ChallengeCard extends React.Component {
this.onLaunchChallenge = this.onLaunchChallenge.bind(this)
}

getCurrentPhase (challenge) {
return challenge.phases.filter((p) => p.isOpen).map((p) => p.name).join(' / ') || '-'
}

getForumLink (challenge) {
const discussionsHaveUrls = (challenge.discussions || []).filter((p) => !!p.url)
return discussionsHaveUrls.length ? discussionsHaveUrls[0].url : ''
}

componentDidUpdate (prevProps) {
const { challenge } = this.props
if (!_.isEqual(challenge.phases, prevProps.challenge.phases)) {
// eslint-disable-next-line react/no-did-update-set-state
this.setState({
currentPhase: this.getCurrentPhase(challenge)
})
}
if (!_.isEqual(challenge.discussions, prevProps.challenge.discussions)) {
// eslint-disable-next-line react/no-did-update-set-state
this.setState({
forumLink: this.getForumLink(challenge)
})
}
}

onUpdateConfirm (value) {
this.setState({ isConfirm: value })
}
Expand Down Expand Up @@ -202,7 +229,7 @@ class ChallengeCard extends React.Component {
}

render () {
const { isLaunch, isConfirm, isSaving, isDeleteLaunch, isCheckChalengePermission, hasEditChallengePermission } = this.state
const { isLaunch, isConfirm, isSaving, isDeleteLaunch, isCheckChalengePermission, hasEditChallengePermission, currentPhase, forumLink } = this.state
const { setActiveProject, challenge, reloadChallengeList, isBillingAccountExpired, disableHover, getStatusText, challengeTypes, loginUserRoleInProject } = this.props
const deleteMessage = isCheckChalengePermission
? 'Checking permissions...'
Expand Down Expand Up @@ -279,6 +306,9 @@ class ChallengeCard extends React.Component {
<div className={styles.col3}>
{renderStatus(challenge.status.toUpperCase(), getStatusText)}
</div>
<div className={styles.col3}>
{currentPhase}
</div>
{
!isReadOnly && (
<div className={styles.col6}>
Expand All @@ -292,6 +322,10 @@ class ChallengeCard extends React.Component {
<div className={styles.col6}>
<a className={styles.link} href={communityAppUrl} target='_blank'>CA</a>
</div>
<div className={styles.col6}>
{forumLink ? (<a className={styles.link} href={forumLink} target='_blank'>CA</a>)
: (<a className={styles.link} href='javascript:void(0)'>Forum</a>)}
</div>
</div>
)
}
Expand Down
8 changes: 8 additions & 0 deletions src/components/ChallengesComponent/ChallengeList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -764,9 +764,17 @@ class ChallengeList extends Component {
{this.renderSortIcon('status')}
</span>
</div>
<div
className={cn(styles.col3)}
>
<span className={styles.filterItem}>
Phase
</span>
</div>
{!isReadOnly ? (<div className={styles.col6}>&nbsp;</div>) : null}
<div className={styles.col6}>&nbsp;</div>
<div className={styles.col6}>&nbsp;</div>
<div className={styles.col6}>&nbsp;</div>
</div>

{isLoading
Expand Down

0 comments on commit 8be49cf

Please sign in to comment.