Skip to content

Commit 6642805

Browse files
authored
Merge pull request topcoder-platform#272 from topcoder-platform/develop
Release 2020-10-09
2 parents cb24288 + 7c653ab commit 6642805

File tree

8 files changed

+124
-51
lines changed

8 files changed

+124
-51
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
- attach_workspace:
2929
at: .
3030
- run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
31-
- run: npm publish
31+
- run: npm publish --tag test-release
3232
# dont change anything
3333
workflows:
3434
version: 2

__tests__/__snapshots__/index.js.snap

Lines changed: 4 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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.6",
3535
"dependencies": {
3636
"auth0-js": "^6.8.4",
3737
"config": "^3.2.0",

src/reducers/challenge.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ export function factory(options = {}) {
471471
const challengeDetails = _.get(res, 'payload', {});
472472
const track = _.get(challengeDetails, 'track', '');
473473
let checkpointsPromise = null;
474-
if (track === COMPETITION_TRACKS.DESIGN) {
474+
if (track === COMPETITION_TRACKS.DES) {
475475
const p = _.get(challengeDetails, 'phases', [])
476476
.filter(x => x.name === 'Checkpoint Review');
477477
if (p.length && !p[0].isOpen) {

src/services/challenges.js

Lines changed: 70 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,43 @@ 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, events } = ff;
22+
delete ff.tags;
23+
delete ff.tracks;
24+
delete ff.types;
25+
delete ff.communityId;
26+
delete ff.groups;
27+
delete ff.events;
28+
29+
// console.log(ff);
30+
31+
let urlFilter = qs.stringify(_.reduce(ff, (result, value, key) => {
32+
// eslint-disable-next-line no-param-reassign
33+
if (value) result[key] = value;
34+
return result;
35+
}, {}));
36+
// console.log(urlFilter);
37+
38+
const ftags = _.map(tags, val => `tags[]=${val}`).join('&');
39+
const ftracks = _.map(_.reduce(tracks, (result, value, key) => {
40+
// eslint-disable-next-line no-unused-expressions
41+
tracks[key] && result.push(key);
42+
return result;
43+
}, []), val => `tracks[]=${val}`).join('&');
44+
const ftypes = _.map(types, val => `types[]=${val}`).join('&');
45+
const fgroups = _.map(groups, val => `groups[]=${val}`).join('&');
46+
const fevents = _.map(events, val => `events[]=${val}`).join('&');
47+
if (ftags.length > 0) urlFilter += `&${ftags}`;
48+
if (ftracks.length > 0) urlFilter += `&${ftracks}`;
49+
if (ftypes.length > 0) urlFilter += `&${ftypes}`;
50+
if (fgroups.length > 9) urlFilter += `&${fgroups}`;
51+
if (fevents.length > 0) urlFilter += `&${fevents}`;
52+
return urlFilter;
53+
}
54+
1855
export const ORDER_BY = {
1956
SUBMISSION_END_DATE: 'submissionEndDate',
2057
};
@@ -133,27 +170,42 @@ class ChallengesService {
133170
*/
134171
const getChallenges = async (
135172
endpoint,
136-
filters = {},
137-
params = {},
173+
filter,
138174
) => {
139-
const query = {
140-
...filters,
141-
...params,
142-
};
143-
const url = `${endpoint}?${qs.stringify(query)}`;
144-
const res = await this.private.apiV5.get(url).then(checkErrorV5);
175+
let res = {};
176+
if (_.some(filter.frontFilter.tracks, val => val)) {
177+
const query = getFilterUrl(filter.backendFilter, filter.frontFilter);
178+
const url = `${endpoint}?${query}`;
179+
res = await this.private.apiV5.get(url).then(checkErrorV5);
180+
}
145181
return {
146182
challenges: res.result || [],
147-
totalCount: res.headers.get('x-total'),
183+
totalCount: res.headers ? res.headers.get('x-total') : 0,
148184
meta: {
149-
allChallengesCount: res.headers.get('x-total'),
185+
allChallengesCount: res.headers ? res.headers.get('x-total') : 0,
150186
myChallengesCount: 0,
151187
ongoingChallengesCount: 0,
152188
openChallengesCount: 0,
153-
totalCount: res.headers.get('x-total'),
189+
totalCount: res.headers ? res.headers.get('x-total') : 0,
154190
},
155191
};
156192
};
193+
194+
const getChallengeDetails = async (
195+
endpoint,
196+
legacyInfo,
197+
) => {
198+
let query = '';
199+
if (legacyInfo) {
200+
query = `legacyId=${legacyInfo.legacyId}`;
201+
}
202+
const url = `${endpoint}?${query}`;
203+
const res = await this.private.apiV5.get(url).then(checkErrorV5);
204+
return {
205+
challenges: res.result || [],
206+
};
207+
};
208+
157209
/**
158210
* Private function being re-used in all methods related to getting
159211
* challenges. It handles query-related arguments in the uniform way:
@@ -189,6 +241,7 @@ class ChallengesService {
189241
apiV2: getApi('V2', tokenV2),
190242
apiV3: getApi('V3', tokenV3),
191243
getChallenges,
244+
getChallengeDetails,
192245
getMemberChallenges,
193246
tokenV2,
194247
tokenV3,
@@ -327,10 +380,10 @@ class ChallengesService {
327380
// condition based on ROUTE used for Review Opportunities, change if needed
328381
if (/^[\d]{5,8}$/.test(challengeId)) {
329382
isLegacyChallenge = true;
330-
challenge = await this.private.getChallenges('/challenges/', { legacyId: challengeId })
383+
challenge = await this.private.getChallengeDetails('/challenges/', { legacyId: challengeId })
331384
.then(res => res.challenges[0] || {});
332385
} else {
333-
challenge = await this.private.getChallenges(`/challenges/${challengeId}`)
386+
challenge = await this.private.getChallengeDetails(`/challenges/${challengeId}`)
334387
.then(res => res.challenges);
335388
}
336389

@@ -464,8 +517,8 @@ class ChallengesService {
464517
* @param {Object} params Optional.
465518
* @return {Promise} Resolves to the api response.
466519
*/
467-
async getChallenges(filters, params) {
468-
return this.private.getChallenges('/challenges/', filters, params)
520+
async getChallenges(filter) {
521+
return this.private.getChallenges('/challenges/', filter)
469522
.then((res) => {
470523
res.challenges.forEach(item => normalizeChallenge(item));
471524
return res;
@@ -642,7 +695,7 @@ class ChallengesService {
642695
let contentType;
643696
let url;
644697

645-
if (track === COMPETITION_TRACKS.DESIGN) {
698+
if (track === COMPETITION_TRACKS.DES) {
646699
({ api } = this.private);
647700
contentType = 'application/json';
648701
url = '/submissions/'; // The submission info is contained entirely in the JSON body
@@ -660,7 +713,7 @@ class ChallengesService {
660713
}, onProgress).then((res) => {
661714
const jres = JSON.parse(res);
662715
// Return result for Develop submission
663-
if (track === COMPETITION_TRACKS.DEVELOP) {
716+
if (track === COMPETITION_TRACKS.DEV) {
664717
return jres;
665718
}
666719
// Design Submission requires an extra "Processing" POST

src/services/reviewOpportunities.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ export function normalizeChallenges(opportunities) {
1717
* until receive API V5 update. */
1818
_.map(opportunities, (opportunity) => {
1919
const { challenge } = opportunity;
20-
challenge.track = COMPETITION_TRACKS.DEVELOP;
20+
challenge.track = COMPETITION_TRACKS.DEV;
2121
if (challenge.technologies) {
22-
if (challenge.technologies.includes(COMPETITION_TRACKS.DATA_SCIENCE)) {
23-
challenge.track = COMPETITION_TRACKS.DATA_SCIENCE;
22+
if (challenge.technologies.includes(COMPETITION_TRACKS.DS)) {
23+
challenge.track = COMPETITION_TRACKS.DS;
2424
}
2525
} else if (challenge.subTrack === OLD_SUBTRACKS.TEST_SUITES
2626
|| challenge.subTrack === OLD_SUBTRACKS.BUG_HUNT
2727
|| challenge.subTrack === OLD_COMPETITION_TRACKS.TEST_SCENARIOS
2828
|| challenge.subTrack === OLD_COMPETITION_TRACKS.TESTING_COMPETITION) {
2929
challenge.track = COMPETITION_TRACKS.QA;
3030
} else if (challenge.track === OLD_COMPETITION_TRACKS.DESIGN) {
31-
challenge.track = COMPETITION_TRACKS.DESIGN;
31+
challenge.track = COMPETITION_TRACKS.DES;
3232
}
3333
return _.defaults(opportunity, { challenge });
3434
});

src/utils/challenge/filter.js

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function filterByRegistrationOpen(challenge, state) {
9090
if (!registrationPhase || !registrationPhase.isOpen) {
9191
return false;
9292
}
93-
if (challenge.track === COMPETITION_TRACKS.DESIGN) {
93+
if (challenge.track === COMPETITION_TRACKS.DES) {
9494
const checkpointPhase = challengePhases.find(item => item.name === 'Checkpoint Submission')[0];
9595
return !checkpointPhase || !checkpointPhase.isOpen;
9696
}
@@ -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+
Development: 'Dev',
254+
Design: 'Des',
255+
'Quality Assurance': '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

Lines changed: 3 additions & 3 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy