diff --git a/__tests__/__snapshots__/index.js.snap b/__tests__/__snapshots__/index.js.snap index 53d2317a..bf72ddb8 100644 --- a/__tests__/__snapshots__/index.js.snap +++ b/__tests__/__snapshots__/index.js.snap @@ -377,6 +377,16 @@ Object { "DEVELOP": "Development", "QA": "Quality Assurance", }, + "OLD_COMPETITION_TRACKS": Object { + "DATA_SCIENCE": "DATA_SCIENCE", + "DESIGN": "DESIGN", + "DEVELOP": "DEVELOP", + "QA": "QA", + }, + "OLD_SUBTRACKS": Object { + "BUG_HUNT": "BUG_HUNT", + "TEST_SUITES": "TEST_SUITES", + }, "REVIEW_OPPORTUNITY_TYPES": Object { "Contest Review": "Review", "Iterative Review": "Iterative Review", diff --git a/package.json b/package.json index 35c82bc4..8086c298 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "lint:js": "./node_modules/.bin/eslint --ext .js,.jsx .", "test": "npm run lint && npm run jest" }, - "version": "1000.19.51", + "version": "1000.20.3", "dependencies": { "auth0-js": "^6.8.4", "config": "^3.2.0", diff --git a/src/services/challenges.js b/src/services/challenges.js index fd0fecec..5f497304 100644 --- a/src/services/challenges.js +++ b/src/services/challenges.js @@ -328,7 +328,7 @@ class ChallengesService { if (/^[\d]{5,8}$/.test(challengeId)) { isLegacyChallenge = true; challenge = await this.private.getChallenges('/challenges/', { legacyId: challengeId }) - .then(res => res.challenges[0]); + .then(res => res.challenges); } else { challenge = await this.private.getChallenges(`/challenges/${challengeId}`) .then(res => res.challenges); diff --git a/src/services/reviewOpportunities.js b/src/services/reviewOpportunities.js index 51af9e44..87f8dcd3 100644 --- a/src/services/reviewOpportunities.js +++ b/src/services/reviewOpportunities.js @@ -4,23 +4,37 @@ * submitting applications. */ import _ from 'lodash'; +import { COMPETITION_TRACKS, OLD_COMPETITION_TRACKS, OLD_SUBTRACKS } from 'utils/tc'; import { getApi } from './api'; /** * Sync the fields of V3 and V5 for front-end to process successfully - * @param challenges - challenges to normalize + * @param opportunities - opportunities to normalize */ -export function normalizeChallenges(challenges) { - if (challenges) { - _.map(challenges, (ch) => { - const { challenge } = ch; - if (challenge.technologies && challenge.technologies.includes('Data Science')) { - challenge.track = 'DATA_SCIENCE'; +export function normalizeChallenges(opportunities) { + if (opportunities) { + /* Issue#4739 : Temporary add track to review opportunities challenges + * until receive API V5 update. */ + _.map(opportunities, (opportunity) => { + const { challenge } = opportunity; + challenge.track = COMPETITION_TRACKS.DEVELOP; + if (challenge.technologies) { + if (challenge.technologies.includes(COMPETITION_TRACKS.DATA_SCIENCE)) { + challenge.track = COMPETITION_TRACKS.DATA_SCIENCE; + } else if (challenge.technologies.includes(OLD_COMPETITION_TRACKS.QA)) { + challenge.track = COMPETITION_TRACKS.QA; + } + } else if (challenge.subTrack === OLD_SUBTRACKS.TEST_SUITES + || challenge.subTrack === OLD_SUBTRACKS.BUG_HUNT) { + challenge.track = COMPETITION_TRACKS.QA; + } else if (challenge.track === OLD_COMPETITION_TRACKS.DESIGN) { + challenge.track = COMPETITION_TRACKS.DESIGN; } - return _.defaults(ch, { challenge }); + return _.defaults(opportunity, { challenge }); }); } - return challenges; + + return opportunities; } /** diff --git a/src/utils/challenge/filter.js b/src/utils/challenge/filter.js index 263c3132..549a36c3 100644 --- a/src/utils/challenge/filter.js +++ b/src/utils/challenge/filter.js @@ -71,8 +71,9 @@ import { COMPETITION_TRACKS, REVIEW_OPPORTUNITY_TYPES } from '../tc'; */ function filterByGroupIds(challenge, state) { - if (!state.groupIds) return true; - return state.groupIds.some(id => challenge.groups[id]); + if (_.isEmpty(state.groupIds)) return true; + if (_.isEmpty(challenge.groups)) return false; + return state.groupIds.some(id => challenge.groups.find(gId => gId === id)); } function filterByRegistrationOpen(challenge, state) { @@ -144,12 +145,18 @@ function filterByStatus(challenge, state) { } function filterByTags(challenge, state) { - if (!state.tags) return true; + if (_.isEmpty(state.tags)) return true; const { platforms, tags } = challenge; const str = `${platforms} ${tags}`.toLowerCase(); return state.tags.some(tag => str.includes(tag.toLowerCase())); } +function filterByEvents(challenge, state) { + if (_.isEmpty(state.events)) return true; + if (_.isEmpty(challenge.events)) return false; + return state.events.some(key => challenge.events.find(e => e.key === key)); +} + function filterByText(challenge, state) { if (!state.text) return true; const str = `${challenge.name} ${challenge.tags} ${challenge.platforms} ${challenge.tags}` @@ -173,8 +180,11 @@ function filterByUpcoming(challenge, state) { } function filterByUsers(challenge, state) { - if (!state.userChallenges) return true; - return state.userChallenges.find(ch => challenge.id === ch); + const userId = _.get(state, 'userId', null); + if (userId) { + return _.get(challenge, ['users', userId], false); + } + return true; } /** @@ -214,6 +224,7 @@ export function getFilterFunction(state) { && filterByGroupIds(challenge, state) && filterByText(challenge, state) && filterByTags(challenge, state) + && filterByEvents(challenge, state) && filterByTypes(challenge, state) && filterByUsers(challenge, state) && filterByEndDate(challenge, state) @@ -343,7 +354,7 @@ export function combine(...filters) { const res = {}; filters.forEach((filter) => { combineEndDate(res, filter); - combineArrayRules(res, filter, 'groups'); + combineArrayRules(res, filter, 'groupIds'); /* TODO: The registrationOpen rule is just ignored for now. */ combineStartDate(res, filter); combineArrayRules(res, filter, 'or', true); @@ -380,7 +391,7 @@ export function combine(...filters) { */ export function mapToBackend(filter) { const res = {}; - if (filter.groups) res.groups = filter.groups; + if (filter.groupIds) res.groups = filter.groupIds; return res; } diff --git a/src/utils/tc.js b/src/utils/tc.js index 5388d4bb..28bcf3b2 100644 --- a/src/utils/tc.js +++ b/src/utils/tc.js @@ -17,6 +17,18 @@ export const COMPETITION_TRACKS = { QA: 'Quality Assurance', }; +export const OLD_COMPETITION_TRACKS = { + DATA_SCIENCE: 'DATA_SCIENCE', + DESIGN: 'DESIGN', + DEVELOP: 'DEVELOP', + QA: 'QA', +}; + +export const OLD_SUBTRACKS = { + TEST_SUITES: 'TEST_SUITES', + BUG_HUNT: 'BUG_HUNT', +}; + /** * Review Opportunity types */