Skip to content

Integration v5 challenge api #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions __tests__/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/services/challenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
32 changes: 23 additions & 9 deletions src/services/reviewOpportunities.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
25 changes: 18 additions & 7 deletions src/utils/challenge/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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}`
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down
12 changes: 12 additions & 0 deletions src/utils/tc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down