Skip to content

Commit 770c6b4

Browse files
Merge pull request #266 from topcoder-platform/feature-refactor-challengelist
Sync feature refactor challengelist with develop
2 parents b06ca4f + aaef421 commit 770c6b4

File tree

5 files changed

+107
-38
lines changed

5 files changed

+107
-38
lines changed

__tests__/__snapshots__/index.js.snap

+4-3
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ Object {
303303
"SUBMISSION_END_DATE": "submissionEndDate",
304304
},
305305
"default": undefined,
306+
"getFilterUrl": [Function],
306307
"getService": [Function],
307308
"normalizeChallenge": [Function],
308309
},
@@ -378,9 +379,9 @@ Object {
378379
"DRAFT": "Draft",
379380
},
380381
"COMPETITION_TRACKS": Object {
381-
"DATA_SCIENCE": "Data Science",
382-
"DESIGN": "Design",
383-
"DEVELOP": "Development",
382+
"DES": "Design",
383+
"DEV": "Development",
384+
"DS": "Data Science",
384385
"QA": "Quality Assurance",
385386
},
386387
"OLD_COMPETITION_TRACKS": Object {

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": "1.0.7",
34+
"version": "1000.24.1",
3535
"dependencies": {
3636
"auth0-js": "^6.8.4",
3737
"config": "^3.2.0",

src/services/challenges.js

+60-11
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,40 @@ import { getApi } from './api';
1515
import { getService as getMembersService } from './members';
1616
import { getService as getSubmissionsService } from './submissions';
1717

18+
export function getFilterUrl(backendFilter, frontFilter) {
19+
const ff = _.clone(frontFilter);
20+
// eslint-disable-next-line object-curly-newline
21+
const { tags, tracks, types, groups } = ff;
22+
delete ff.tags;
23+
delete ff.tracks;
24+
delete ff.types;
25+
delete ff.communityId;
26+
delete ff.groups;
27+
28+
// console.log(ff);
29+
30+
let urlFilter = qs.stringify(_.reduce(ff, (result, value, key) => {
31+
// eslint-disable-next-line no-param-reassign
32+
if (value) result[key] = value;
33+
return result;
34+
}, {}));
35+
// console.log(urlFilter);
36+
37+
const ftags = _.map(tags, val => `tags[]=${val}`).join('&');
38+
const ftracks = _.map(_.reduce(tracks, (result, value, key) => {
39+
// eslint-disable-next-line no-unused-expressions
40+
tracks[key] && result.push(key);
41+
return result;
42+
}, []), val => `tracks[]=${val}`).join('&');
43+
const ftypes = _.map(types, val => `types[]=${val}`).join('&');
44+
const fgroups = _.map(groups, val => `groups[]=${val}`).join('&');
45+
if (ftags.length > 0) urlFilter += `&${ftags}`;
46+
if (ftracks.length > 0) urlFilter += `&${ftracks}`;
47+
if (ftypes.length > 0) urlFilter += `&${ftypes}`;
48+
if (fgroups.length > 9) urlFilter += `&${fgroups}`;
49+
return urlFilter;
50+
}
51+
1852
export const ORDER_BY = {
1953
SUBMISSION_END_DATE: 'submissionEndDate',
2054
};
@@ -133,14 +167,12 @@ class ChallengesService {
133167
*/
134168
const getChallenges = async (
135169
endpoint,
136-
filters = {},
137-
params = {},
170+
filter,
138171
) => {
139-
const query = {
140-
...filters,
141-
...params,
142-
};
143-
const url = `${endpoint}?${qs.stringify(query)}`;
172+
// console.log(filter);
173+
const query = getFilterUrl(filter.backendFilter, filter.frontFilter);
174+
const url = `${endpoint}?${query}`;
175+
// console.log(url);
144176
const res = await this.private.apiV5.get(url).then(checkErrorV5);
145177
return {
146178
challenges: res.result || [],
@@ -154,6 +186,22 @@ class ChallengesService {
154186
},
155187
};
156188
};
189+
190+
const getChallengeDetails = async (
191+
endpoint,
192+
legacyInfo,
193+
) => {
194+
let query = '';
195+
if (legacyInfo) {
196+
query = `legacyId=${legacyInfo.legacyId}`;
197+
}
198+
const url = `${endpoint}?${query}`;
199+
const res = await this.private.apiV5.get(url).then(checkErrorV5);
200+
return {
201+
challenges: res.result || [],
202+
};
203+
};
204+
157205
/**
158206
* Private function being re-used in all methods related to getting
159207
* challenges. It handles query-related arguments in the uniform way:
@@ -189,6 +237,7 @@ class ChallengesService {
189237
apiV2: getApi('V2', tokenV2),
190238
apiV3: getApi('V3', tokenV3),
191239
getChallenges,
240+
getChallengeDetails,
192241
getMemberChallenges,
193242
tokenV2,
194243
tokenV3,
@@ -327,10 +376,10 @@ class ChallengesService {
327376
// condition based on ROUTE used for Review Opportunities, change if needed
328377
if (/^[\d]{5,8}$/.test(challengeId)) {
329378
isLegacyChallenge = true;
330-
challenge = await this.private.getChallenges('/challenges/', { legacyId: challengeId })
379+
challenge = await this.private.getChallengeDetails('/challenges/', { legacyId: challengeId })
331380
.then(res => res.challenges[0] || {});
332381
} else {
333-
challenge = await this.private.getChallenges(`/challenges/${challengeId}`)
382+
challenge = await this.private.getChallengeDetails(`/challenges/${challengeId}`)
334383
.then(res => res.challenges);
335384
}
336385

@@ -464,8 +513,8 @@ class ChallengesService {
464513
* @param {Object} params Optional.
465514
* @return {Promise} Resolves to the api response.
466515
*/
467-
async getChallenges(filters, params) {
468-
return this.private.getChallenges('/challenges/', filters, params)
516+
async getChallenges(filter) {
517+
return this.private.getChallenges('/challenges/', filter)
469518
.then((res) => {
470519
res.challenges.forEach(item => normalizeChallenge(item));
471520
return res;

src/utils/challenge/filter.js

+39-20
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ function filterByStatus(challenge, state) {
147147
function filterByTags(challenge, state) {
148148
if (_.isEmpty(state.tags)) return true;
149149
const { platforms, tags } = challenge;
150-
const str = `${platforms} ${tags}`.toLowerCase();
150+
const str = `${platforms.join(' ')} ${tags.join(' ')}`.toLowerCase();
151151
return state.tags.some(tag => str.includes(tag.toLowerCase()));
152152
}
153153

@@ -158,19 +158,20 @@ function filterByEvents(challenge, state) {
158158
}
159159

160160
function filterByText(challenge, state) {
161-
if (!state.text) return true;
161+
if (!state.name) return true;
162162
const str = `${challenge.name} ${challenge.tags} ${challenge.platforms} ${challenge.tags}`
163163
.toLowerCase();
164-
return str.includes(state.text.toLowerCase());
164+
return str.includes(state.name.toLowerCase());
165165
}
166166

167167
function filterByTrack(challenge, state) {
168-
if (!state.tracks) return true;
169-
return _.keys(state.tracks).some(track => challenge.track === track);
168+
// if (!state.tracks) return true;
169+
// eslint-disable-next-line max-len
170+
return state.tracks[challenge.track] === true;
170171
}
171172

172173
function filterByTypes(challenge, state) {
173-
if (!state.types) return true;
174+
if (state.types.length === 0) return true;
174175
return state.types.includes(challenge.typeId);
175176
}
176177

@@ -179,10 +180,10 @@ function filterByUpcoming(challenge, state) {
179180
return moment().isBefore(challenge.registrationStartDate);
180181
}
181182

182-
function filterByUsers(challenge, state) {
183-
if (!state.userChallenges) return true;
184-
return state.userChallenges.find(ch => challenge.id === ch);
185-
}
183+
// function filterByUsers(challenge, state) {
184+
// if (!state.userChallenges) return true;
185+
// return state.userChallenges.find(ch => challenge.id === ch);
186+
// }
186187

187188
/**
188189
* Returns clone of the state with the specified competition track added.
@@ -223,7 +224,7 @@ export function getFilterFunction(state) {
223224
&& filterByTags(challenge, state)
224225
&& filterByEvents(challenge, state)
225226
&& filterByTypes(challenge, state)
226-
&& filterByUsers(challenge, state)
227+
// && filterByUsers(challenge, state)
227228
&& filterByEndDate(challenge, state)
228229
&& filterByStartDate(challenge, state)
229230
&& filterByStarted(challenge, state)
@@ -247,7 +248,14 @@ export function getFilterFunction(state) {
247248
*/
248249
export function getReviewOpportunitiesFilterFunction(state, validTypes) {
249250
return (opp) => {
250-
const newType = _.find(validTypes, { name: opp.challenge.type }) || {};
251+
const trackAbbr = {
252+
DATA_SCIENCE: 'DS',
253+
DEVELOP: 'Dev',
254+
DESIGN: 'Des',
255+
QA: 'QA',
256+
};
257+
// const newType = _.find(validTypes, { name: opp.challenge.type }) || {};
258+
const newType = _.find(validTypes, { name: opp.challenge.subTrack === 'FIRST_2_FINISH' ? 'First2Finish' : 'Challenge' }) || {};
251259

252260
// Review Opportunity objects have a challenge field which
253261
// is largely compatible with many of the existing filter functions
@@ -256,21 +264,32 @@ export function getReviewOpportunitiesFilterFunction(state, validTypes) {
256264
...opp.challenge,
257265
// This allows filterByText to search for Review Types and Challenge Titles
258266
name: `${opp.challenge.title} ${REVIEW_OPPORTUNITY_TYPES[opp.type]}`,
259-
registrationStartDate: opp.startDate, // startDate of Review, not Challenge
260-
submissionEndDate: opp.startDate, // Currently uses startDate for both date comparisons
261-
communities: new Set([ // Used to filter by Track, and communities at a future date
262-
opp.challenge.track.toLowerCase(),
263-
]),
264-
typeId: newType.id,
267+
// registrationStartDate: opp.startDate, // startDate of Review, not Challenge
268+
// submissionEndDate: opp.startDate, // Currently uses startDate for both date comparisons
269+
// communities: new Set([ // Used to filter by Track, and communities at a future date
270+
// opp.challenge.track === 'QA' ? 'Dev' : trackAbbr[opp.challenge.track],
271+
// ]),
272+
track: trackAbbr[opp.challenge.track],
273+
typeId: newType.abbreviation,
265274
tags: opp.challenge.technologies || [],
266275
platforms: opp.challenge.platforms || [],
267276
};
268-
277+
/**
278+
console.log(challenge);
279+
console.log(`=====`);
280+
console.log(`11111`);
281+
console.log(filterByTrack(challenge, state));
282+
console.log(filterByText(challenge, state));
283+
console.log(filterByTags(challenge, state));
284+
console.log(filterByEndDate(challenge, state));
285+
console.log(filterByStartDate(challenge, state));
286+
console.log(filterByReviewOpportunityType(opp, state));
287+
*/
269288
return (
270289
filterByTrack(challenge, state)
271290
&& filterByText(challenge, state)
272291
&& filterByTags(challenge, state)
273-
// && filterByTypes(challenge, state)
292+
&& filterByTypes(challenge, state)
274293
&& filterByEndDate(challenge, state)
275294
&& filterByStartDate(challenge, state)
276295
&& filterByReviewOpportunityType(opp, state)

src/utils/tc.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
* uses upper-case literals to encode the tracks. At some point, we should
1212
* update it in this code as well! */
1313
export const COMPETITION_TRACKS = {
14-
DATA_SCIENCE: 'Data Science',
15-
DESIGN: 'Design',
16-
DEVELOP: 'Development',
14+
DS: 'Data Science',
15+
DES: 'Design',
16+
DEV: 'Development',
1717
QA: 'Quality Assurance',
1818
};
1919

0 commit comments

Comments
 (0)