Skip to content

Commit bb010f4

Browse files
Merge pull request #2 from topcoder-platform/integration-v5-challenge-api
Integration v5 challenge api
2 parents a1ad2ee + c7656cf commit bb010f4

File tree

5 files changed

+64
-17
lines changed

5 files changed

+64
-17
lines changed

__tests__/__snapshots__/index.js.snap

+10
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,16 @@ Object {
377377
"DEVELOP": "Development",
378378
"QA": "Quality Assurance",
379379
},
380+
"OLD_COMPETITION_TRACKS": Object {
381+
"DATA_SCIENCE": "DATA_SCIENCE",
382+
"DESIGN": "DESIGN",
383+
"DEVELOP": "DEVELOP",
384+
"QA": "QA",
385+
},
386+
"OLD_SUBTRACKS": Object {
387+
"BUG_HUNT": "BUG_HUNT",
388+
"TEST_SUITES": "TEST_SUITES",
389+
},
380390
"REVIEW_OPPORTUNITY_TYPES": Object {
381391
"Contest Review": "Review",
382392
"Iterative Review": "Iterative Review",

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"lint:js": "./node_modules/.bin/eslint --ext .js,.jsx .",
3232
"test": "npm run lint && npm run jest"
3333
},
34-
"version": "1000.19.51",
34+
"version": "1000.20.3",
3535
"dependencies": {
3636
"auth0-js": "^6.8.4",
3737
"config": "^3.2.0",

src/services/reviewOpportunities.js

+23-9
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,37 @@
44
* submitting applications.
55
*/
66
import _ from 'lodash';
7+
import { COMPETITION_TRACKS, OLD_COMPETITION_TRACKS, OLD_SUBTRACKS } from 'utils/tc';
78
import { getApi } from './api';
89

910
/**
1011
* Sync the fields of V3 and V5 for front-end to process successfully
11-
* @param challenges - challenges to normalize
12+
* @param opportunities - opportunities to normalize
1213
*/
13-
export function normalizeChallenges(challenges) {
14-
if (challenges) {
15-
_.map(challenges, (ch) => {
16-
const { challenge } = ch;
17-
if (challenge.technologies && challenge.technologies.includes('Data Science')) {
18-
challenge.track = 'DATA_SCIENCE';
14+
export function normalizeChallenges(opportunities) {
15+
if (opportunities) {
16+
/* Issue#4739 : Temporary add track to review opportunities challenges
17+
* until receive API V5 update. */
18+
_.map(opportunities, (opportunity) => {
19+
const { challenge } = opportunity;
20+
challenge.track = COMPETITION_TRACKS.DEVELOP;
21+
if (challenge.technologies) {
22+
if (challenge.technologies.includes(COMPETITION_TRACKS.DATA_SCIENCE)) {
23+
challenge.track = COMPETITION_TRACKS.DATA_SCIENCE;
24+
} else if (challenge.technologies.includes(OLD_COMPETITION_TRACKS.QA)) {
25+
challenge.track = COMPETITION_TRACKS.QA;
26+
}
27+
} else if (challenge.subTrack === OLD_SUBTRACKS.TEST_SUITES
28+
|| challenge.subTrack === OLD_SUBTRACKS.BUG_HUNT) {
29+
challenge.track = COMPETITION_TRACKS.QA;
30+
} else if (challenge.track === OLD_COMPETITION_TRACKS.DESIGN) {
31+
challenge.track = COMPETITION_TRACKS.DESIGN;
1932
}
20-
return _.defaults(ch, { challenge });
33+
return _.defaults(opportunity, { challenge });
2134
});
2235
}
23-
return challenges;
36+
37+
return opportunities;
2438
}
2539

2640
/**

src/utils/challenge/filter.js

+18-7
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ import { COMPETITION_TRACKS, REVIEW_OPPORTUNITY_TYPES } from '../tc';
7171
*/
7272

7373
function filterByGroupIds(challenge, state) {
74-
if (!state.groupIds) return true;
75-
return state.groupIds.some(id => challenge.groups[id]);
74+
if (_.isEmpty(state.groupIds)) return true;
75+
if (_.isEmpty(challenge.groups)) return false;
76+
return state.groupIds.some(id => challenge.groups.find(gId => gId === id));
7677
}
7778

7879
function filterByRegistrationOpen(challenge, state) {
@@ -144,12 +145,18 @@ function filterByStatus(challenge, state) {
144145
}
145146

146147
function filterByTags(challenge, state) {
147-
if (!state.tags) return true;
148+
if (_.isEmpty(state.tags)) return true;
148149
const { platforms, tags } = challenge;
149150
const str = `${platforms} ${tags}`.toLowerCase();
150151
return state.tags.some(tag => str.includes(tag.toLowerCase()));
151152
}
152153

154+
function filterByEvents(challenge, state) {
155+
if (_.isEmpty(state.events)) return true;
156+
if (_.isEmpty(challenge.events)) return false;
157+
return state.events.some(key => challenge.events.find(e => e.key === key));
158+
}
159+
153160
function filterByText(challenge, state) {
154161
if (!state.text) return true;
155162
const str = `${challenge.name} ${challenge.tags} ${challenge.platforms} ${challenge.tags}`
@@ -173,8 +180,11 @@ function filterByUpcoming(challenge, state) {
173180
}
174181

175182
function filterByUsers(challenge, state) {
176-
if (!state.userChallenges) return true;
177-
return state.userChallenges.find(ch => challenge.id === ch);
183+
const userId = _.get(state, 'userId', null);
184+
if (userId) {
185+
return _.get(challenge, ['users', userId], false);
186+
}
187+
return true;
178188
}
179189

180190
/**
@@ -214,6 +224,7 @@ export function getFilterFunction(state) {
214224
&& filterByGroupIds(challenge, state)
215225
&& filterByText(challenge, state)
216226
&& filterByTags(challenge, state)
227+
&& filterByEvents(challenge, state)
217228
&& filterByTypes(challenge, state)
218229
&& filterByUsers(challenge, state)
219230
&& filterByEndDate(challenge, state)
@@ -343,7 +354,7 @@ export function combine(...filters) {
343354
const res = {};
344355
filters.forEach((filter) => {
345356
combineEndDate(res, filter);
346-
combineArrayRules(res, filter, 'groups');
357+
combineArrayRules(res, filter, 'groupIds');
347358
/* TODO: The registrationOpen rule is just ignored for now. */
348359
combineStartDate(res, filter);
349360
combineArrayRules(res, filter, 'or', true);
@@ -380,7 +391,7 @@ export function combine(...filters) {
380391
*/
381392
export function mapToBackend(filter) {
382393
const res = {};
383-
if (filter.groups) res.groups = filter.groups;
394+
if (filter.groupIds) res.groups = filter.groupIds;
384395
return res;
385396
}
386397

src/utils/tc.js

+12
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ export const COMPETITION_TRACKS = {
1717
QA: 'Quality Assurance',
1818
};
1919

20+
export const OLD_COMPETITION_TRACKS = {
21+
DATA_SCIENCE: 'DATA_SCIENCE',
22+
DESIGN: 'DESIGN',
23+
DEVELOP: 'DEVELOP',
24+
QA: 'QA',
25+
};
26+
27+
export const OLD_SUBTRACKS = {
28+
TEST_SUITES: 'TEST_SUITES',
29+
BUG_HUNT: 'BUG_HUNT',
30+
};
31+
2032
/**
2133
* Review Opportunity types
2234
*/

0 commit comments

Comments
 (0)