Skip to content

Commit 0d5ada6

Browse files
Merge pull request #5394 from topcoder-platform/tco-leaderboards-fixes
Tco leaderboards fixes
2 parents 42abb08 + 344523f commit 0d5ada6

File tree

5 files changed

+38
-17
lines changed

5 files changed

+38
-17
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ workflows:
275275
filters:
276276
branches:
277277
only:
278-
- gig-referrals
278+
- develop
279279
# This is alternate dev env for parallel testing
280280
- "build-test":
281281
context : org-global

src/shared/actions/leaderboard.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
/* eslint-disable no-param-reassign */
12
/**
23
* Leaderboard actions.
34
*/
45

5-
/* global fetch */ /* eslint no-param-reassign: ["error", { "props": false }] */
6-
76
import _ from 'lodash';
87
import { createActions } from 'redux-actions';
98

@@ -34,21 +33,33 @@ function fetchLeaderboard(auth, apiUrl, id) {
3433
});
3534
}
3635

36+
/**
37+
* Prepare loading looker for TCO history modal
38+
* @param {string} url the url to load data from
39+
*/
3740
function getTcoHistoryChallengesInit(url) {
3841
return _.toString(url);
3942
}
4043

44+
/**
45+
* Loads looker for TCO history modal
46+
* @param {string} url the url to load data from
47+
* @param {object} competitor the competitor data
48+
*/
4149
async function getTcoHistoryChallengesDone(url, competitor) {
4250
const res = await fetch(url)
4351
.then(response => response.json())
4452
.then(jsonResponse => ({
4553
challenges: _.filter(jsonResponse, challenge => (
4654
challenge['member_profile_basic.user_id']
4755
? (challenge['member_profile_basic.user_id'] === competitor['member_profile_basic.user_id'])
48-
: (challenge.userid === competitor.userid)
56+
: (challenge.userid === (competitor['member_profile_basic.user_id'] || competitor.userid))
4957
)),
5058
}));
51-
return res;
59+
return {
60+
url,
61+
challenges: res.challenges,
62+
};
5263
}
5364

5465
export default createActions({

src/shared/components/Leaderboard/ChallengeHistoryModal/index.jsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class ChallengeHistoryModal extends Component {
114114
<tbody>
115115
{
116116
challengesOrdered.map(challenge => (
117-
<tr styleName="row" key={`${challenge['tco_leaderboard.challenge_id'] || challenge.challenge_id}`}>
117+
<tr styleName="row" key={`${challenge['tco_leaderboard.challenge_id'] || challenge['challenge.challenge_id'] || challenge.challenge_id}`}>
118118
<td styleName="name">
119119
<a href={`${config.URL.BASE}/challenges/${challenge['tco_leaderboard.challenge_id'] || challenge['challenge.challenge_id'] || challenge.challenge_id}/`} styleName="link" target="_blank" rel="noopener noreferrer">
120120
{challenge.challenge_name || challenge['challenge.challenge_name'] || challenge['tco_leaderboard.challenge_id'] || challenge.challenge_id}
@@ -136,6 +136,11 @@ class ChallengeHistoryModal extends Component {
136136
{
137137
loading ? <LoadingIndicator /> : null
138138
}
139+
{
140+
!challengesOrdered.length && !loading && (
141+
<center><strong>No data available.</strong></center>
142+
)
143+
}
139144
<div styleName="buttons">
140145
<button onClick={onCancel} type="button" styleName="close-btn">
141146
Return to page
@@ -163,10 +168,11 @@ const CompetitorShape = PT.shape({
163168
ChallengeHistoryModal.defaultProps = {
164169
isCopilot: false,
165170
isAlgo: false,
171+
challenges: [],
166172
};
167173

168174
ChallengeHistoryModal.propTypes = {
169-
challenges: CHALLENGES_TYPE.isRequired,
175+
challenges: CHALLENGES_TYPE,
170176
competitor: CompetitorShape.isRequired,
171177
onCancel: PT.func.isRequired,
172178
loading: PT.bool.isRequired,

src/shared/containers/tco/Leaderboard/ChallengeHistoryModal/index.jsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function ChallengeHistoryModalContainer({
1414
isCopilot,
1515
isAlgo,
1616
}) {
17-
if (!challenges.length) {
17+
if (!challenges && !loading) {
1818
getChallengesHistory(dataUrl, competitor);
1919
}
2020

@@ -32,8 +32,8 @@ function ChallengeHistoryModalContainer({
3232

3333
ChallengeHistoryModalContainer.defaultProps = {
3434
dataUrl: 'http://www.mocky.io/v2/5bbec82f3400006e006fcba6?mocky-delay=5000ms',
35-
challenges: [],
36-
loading: true,
35+
challenges: null,
36+
loading: false,
3737
isCopilot: false,
3838
isAlgo: false,
3939
};
@@ -64,7 +64,7 @@ ChallengeHistoryModalContainer.propTypes = {
6464
};
6565

6666
function mapStateToProps(state, ownProps) {
67-
const { challenges, loading } = state.leaderboard;
67+
const { challenges, loading } = state.leaderboard[ownProps.dataUrl] || {};
6868
return {
6969
challenges: ownProps.challenges || challenges,
7070
loading,
@@ -74,7 +74,7 @@ function mapStateToProps(state, ownProps) {
7474
function mapDispatchToProps(dispatch) {
7575
return {
7676
getChallengesHistory: (url, competitor) => {
77-
dispatch(actions.leaderboard.getTcoHistoryChallengesInit());
77+
dispatch(actions.leaderboard.getTcoHistoryChallengesInit(url));
7878
dispatch(actions.leaderboard.getTcoHistoryChallengesDone(url, competitor));
7979
},
8080
};

src/shared/reducers/leaderboard.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ function onDone(state, action) {
3232
function onHistoryChallengesDone(state, action) {
3333
return {
3434
...state,
35-
challenges: action.error ? [] : action.payload.challenges,
36-
failed: !!action.error,
37-
loading: false,
35+
[action.payload.url]: {
36+
challenges: action.error ? [] : action.payload.challenges,
37+
failed: !!action.error,
38+
loading: false,
39+
},
3840
};
3941
}
4042

@@ -57,10 +59,12 @@ function create(initialState) {
5759
};
5860
},
5961
[actions.leaderboard.fetchLeaderboardDone]: onDone,
60-
[actions.leaderboard.getTcoHistoryChallengesInit](state) {
62+
[actions.leaderboard.getTcoHistoryChallengesInit](state, action) {
6163
return {
6264
...state,
63-
loading: true,
65+
[action.payload]: {
66+
loading: true,
67+
},
6468
};
6569
},
6670
[actions.leaderboard.getTcoHistoryChallengesDone]: onHistoryChallengesDone,

0 commit comments

Comments
 (0)