Skip to content

Issue-4706 : Track and Subtrack enhancements #216

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
merged 3 commits into from
Aug 6, 2020
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
9 changes: 5 additions & 4 deletions __tests__/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ Object {
"setEndDate": [Function],
"setReviewOpportunityType": [Function],
"setStartDate": [Function],
"setSubtracks": [Function],
"setTags": [Function],
"setText": [Function],
"setTypes": [Function],
},
},
"errors": Object {
Expand Down Expand Up @@ -372,9 +372,10 @@ Object {
},
"tc": Object {
"COMPETITION_TRACKS": Object {
"DATA_SCIENCE": "data_science",
"DESIGN": "design",
"DEVELOP": "develop",
"DATA_SCIENCE": "Data Science",
"DESIGN": "Design",
"DEVELOP": "Development",
"QA": "Quality Assurance",
},
"REVIEW_OPPORTUNITY_TYPES": Object {
"Contest Review": "Review",
Expand Down
12 changes: 6 additions & 6 deletions __tests__/utils/challenge/filter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
setText, setTags, setSubtracks, setStartDate,
setText, setTags, setTypes, setStartDate,
} from '../../../src/utils/challenge/filter';

describe('challenge filter', () => {
Expand All @@ -22,12 +22,12 @@ describe('challenge filter', () => {
expect(res).toEqual({});
});

test('setSubtracks', () => {
res = setSubtracks({});
test('setTypes', () => {
res = setTypes({});
expect(res).toEqual({});
res = setSubtracks({}, 'subtracks');
expect(res).toEqual({ subtracks: 'subtracks' });
res = setSubtracks({ subtracks: 'subtracks' });
res = setTypes({}, 'types');
expect(res).toEqual({ types: 'types' });
res = setTypes({ types: 'types' });
expect(res).toEqual({});
});

Expand Down
10 changes: 5 additions & 5 deletions docs/challenge.filter.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ users are participating.
* [.setEndDate(state, date)](#module_challenge.filter.setEndDate) ⇒ <code>Object</code>
* [.setReviewOpportunityType(state, reviewOpportunityType)](#module_challenge.filter.setReviewOpportunityType) ⇒ <code>Object</code>
* [.setStartDate(state, date)](#module_challenge.filter.setStartDate) ⇒ <code>Object</code>
* [.setSubtracks(state, subtracks)](#module_challenge.filter.setSubtracks) ⇒ <code>Object</code>
* [.setTypes(state, types)](#module_challenge.filter.setTypes) ⇒ <code>Object</code>
* [.setTags(state, tags)](#module_challenge.filter.setTags) ⇒ <code>Object</code>
* [.setText(state, text)](#module_challenge.filter.setText) ⇒ <code>Object</code>
* _inner_
Expand Down Expand Up @@ -198,17 +198,17 @@ Clones the state and sets the start date.
| state | <code>Object</code> | |
| date | <code>String</code> | ISO date string. |

<a name="module_challenge.filter.setSubtracks"></a>
<a name="module_challenge.filter.setTypes"></a>

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

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

| Param | Type |
| --- | --- |
| state | <code>Object</code> |
| subtracks | <code>Array</code> |
| types | <code>Array</code> |

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

Expand Down
39 changes: 15 additions & 24 deletions src/utils/challenge/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,20 +159,12 @@ function filterByText(challenge, state) {

function filterByTrack(challenge, state) {
if (!state.tracks) return true;

/* Development challenges having Data Science tech tag, still should be
* included into data science track. */
if (state.tracks[COMPETITION_TRACKS.DATA_SCIENCE]
&& _.includes(challenge.tags, 'Data Science')) {
return true;
}

return _.keys(state.tracks).some(track => challenge.communities.has(track));
return _.keys(state.tracks).some(track => challenge.track === track);
}

function filterBySubtracks(challenge, state) {
if (!state.subtracks) return true;
return state.subtracks.includes(challenge.typeId);
function filterByTypes(challenge, state) {
if (!state.types) return true;
return state.types.includes(challenge.typeId);
}

function filterByUpcoming(challenge, state) {
Expand Down Expand Up @@ -222,7 +214,7 @@ export function getFilterFunction(state) {
&& filterByGroupIds(challenge, state)
&& filterByText(challenge, state)
&& filterByTags(challenge, state)
&& filterBySubtracks(challenge, state)
&& filterByTypes(challenge, state)
&& filterByUsers(challenge, state)
&& filterByEndDate(challenge, state)
&& filterByStartDate(challenge, state)
Expand All @@ -245,9 +237,9 @@ export function getFilterFunction(state) {
* @param {Object} state
* @return {Function}
*/
export function getReviewOpportunitiesFilterFunction(state, validSubtracks) {
export function getReviewOpportunitiesFilterFunction(state, validTypes) {
return (opp) => {
const newSubTrack = _.find(validSubtracks, { abbreviation: opp.challenge.subTrack }) || {};
const newType = _.find(validTypes, { name: opp.challenge.type }) || {};

// Review Opportunity objects have a challenge field which
// is largely compatible with many of the existing filter functions
Expand All @@ -257,12 +249,11 @@ export function getReviewOpportunitiesFilterFunction(state, validSubtracks) {
// This allows filterByText to search for Review Types and Challenge Titles
name: `${opp.challenge.title} ${REVIEW_OPPORTUNITY_TYPES[opp.type]}`,
registrationStartDate: opp.startDate, // startDate of Review, not Challenge
subTrack: opp.challenge.subTrack || '', // Sometimes back-end doesn't return this field
submissionEndDate: opp.startDate, // Currently uses startDate for both date comparisons
communities: new Set([ // Used to filter by Track, and communities at a future date
opp.challenge.track.toLowerCase(),
]),
typeId: newSubTrack.id,
typeId: newType.id,
tags: opp.challenge.technologies || [],
platforms: opp.challenge.platforms || [],
};
Expand All @@ -271,7 +262,7 @@ export function getReviewOpportunitiesFilterFunction(state, validSubtracks) {
filterByTrack(challenge, state)
&& filterByText(challenge, state)
&& filterByTags(challenge, state)
&& filterBySubtracks(challenge, state)
&& filterByTypes(challenge, state)
&& filterByEndDate(challenge, state)
&& filterByStartDate(challenge, state)
&& filterByReviewOpportunityType(opp, state)
Expand Down Expand Up @@ -455,16 +446,16 @@ export function setStartDate(state, date) {
}

/**
* Clones the state and sets the subtracks.
* Clones the state and sets the challenge types.
* @param {Object} state
* @param {Array} subtracks
* @param {Array} types
* @return {Object}
*/
export function setSubtracks(state, subtracks) {
if (subtracks && subtracks.length) return { ...state, subtracks };
if (!state.subtracks) return state;
export function setTypes(state, types) {
if (types && types.length) return { ...state, types };
if (!state.types) return state;
const res = _.clone(state);
delete res.subtracks;
delete res.types;
return res;
}

Expand Down
7 changes: 4 additions & 3 deletions src/utils/tc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
* uses upper-case literals to encode the tracks. At some point, we should
* update it in this code as well! */
export const COMPETITION_TRACKS = {
DATA_SCIENCE: 'data_science',
DESIGN: 'design',
DEVELOP: 'develop',
DATA_SCIENCE: 'Data Science',
DESIGN: 'Design',
DEVELOP: 'Development',
QA: 'Quality Assurance',
};

/**
Expand Down