Skip to content

fix issue #200 #247

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 2 commits into from
Aug 30, 2017
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
4 changes: 2 additions & 2 deletions __tests__/shared/actions/challenge-listing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('challengeListing.getPastChallengesInit', () => {
});

describe('challengeListing.getChallengeSubtracksDone', () => {
global.fetch = mockFetch(true, [{ description: 'dummy' }]);
global.fetch = mockFetch(true, { result: { status: 200, content: [{ description: 'dummy' }] } });

const a = actions.getChallengeSubtracksDone();

Expand All @@ -91,7 +91,7 @@ describe('challengeListing.getChallengeSubtracksDone', () => {
});

test('payload is a promise which resolves to the expected object', () =>
a.payload.then(res => expect(res).toEqual(['dummy', 'dummy'])));
a.payload.then(res => expect(res).toEqual([{ description: 'dummy' }])));
});

describe('challengeListing.getChallengeTagsDone', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const mockDatas = [{
setFilterState,
setSearchText,
validKeywords: ['key', 'word'],
validSubtracks: ['sub', 'track'],
validSubtracks: [{ name: 'sub', subTrack: 'sub' }, { name: 'track', subTrack: 'track' }],
onClose,
}, {
communityFilters: [
Expand Down
1 change: 1 addition & 0 deletions __tests__/shared/reducers/challenge-listing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ let expectedState = {

challenges: [],
challengeSubtracks: [],
challengeSubtracksMap: {},
challengeTags: [],

filter: {},
Expand Down
3 changes: 1 addition & 2 deletions src/shared/actions/challenge-listing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ function getChallengeSubtracksDone() {
return getService()
.getChallengeSubtracks()
.then(res =>
res.map(item => item.description)
.sort((a, b) => a.localeCompare(b)),
res.sort((a, b) => a.name.localeCompare(b.name)),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import React from 'react';
import PT from 'prop-types';
import _ from 'lodash';
import { Link } from 'utils/router';

import './style.scss';
Expand All @@ -20,8 +21,17 @@ export default function ChallengeTags(props) {
subTrackStyle,
eventStyle,
setChallengeListingFilter,
challengeSubtracksMap,
} = props;

const stylizedSubTrack = (t) => {
if (challengeSubtracksMap[t]) {
return challengeSubtracksMap[t].name;
}
return (t || '').replace(/_/g, ' ')
.replace(/\w\S*/g, txt => _.capitalize(txt));
};

return (
<div styleName="tag-holder">
{
Expand All @@ -30,7 +40,7 @@ export default function ChallengeTags(props) {
onClick={() => setChallengeListingFilter({ subtracks: [subTrack] })}
to="/challenges"
styleName={`tag-common ${subTrackStyle}`}
>{subTrack}</Link>
>{stylizedSubTrack(subTrack)}</Link>
}
{
events.map(event => (
Expand Down Expand Up @@ -71,4 +81,5 @@ ChallengeTags.propTypes = {
subTrackStyle: PT.string.isRequired,
eventStyle: PT.string.isRequired,
setChallengeListingFilter: PT.func.isRequired,
challengeSubtracksMap: PT.shape().isRequired,
};
7 changes: 4 additions & 3 deletions src/shared/components/challenge-detail/Header/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default function ChallengeHeader(props) {
setChallengeListingFilter,
unregisterFromChallenge,
unregistering,
challengeSubtracksMap,
} = props;

const {
Expand Down Expand Up @@ -66,8 +67,6 @@ export default function ChallengeHeader(props) {

const theme = themeFactory(trackLower);

const stylizedSubTrack = (subTrack || '').replace('_', ' ')
.replace(/\w\S*/g, txt => _.capitalize(txt));
const subTrackStyle = `${trackLower}-accent-background`;
const eventStyle = `${trackLower}-accent-color`;
const eventNames = (events || []).map((event => (event.eventName || '').toUpperCase()));
Expand Down Expand Up @@ -138,7 +137,8 @@ export default function ChallengeHeader(props) {
<div styleName="important-detail">
<h1 styleName="challenge-header">{name}</h1>
<ChallengeTags
subTrack={stylizedSubTrack}
subTrack={subTrack}
challengeSubtracksMap={challengeSubtracksMap}
events={eventNames}
technPlatforms={miscTags}
subTrackStyle={subTrackStyle}
Expand Down Expand Up @@ -259,4 +259,5 @@ ChallengeHeader.propTypes = {
showDeadlineDetail: PT.bool.isRequired,
unregisterFromChallenge: PT.func.isRequired,
unregistering: PT.bool.isRequired,
challengeSubtracksMap: PT.shape().isRequired,
};
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default function FiltersPanel({
}));

const mapOps = item => ({ label: item, value: item });

const mapSubtracks = item => ({ label: item.name, value: item.subTrack });
return (
<div styleName={className}>
<div styleName="header">
Expand Down Expand Up @@ -98,7 +98,7 @@ export default function FiltersPanel({
const subtracks = value ? value.split(',') : undefined;
setFilterState(Filter.setSubtracks(filterState, subtracks));
}}
options={validSubtracks.map(mapOps)}
options={validSubtracks.map(mapSubtracks)}
simpleValue
value={
filterState.subtracks ? filterState.subtracks.join(',') : null
Expand Down Expand Up @@ -162,6 +162,6 @@ FiltersPanel.propTypes = {
setFilterState: PT.func.isRequired,
setSearchText: PT.func.isRequired,
validKeywords: PT.arrayOf(PT.string).isRequired,
validSubtracks: PT.arrayOf(PT.string).isRequired,
validSubtracks: PT.arrayOf(PT.shape()).isRequired,
onClose: PT.func,
};
16 changes: 15 additions & 1 deletion src/shared/containers/challenge-detail/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ class ChallengeDetailPageContainer extends React.Component {

componentDidMount() {
const { challenge, loadChallengeDetails, loadTerms,
openTermsModal, authTokens, challengeId } = this.props;
openTermsModal, authTokens, challengeId,
challengeSubtracksMap, getSubtracks } = this.props;

if (challenge.id !== challengeId) {
loadChallengeDetails(authTokens, challengeId);
Expand All @@ -65,6 +66,10 @@ class ChallengeDetailPageContainer extends React.Component {
if (authTokens.tokenV2 && location.search.indexOf('showTerms=true') > 0) {
openTermsModal();
}

if (_.isEmpty(challengeSubtracksMap)) {
getSubtracks();
}
}

componentWillReceiveProps(nextProps) {
Expand Down Expand Up @@ -147,6 +152,7 @@ class ChallengeDetailPageContainer extends React.Component {
unregistering={this.props.unregistering}
checkpoints={this.props.checkpoints}
hasRegistered={hasRegistered}
challengeSubtracksMap={this.props.challengeSubtracksMap}
/>
}
{
Expand Down Expand Up @@ -282,6 +288,8 @@ ChallengeDetailPageContainer.propTypes = {
agreedTerms: PT.shape(),
loadingDocuSignUrl: PT.string,
setChallengeListingFilter: PT.func.isRequired,
challengeSubtracksMap: PT.shape().isRequired,
getSubtracks: PT.func.isRequired,
};

function extractChallengeDetail(v3, v2, challengeId) {
Expand Down Expand Up @@ -388,6 +396,7 @@ const mapStateToProps = (state, props) => ({
agreeingTerm: state.terms.agreeingTerm,
agreedTerms: state.terms.agreedTerms,
isLoadingTerms: state.terms.loadingTermsForChallengeId === props.match.params.challengeId,
challengeSubtracksMap: state.challengeListing.challengeSubtracksMap,
});

const mapDispatchToProps = (dispatch) => {
Expand Down Expand Up @@ -456,6 +465,11 @@ const mapDispatchToProps = (dispatch) => {
dispatch(t.agreeTermInit(termId));
dispatch(t.agreeTermDone(termId, tokens.tokenV2));
},
getSubtracks: () => {
const cl = challengeListingActions.challengeListing;
dispatch(cl.getChallengeSubtracksInit());
dispatch(cl.getChallengeSubtracksDone());
},
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ ListingContainer.propTypes = {
allDraftChallengesLoaded: PT.bool.isRequired,
allPastChallengesLoaded: PT.bool.isRequired,
challenges: PT.arrayOf(PT.shape({})).isRequired,
challengeSubtracks: PT.arrayOf(PT.string).isRequired,
challengeSubtracks: PT.arrayOf(PT.shape()).isRequired,
challengeTags: PT.arrayOf(PT.string).isRequired,
communityFilters: PT.arrayOf(PT.shape({
challengeFilter: PT.shape(),
Expand Down
2 changes: 2 additions & 0 deletions src/shared/reducers/challenge-listing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function onGetChallengeSubtracksDone(state, action) {
return {
...state,
challengeSubtracks: action.error ? [] : action.payload,
challengeSubtracksMap: action.error ? {} : _.keyBy(action.payload, 'subTrack'),
loadingChallengeSubtracks: false,
};
}
Expand Down Expand Up @@ -237,6 +238,7 @@ function create(initialState) {

challenges: [],
challengeSubtracks: [],
challengeSubtracksMap: {},
challengeTags: [],

filter: {},
Expand Down
13 changes: 7 additions & 6 deletions src/shared/services/challenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,13 @@ class ChallengesService {
* @return {Promise} Resolves to the array of subtrack names.
*/
getChallengeSubtracks() {
return Promise.all([
this.private.apiV2.get('/design/challengetypes')
.then(res => (res.ok ? res.json() : new Error(res.statusText))),
this.private.apiV2.get('/develop/challengetypes')
.then(res => (res.ok ? res.json() : new Error(res.statusText))),
]).then(([a, b]) => a.concat(b));
return this.private.api.get('/challenge-types')
.then(res => (res.ok ? res.json() : new Error(res.statusText)))
.then(res => (
res.result.status === 200 ?
res.result.content :
new Error(res.result.content)
));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/shared/utils/challenge-listing/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ function filterBySubtracks(challenge, state) {
* why challenge subtracks in challenge objects are different from those
* return from the API as the list of possible subtracks. */
const filterSubtracks = state.subtracks.map(item =>
item.toLowerCase().replace(/ /g, ''));
const challengeSubtrack = challenge.subTrack.toLowerCase().replace(/_/g, '');
item.toLowerCase().replace(/[_ ]/g, ''));
const challengeSubtrack = challenge.subTrack.toLowerCase().replace(/[_ ]/g, '');
return filterSubtracks.includes(challengeSubtrack);
}

Expand Down