Skip to content

Commit b61fb0f

Browse files
authored
Merge pull request #216 from topcoder-platform/issue-4706
Issue-4706 : Track and Subtrack enhancements
2 parents 2e8a309 + d16b2ba commit b61fb0f

File tree

5 files changed

+35
-42
lines changed

5 files changed

+35
-42
lines changed

__tests__/__snapshots__/index.js.snap

+5-4
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,9 @@ Object {
225225
"setEndDate": [Function],
226226
"setReviewOpportunityType": [Function],
227227
"setStartDate": [Function],
228-
"setSubtracks": [Function],
229228
"setTags": [Function],
230229
"setText": [Function],
230+
"setTypes": [Function],
231231
},
232232
},
233233
"errors": Object {
@@ -372,9 +372,10 @@ Object {
372372
},
373373
"tc": Object {
374374
"COMPETITION_TRACKS": Object {
375-
"DATA_SCIENCE": "data_science",
376-
"DESIGN": "design",
377-
"DEVELOP": "develop",
375+
"DATA_SCIENCE": "Data Science",
376+
"DESIGN": "Design",
377+
"DEVELOP": "Development",
378+
"QA": "Quality Assurance",
378379
},
379380
"REVIEW_OPPORTUNITY_TYPES": Object {
380381
"Contest Review": "Review",

__tests__/utils/challenge/filter.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
setText, setTags, setSubtracks, setStartDate,
2+
setText, setTags, setTypes, setStartDate,
33
} from '../../../src/utils/challenge/filter';
44

55
describe('challenge filter', () => {
@@ -22,12 +22,12 @@ describe('challenge filter', () => {
2222
expect(res).toEqual({});
2323
});
2424

25-
test('setSubtracks', () => {
26-
res = setSubtracks({});
25+
test('setTypes', () => {
26+
res = setTypes({});
2727
expect(res).toEqual({});
28-
res = setSubtracks({}, 'subtracks');
29-
expect(res).toEqual({ subtracks: 'subtracks' });
30-
res = setSubtracks({ subtracks: 'subtracks' });
28+
res = setTypes({}, 'types');
29+
expect(res).toEqual({ types: 'types' });
30+
res = setTypes({ types: 'types' });
3131
expect(res).toEqual({});
3232
});
3333

docs/challenge.filter.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ users are participating.
7070
* [.setEndDate(state, date)](#module_challenge.filter.setEndDate) ⇒ <code>Object</code>
7171
* [.setReviewOpportunityType(state, reviewOpportunityType)](#module_challenge.filter.setReviewOpportunityType) ⇒ <code>Object</code>
7272
* [.setStartDate(state, date)](#module_challenge.filter.setStartDate) ⇒ <code>Object</code>
73-
* [.setSubtracks(state, subtracks)](#module_challenge.filter.setSubtracks) ⇒ <code>Object</code>
73+
* [.setTypes(state, types)](#module_challenge.filter.setTypes) ⇒ <code>Object</code>
7474
* [.setTags(state, tags)](#module_challenge.filter.setTags) ⇒ <code>Object</code>
7575
* [.setText(state, text)](#module_challenge.filter.setText) ⇒ <code>Object</code>
7676
* _inner_
@@ -198,17 +198,17 @@ Clones the state and sets the start date.
198198
| state | <code>Object</code> | |
199199
| date | <code>String</code> | ISO date string. |
200200

201-
<a name="module_challenge.filter.setSubtracks"></a>
201+
<a name="module_challenge.filter.setTypes"></a>
202202

203-
### challenge.filter.setSubtracks(state, subtracks) ⇒ <code>Object</code>
204-
Clones the state and sets the subtracks.
203+
### challenge.filter.setTypes(state, types) ⇒ <code>Object</code>
204+
Clones the state and sets the challenge types.
205205

206206
**Kind**: static method of [<code>challenge.filter</code>](#module_challenge.filter)
207207

208208
| Param | Type |
209209
| --- | --- |
210210
| state | <code>Object</code> |
211-
| subtracks | <code>Array</code> |
211+
| types | <code>Array</code> |
212212

213213
<a name="module_challenge.filter.setTags"></a>
214214

src/utils/challenge/filter.js

+15-24
Original file line numberDiff line numberDiff line change
@@ -159,20 +159,12 @@ function filterByText(challenge, state) {
159159

160160
function filterByTrack(challenge, state) {
161161
if (!state.tracks) return true;
162-
163-
/* Development challenges having Data Science tech tag, still should be
164-
* included into data science track. */
165-
if (state.tracks[COMPETITION_TRACKS.DATA_SCIENCE]
166-
&& _.includes(challenge.tags, 'Data Science')) {
167-
return true;
168-
}
169-
170-
return _.keys(state.tracks).some(track => challenge.communities.has(track));
162+
return _.keys(state.tracks).some(track => challenge.track === track);
171163
}
172164

173-
function filterBySubtracks(challenge, state) {
174-
if (!state.subtracks) return true;
175-
return state.subtracks.includes(challenge.typeId);
165+
function filterByTypes(challenge, state) {
166+
if (!state.types) return true;
167+
return state.types.includes(challenge.typeId);
176168
}
177169

178170
function filterByUpcoming(challenge, state) {
@@ -222,7 +214,7 @@ export function getFilterFunction(state) {
222214
&& filterByGroupIds(challenge, state)
223215
&& filterByText(challenge, state)
224216
&& filterByTags(challenge, state)
225-
&& filterBySubtracks(challenge, state)
217+
&& filterByTypes(challenge, state)
226218
&& filterByUsers(challenge, state)
227219
&& filterByEndDate(challenge, state)
228220
&& filterByStartDate(challenge, state)
@@ -245,9 +237,9 @@ export function getFilterFunction(state) {
245237
* @param {Object} state
246238
* @return {Function}
247239
*/
248-
export function getReviewOpportunitiesFilterFunction(state, validSubtracks) {
240+
export function getReviewOpportunitiesFilterFunction(state, validTypes) {
249241
return (opp) => {
250-
const newSubTrack = _.find(validSubtracks, { abbreviation: opp.challenge.subTrack }) || {};
242+
const newType = _.find(validTypes, { name: opp.challenge.type }) || {};
251243

252244
// Review Opportunity objects have a challenge field which
253245
// is largely compatible with many of the existing filter functions
@@ -257,12 +249,11 @@ export function getReviewOpportunitiesFilterFunction(state, validSubtracks) {
257249
// This allows filterByText to search for Review Types and Challenge Titles
258250
name: `${opp.challenge.title} ${REVIEW_OPPORTUNITY_TYPES[opp.type]}`,
259251
registrationStartDate: opp.startDate, // startDate of Review, not Challenge
260-
subTrack: opp.challenge.subTrack || '', // Sometimes back-end doesn't return this field
261252
submissionEndDate: opp.startDate, // Currently uses startDate for both date comparisons
262253
communities: new Set([ // Used to filter by Track, and communities at a future date
263254
opp.challenge.track.toLowerCase(),
264255
]),
265-
typeId: newSubTrack.id,
256+
typeId: newType.id,
266257
tags: opp.challenge.technologies || [],
267258
platforms: opp.challenge.platforms || [],
268259
};
@@ -271,7 +262,7 @@ export function getReviewOpportunitiesFilterFunction(state, validSubtracks) {
271262
filterByTrack(challenge, state)
272263
&& filterByText(challenge, state)
273264
&& filterByTags(challenge, state)
274-
&& filterBySubtracks(challenge, state)
265+
&& filterByTypes(challenge, state)
275266
&& filterByEndDate(challenge, state)
276267
&& filterByStartDate(challenge, state)
277268
&& filterByReviewOpportunityType(opp, state)
@@ -455,16 +446,16 @@ export function setStartDate(state, date) {
455446
}
456447

457448
/**
458-
* Clones the state and sets the subtracks.
449+
* Clones the state and sets the challenge types.
459450
* @param {Object} state
460-
* @param {Array} subtracks
451+
* @param {Array} types
461452
* @return {Object}
462453
*/
463-
export function setSubtracks(state, subtracks) {
464-
if (subtracks && subtracks.length) return { ...state, subtracks };
465-
if (!state.subtracks) return state;
454+
export function setTypes(state, types) {
455+
if (types && types.length) return { ...state, types };
456+
if (!state.types) return state;
466457
const res = _.clone(state);
467-
delete res.subtracks;
458+
delete res.types;
468459
return res;
469460
}
470461

src/utils/tc.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
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: 'develop',
14+
DATA_SCIENCE: 'Data Science',
15+
DESIGN: 'Design',
16+
DEVELOP: 'Development',
17+
QA: 'Quality Assurance',
1718
};
1819

1920
/**

0 commit comments

Comments
 (0)