Skip to content

Commit 826b5ce

Browse files
author
vikasrohit
authored
Merge pull request #749 from topcoder-platform/develop
Handling challenge api refactoring
2 parents 57d6efd + 3f678a6 commit 826b5ce

File tree

23 files changed

+102
-68
lines changed

23 files changed

+102
-68
lines changed

config/constants/development.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports = {
1111
CHALLENGE_API_URL: `${DEV_API_HOSTNAME}/v5/challenges`,
1212
CHALLENGE_TIMELINE_TEMPLATES_URL: `${DEV_API_HOSTNAME}/v5/timeline-templates`,
1313
CHALLENGE_TYPES_URL: `${DEV_API_HOSTNAME}/v5/challenge-types`,
14+
CHALLENGE_TRACKS_URL: `${DEV_API_HOSTNAME}/v5/challenge-tracks`,
1415
CHALLENGE_PHASES_URL: `${DEV_API_HOSTNAME}/v5/challenge-phases`,
1516
CHALLENGE_TIMELINES_URL: `${DEV_API_HOSTNAME}/v5/challenge-timelines`,
1617
PROJECT_API_URL: `${DEV_API_HOSTNAME}/v5/projects`,
@@ -25,5 +26,10 @@ module.exports = {
2526
ONLINE_REVIEW_URL: `https://software.${DOMAIN}`,
2627
DEFAULT_TERM_UUID: 'ae6fc4ff-3bd1-4e3f-a987-cc60ab94b422', // Terms & Conditions of Use at TopCoder
2728
DEFAULT_NDA_UUID: '7245bb7d-d7c9-45a0-9603-d5ff05af0977', // Appirio NDA v2.0
28-
SUBMITTER_ROLE_UUID: '732339e7-8e30-49d7-9198-cccf9451e221'
29+
SUBMITTER_ROLE_UUID: '732339e7-8e30-49d7-9198-cccf9451e221',
30+
DEV_TRACK_ID: '9b6fc876-f4d9-4ccb-9dfd-419247628825',
31+
DES_TRACK_ID: '5fa04185-041f-49a6-bfd1-fe82533cd6c8',
32+
DS_TRACK_ID: 'c0f5d461-8219-4c14-878a-c3a3f356466d',
33+
QA_TRACK_ID: '36e6a8d0-7e1e-4608-a673-64279d99c115',
34+
SEGMENT_API_KEY: 'QBtLgV8vCiuRX1lDikbMjcoe9aCHkF6n'
2935
}

config/constants/production.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports = {
1111
CHALLENGE_API_URL: `${PROD_API_HOSTNAME}/v5/challenges`,
1212
CHALLENGE_TIMELINE_TEMPLATES_URL: `${PROD_API_HOSTNAME}/v5/timeline-templates`,
1313
CHALLENGE_TYPES_URL: `${PROD_API_HOSTNAME}/v5/challenge-types`,
14+
CHALLENGE_TRACKS_URL: `${DEV_API_HOSTNAME}/v5/challenge-tracks`,
1415
CHALLENGE_PHASES_URL: `${PROD_API_HOSTNAME}/v5/challenge-phases`,
1516
CHALLENGE_TIMELINES_URL: `${PROD_API_HOSTNAME}/v5/challenge-timelines`,
1617
PROJECT_API_URL: `${PROD_API_HOSTNAME}/v5/projects`,
@@ -25,5 +26,10 @@ module.exports = {
2526
ONLINE_REVIEW_URL: `https://software.${DOMAIN}`,
2627
DEFAULT_TERM_UUID: '5e217280-1413-4d4f-b183-454f348805ab', // Terms & Conditions of Use at TopCoder
2728
DEFAULT_NDA_UUID: '05342dcb-3405-445e-95b2-8ea2a3834b0d', // Appirio NDA v2.0
28-
SUBMITTER_ROLE_UUID: '732339e7-8e30-49d7-9198-cccf9451e221'
29+
SUBMITTER_ROLE_UUID: '732339e7-8e30-49d7-9198-cccf9451e221',
30+
DEV_TRACK_ID: '9b6fc876-f4d9-4ccb-9dfd-419247628825',
31+
DES_TRACK_ID: '5fa04185-041f-49a6-bfd1-fe82533cd6c8',
32+
DS_TRACK_ID: 'c0f5d461-8219-4c14-878a-c3a3f356466d',
33+
QA_TRACK_ID: '36e6a8d0-7e1e-4608-a673-64279d99c115',
34+
SEGMENT_API_KEY: 'QSQAW5BWmZfLoKFNRgNKaqHvLDLJoGqF'
2935
}

src/actions/challenges.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import {
1111
fetchChallengeTerms,
1212
fetchResources,
1313
fetchResourceRoles,
14-
fetchChallengeTimelines
14+
fetchChallengeTimelines,
15+
fetchChallengeTracks
1516
} from '../services/challenges'
1617
import {
1718
LOAD_CHALLENGE_DETAILS_PENDING,
@@ -229,6 +230,17 @@ export function loadChallengeTypes () {
229230
}
230231
}
231232

233+
export function loadChallengeTracks () {
234+
return async (dispatch) => {
235+
const challengeTracks = await fetchChallengeTracks()
236+
dispatch({
237+
type: LOAD_CHALLENGE_METADATA_SUCCESS,
238+
metadataKey: 'challengeTracks',
239+
metadataValue: challengeTracks
240+
})
241+
}
242+
}
243+
232244
export function loadChallengeTimelines () {
233245
return async (dispatch) => {
234246
const challengeTimelines = await fetchChallengeTimelines()

src/components/ChallengeEditor/ChallengeName-Field/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ const ChallengeNameField = ({ challenge, onUpdateInput }) => {
88
<>
99
<div className={styles.row}>
1010
<div className={cn(styles.field, styles.col1)}>
11-
<label htmlFor='challengeName'>Challenge Name <span>*</span> :</label>
11+
<label htmlFor='challengeName'>Work Name <span>*</span> :</label>
1212
</div>
1313
<div className={cn(styles.field, styles.col2)}>
14-
<input className={styles.challengeName} id='name' name='name' type='text' placeholder='Challenge Name' value={challenge.name} maxLength='200' required onChange={onUpdateInput} />
14+
<input className={styles.challengeName} id='name' name='name' type='text' placeholder='Work Name' value={challenge.name} maxLength='200' required onChange={onUpdateInput} />
1515
</div>
1616
</div>
1717
{ challenge.submitTriggered && !challenge.name && <div className={styles.row}>
1818
<div className={cn(styles.field, styles.col1)} />
1919
<div className={cn(styles.field, styles.col2, styles.error)}>
20-
Name is required field
20+
Work Name is required field
2121
</div>
2222
</div> }
2323
</>

src/components/ChallengeEditor/ChallengeView/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import Loader from '../../Loader'
2020

2121
const ChallengeView = ({ projectDetail, challenge, metadata, challengeResources, token, isLoading, challengeId }) => {
2222
const selectedType = _.find(metadata.challengeTypes, { id: challenge.typeId })
23+
const challengeTrack = _.find(metadata.challengeTracks, { id: challenge.trackId })
2324

2425
const [openAdvanceSettings, setOpenAdvanceSettings] = useState(false)
2526

@@ -73,7 +74,7 @@ const ChallengeView = ({ projectDetail, challenge, metadata, challengeResources,
7374
</div>
7475
<div className={styles.col}>
7576
<span className={styles.fieldTitle}>Track:</span>
76-
<Track disabled type={challenge.track} isActive key={challenge.track} onUpdateOthers={() => {}} />
77+
<Track disabled type={challengeTrack} isActive key={challenge.trackId} onUpdateOthers={() => {}} />
7778
</div>
7879
<div className={styles.col}>
7980
<span><span className={styles.fieldTitle}>Type:</span> {selectedType ? selectedType.name : ''}</span>

src/components/ChallengeEditor/ReviewType-Field/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const ReviewTypeField = ({ reviewers, challenge, onUpdateOthers, onUpdateSelect
1212
<div>
1313
<div className={styles.row}>
1414
<div className={cn(styles.field, styles.col1)}>
15-
<label htmlFor='reviewType'>Review Type <span>*</span> :</label>
15+
<label htmlFor='reviewType'>Reviewer <span>*</span> :</label>
1616
</div>
1717
<div className={cn(styles.field, styles.col2)}>
1818
<div className={styles.subGroup}>

src/components/ChallengeEditor/TextEditor-Field/index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ class TextEditorField extends Component {
3636
readOnly
3737
} = this.props
3838
const { addedNewPrivateDescription } = this.state
39-
const challengeTrack = challenge.legacy
40-
? challenge.legacy.track
41-
: challenge.track
4239
const challengeTagsFiltered = challengeTags.map(function (tag) {
4340
return { id: tag.name, name: tag.name }
4441
})
@@ -84,7 +81,7 @@ class TextEditorField extends Component {
8481
onUpdateMultiSelect={onUpdateMultiSelect}
8582
readOnly={readOnly}
8683
/>
87-
{challengeTrack && challengeTrack === CHALLENGE_TRACKS.DESIGN && (
84+
{challenge.trackId === CHALLENGE_TRACKS.DESIGN && (
8885
<React.Fragment>
8986
<FinalDeliverablesField
9087
challenge={challenge}

src/components/ChallengeEditor/Track-Field/index.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,31 @@ import _ from 'lodash'
33
import React from 'react'
44
import PropTypes from 'prop-types'
55
import styles from './Track-Field.module.scss'
6-
7-
import { CHALLENGE_TRACKS } from '../../../config/constants'
86
import Track from '../../Track'
97

10-
const TrackField = ({ challenge, onUpdateOthers, disabled }) => {
8+
const TrackField = ({ challenge, tracks, onUpdateOthers, disabled }) => {
119
const renderTracks = (track, currentTrack) => {
1210
return (
13-
<Track disabled={disabled} type={track} isActive={track === currentTrack} key={track} onUpdateOthers={onUpdateOthers} />
11+
<Track disabled={disabled} type={track} isActive={track.id === currentTrack} key={track.id} onUpdateOthers={onUpdateOthers} />
1412
)
1513
}
1614

1715
return (
1816
<>
1917
<div className={styles.row}>
2018
<div className={cn(styles.field, styles.col1)}>
21-
<label htmlFor='track'>Track <span>*</span> :</label>
19+
<label htmlFor='track'>Work Type <span>*</span> :</label>
2220
</div>
2321
<div className={cn(styles.field, styles.col2)}>
2422
{
25-
_.map(CHALLENGE_TRACKS, track => renderTracks(track, challenge.track))
23+
_.map(tracks, track => renderTracks(track, challenge.trackId))
2624
}
2725
</div>
2826
</div>
2927
{ challenge.submitTriggered && !challenge.track && <div className={styles.row}>
3028
<div className={cn(styles.field, styles.col1)} />
3129
<div className={cn(styles.field, styles.col2, styles.error)}>
32-
Track is required field
30+
Work Type is required field
3331
</div>
3432
</div> }
3533
</>

src/components/ChallengeEditor/Type-Field/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ const TypeField = ({ types, onUpdateSelect, challenge, disabled }) => {
1010
<>
1111
<div className={styles.row}>
1212
<div className={cn(styles.field, styles.col1)}>
13-
<label htmlFor='type'>Type <span>*</span> :</label>
13+
<label htmlFor='type'>Work Format <span>*</span> :</label>
1414
</div>
1515
<div className={cn(styles.field, styles.col2, { [styles.disabled]: disabled })}>
1616
<Select
1717
name='track'
18-
options={_.filter(types, t => t.isActive && t.track === challenge.track)}
18+
options={_.filter(types, t => t.isActive)}
1919
value={challenge.typeId}
20-
placeholder='Track Type'
20+
placeholder='Work Format'
2121
labelKey='name'
2222
valueKey='id'
2323
clearable={false}
@@ -29,7 +29,7 @@ const TypeField = ({ types, onUpdateSelect, challenge, disabled }) => {
2929
{ challenge.submitTriggered && !challenge.typeId && <div className={styles.row}>
3030
<div className={cn(styles.field, styles.col1)} />
3131
<div className={cn(styles.field, styles.col2, styles.error)}>
32-
Type is required field
32+
Work Format is required field
3333
</div>
3434
</div> }
3535
</>

src/components/ChallengeEditor/index.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ const theme = {
5555

5656
const getTitle = (isNew) => {
5757
if (isNew) {
58-
return 'Create New Challenge'
58+
return 'Create New Work'
5959
}
6060

61-
return 'Edit Challenge'
61+
return 'Set-Up Work'
6262
}
6363

6464
class ChallengeEditor extends Component {
@@ -508,8 +508,8 @@ class ChallengeEditor extends Component {
508508
isValidChallenge () {
509509
const { challenge } = this.state
510510
if (this.props.isNew) {
511-
const { name, track, typeId } = challenge
512-
return !!name && !!track && !!typeId
511+
const { name, trackId, typeId } = challenge
512+
return !!name && !!trackId && !!typeId
513513
}
514514

515515
const reviewType = challenge.reviewType ? challenge.reviewType.toLowerCase() : 'community'
@@ -523,7 +523,7 @@ class ChallengeEditor extends Component {
523523
}
524524

525525
return !(Object.values(pick([
526-
'track',
526+
'trackId',
527527
'typeId',
528528
'name',
529529
'description',
@@ -586,7 +586,7 @@ class ChallengeEditor extends Component {
586586
const challenge = pick([
587587
'phases',
588588
'typeId',
589-
'track',
589+
'trackId',
590590
'name',
591591
'description',
592592
'privateDescription',
@@ -599,8 +599,7 @@ class ChallengeEditor extends Component {
599599
'prizeSets'
600600
], this.state.challenge)
601601
challenge.legacy = _.assign(this.state.challenge.legacy, {
602-
reviewType: challenge.reviewType,
603-
track: challenge.track
602+
reviewType: challenge.reviewType
604603
})
605604
challenge.timelineTemplateId = _.get(this.getCurrentTemplate(), 'id')
606605
challenge.projectId = this.props.projectId
@@ -618,7 +617,6 @@ class ChallengeEditor extends Component {
618617
], p))
619618
if (challenge.terms && challenge.terms.length === 0) delete challenge.terms
620619
delete challenge.attachments
621-
delete challenge.track
622620
delete challenge.reviewType
623621
return _.cloneDeep(challenge)
624622
}
@@ -632,7 +630,7 @@ class ChallengeEditor extends Component {
632630
async createNewChallenge () {
633631
if (!this.props.isNew) return
634632
const { metadata } = this.props
635-
const { name, track, typeId } = this.state.challenge
633+
const { name, trackId, typeId } = this.state.challenge
636634
const { timelineTemplates } = metadata
637635

638636
// fallback template
@@ -646,9 +644,9 @@ class ChallengeEditor extends Component {
646644
projectId: this.props.projectId,
647645
name,
648646
typeId,
647+
trackId,
649648
startDate: moment().add(1, 'days').format(),
650649
legacy: {
651-
track,
652650
reviewType: 'community'
653651
},
654652
descriptionFormat: 'markdown',
@@ -996,7 +994,7 @@ class ChallengeEditor extends Component {
996994
isNew && (
997995
<div className={styles.buttonContainer}>
998996
<div className={styles.button}>
999-
<OutlineButton text={'Create Challenge'} type={'success'} submit />
997+
<OutlineButton text={'Continue Set-Up'} type={'success'} submit />
1000998
</div>
1001999
</div>
10021000
)
@@ -1023,13 +1021,14 @@ class ChallengeEditor extends Component {
10231021
}
10241022
</React.Fragment>
10251023
const selectedType = _.find(metadata.challengeTypes, { id: challenge.typeId })
1024+
const challengeTrack = _.find(metadata.challengeTracks, { id: challenge.trackId })
10261025
const currentChallengeId = this.getCurrentChallengeId()
10271026
const showTimeline = false // disables the timeline for time being https://github.com/topcoder-platform/challenge-engine-ui/issues/706
10281027
const challengeForm = isNew
10291028
? (
10301029
<form name='challenge-new-form' noValidate autoComplete='off' onSubmit={this.createChallengeHandler}>
10311030
<div className={styles.newFormContainer}>
1032-
<TrackField challenge={challenge} onUpdateOthers={this.onUpdateOthers} />
1031+
<TrackField tracks={metadata.challengeTracks} challenge={challenge} onUpdateOthers={this.onUpdateOthers} />
10331032
<TypeField types={metadata.challengeTypes} onUpdateSelect={this.onUpdateSelect} challenge={challenge} />
10341033
<ChallengeNameField challenge={challenge} onUpdateInput={this.onUpdateInput} />
10351034
</div>
@@ -1050,7 +1049,7 @@ class ChallengeEditor extends Component {
10501049
</div>
10511050
<div className={styles.col}>
10521051
<span className={styles.fieldTitle}>Track:</span>
1053-
<Track disabled type={challenge.track} isActive key={challenge.track} onUpdateOthers={() => {}} />
1052+
<Track disabled type={challengeTrack} isActive key={challenge.trackId} onUpdateOthers={() => {}} />
10541053
</div>
10551054
<div className={styles.col}>
10561055
<span><span className={styles.fieldTitle}>Type:</span> {selectedType ? selectedType.name : ''}</span>

src/components/ChallengesComponent/ChallengeCard/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ class ChallengeCard extends React.Component {
242242
<Link className={styles.col1} to={`/projects/${challenge.projectId}/challenges/${challenge.id}/view`}>
243243
<div className={styles.name}>
244244
<span className={styles.block}>{challenge.name}</span>
245-
<ChallengeTag track={challenge.legacy && challenge.legacy.track} challengeType={challenge.type} />
245+
<ChallengeTag track={challenge.trackId} challengeType={challenge.type} />
246246
</div>
247247
</Link>
248248
<Link className={styles.col2} to={`/projects/${challenge.projectId}/challenges/${challenge.id}/view`}>

src/components/ChallengesComponent/ChallengeTag/ChallengeTag.module.scss

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,3 @@
3838
color: $white;
3939
background-color: $light-blue;
4040
}
41-
42-
.design {
43-
color: $white;
44-
background-color: $green;
45-
}

src/components/Sidebar/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const Sidebar = ({
1414
return (
1515
<div className={styles.sidebar}>
1616
<img src={TopcoderLogo} className={styles.logo} />
17-
<div className={styles.title}>Challenge Editor</div>
17+
<div className={styles.title}>Work Manager</div>
1818
<Link to='/'>
1919
<div className={cn(styles.homeLink, { [styles.active]: !projectId })} onClick={resetSidebarActiveParams}>
2020
Active challenges

src/components/Tag/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ const stylizedSubTrack = (t, challengeTypes) => {
2828
)
2929
}
3030

31+
/**
32+
* ***************** UNUSED **************************
33+
*/
3134
const Tag = ({ track, subTrack, value, challengeTypes, roleTag }) => {
3235
const className = cn(styles.tag, {
3336
[styles.dataScience]: track === CHALLENGE_TRACKS.DATA_SCIENCE,

src/components/Track/index.js

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,19 @@ import React from 'react'
22
import PropTypes from 'prop-types'
33
import cn from 'classnames'
44
import ReactSVG from 'react-svg'
5-
import { CHALLENGE_TRACKS } from '../../config/constants'
65
import styles from './Track.module.scss'
76

87
const assets = require.context('../../assets/images/tracks', false, /svg/)
98

109
const Track = ({ type, isActive, onUpdateOthers, disabled }) => {
11-
const icon = `./${type.toLowerCase()}.svg`
12-
const getName = (type) => {
13-
switch (type.toUpperCase()) {
14-
case CHALLENGE_TRACKS.DEVELOP:
15-
return 'Development'
16-
case CHALLENGE_TRACKS.DESIGN:
17-
return 'Design'
18-
case CHALLENGE_TRACKS.DATA_SCIENCE:
19-
return 'Data Science'
20-
case CHALLENGE_TRACKS.QA:
21-
return CHALLENGE_TRACKS.QA
22-
default:
23-
return ''
24-
}
25-
}
10+
const icon = `./${type.abbreviation.toLowerCase()}.svg`
2611

2712
return (
28-
<div className={cn(styles.container, { [styles.active]: isActive, [styles.disabled]: disabled })} onClick={() => onUpdateOthers({ field: 'track', value: type })}>
13+
<div className={cn(styles.container, { [styles.active]: isActive, [styles.disabled]: disabled })} onClick={() => onUpdateOthers({ field: 'trackId', value: type.id })}>
2914
<div className={styles.icon}>
3015
{ assets && assets.keys().includes(icon) ? <ReactSVG path={assets(`${icon}`)} /> : '' }
3116
</div>
32-
<span className={styles.name}>{getName(type)}</span>
17+
<span className={styles.name}>{type.name}</span>
3318
</div>
3419
)
3520
}
@@ -40,7 +25,7 @@ Track.defaultProps = {
4025
}
4126

4227
Track.propTypes = {
43-
type: PropTypes.string.isRequired,
28+
type: PropTypes.object.isRequired,
4429
isActive: PropTypes.bool,
4530
disabled: PropTypes.bool,
4631
onUpdateOthers: PropTypes.func.isRequired

0 commit comments

Comments
 (0)