Skip to content

Tco leaderboards fixes #5394

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
Feb 25, 2021
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ workflows:
filters:
branches:
only:
- gig-referrals
- develop
# This is alternate dev env for parallel testing
- "build-test":
context : org-global
Expand Down
19 changes: 15 additions & 4 deletions src/shared/actions/leaderboard.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/* eslint-disable no-param-reassign */
/**
* Leaderboard actions.
*/

/* global fetch */ /* eslint no-param-reassign: ["error", { "props": false }] */

import _ from 'lodash';
import { createActions } from 'redux-actions';

Expand Down Expand Up @@ -34,21 +33,33 @@ function fetchLeaderboard(auth, apiUrl, id) {
});
}

/**
* Prepare loading looker for TCO history modal
* @param {string} url the url to load data from
*/
function getTcoHistoryChallengesInit(url) {
return _.toString(url);
}

/**
* Loads looker for TCO history modal
* @param {string} url the url to load data from
* @param {object} competitor the competitor data
*/
async function getTcoHistoryChallengesDone(url, competitor) {
const res = await fetch(url)
.then(response => response.json())
.then(jsonResponse => ({
challenges: _.filter(jsonResponse, challenge => (
challenge['member_profile_basic.user_id']
? (challenge['member_profile_basic.user_id'] === competitor['member_profile_basic.user_id'])
: (challenge.userid === competitor.userid)
: (challenge.userid === (competitor['member_profile_basic.user_id'] || competitor.userid))
)),
}));
return res;
return {
url,
challenges: res.challenges,
};
}

export default createActions({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class ChallengeHistoryModal extends Component {
<tbody>
{
challengesOrdered.map(challenge => (
<tr styleName="row" key={`${challenge['tco_leaderboard.challenge_id'] || challenge.challenge_id}`}>
<tr styleName="row" key={`${challenge['tco_leaderboard.challenge_id'] || challenge['challenge.challenge_id'] || challenge.challenge_id}`}>
<td styleName="name">
<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">
{challenge.challenge_name || challenge['challenge.challenge_name'] || challenge['tco_leaderboard.challenge_id'] || challenge.challenge_id}
Expand All @@ -136,6 +136,11 @@ class ChallengeHistoryModal extends Component {
{
loading ? <LoadingIndicator /> : null
}
{
!challengesOrdered.length && !loading && (
<center><strong>No data available.</strong></center>
)
}
<div styleName="buttons">
<button onClick={onCancel} type="button" styleName="close-btn">
Return to page
Expand Down Expand Up @@ -163,10 +168,11 @@ const CompetitorShape = PT.shape({
ChallengeHistoryModal.defaultProps = {
isCopilot: false,
isAlgo: false,
challenges: [],
};

ChallengeHistoryModal.propTypes = {
challenges: CHALLENGES_TYPE.isRequired,
challenges: CHALLENGES_TYPE,
competitor: CompetitorShape.isRequired,
onCancel: PT.func.isRequired,
loading: PT.bool.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function ChallengeHistoryModalContainer({
isCopilot,
isAlgo,
}) {
if (!challenges.length) {
if (!challenges && !loading) {
getChallengesHistory(dataUrl, competitor);
}

Expand All @@ -32,8 +32,8 @@ function ChallengeHistoryModalContainer({

ChallengeHistoryModalContainer.defaultProps = {
dataUrl: 'http://www.mocky.io/v2/5bbec82f3400006e006fcba6?mocky-delay=5000ms',
challenges: [],
loading: true,
challenges: null,
loading: false,
isCopilot: false,
isAlgo: false,
};
Expand Down Expand Up @@ -64,7 +64,7 @@ ChallengeHistoryModalContainer.propTypes = {
};

function mapStateToProps(state, ownProps) {
const { challenges, loading } = state.leaderboard;
const { challenges, loading } = state.leaderboard[ownProps.dataUrl] || {};
return {
challenges: ownProps.challenges || challenges,
loading,
Expand All @@ -74,7 +74,7 @@ function mapStateToProps(state, ownProps) {
function mapDispatchToProps(dispatch) {
return {
getChallengesHistory: (url, competitor) => {
dispatch(actions.leaderboard.getTcoHistoryChallengesInit());
dispatch(actions.leaderboard.getTcoHistoryChallengesInit(url));
dispatch(actions.leaderboard.getTcoHistoryChallengesDone(url, competitor));
},
};
Expand Down
14 changes: 9 additions & 5 deletions src/shared/reducers/leaderboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ function onDone(state, action) {
function onHistoryChallengesDone(state, action) {
return {
...state,
challenges: action.error ? [] : action.payload.challenges,
failed: !!action.error,
loading: false,
[action.payload.url]: {
challenges: action.error ? [] : action.payload.challenges,
failed: !!action.error,
loading: false,
},
};
}

Expand All @@ -57,10 +59,12 @@ function create(initialState) {
};
},
[actions.leaderboard.fetchLeaderboardDone]: onDone,
[actions.leaderboard.getTcoHistoryChallengesInit](state) {
[actions.leaderboard.getTcoHistoryChallengesInit](state, action) {
return {
...state,
loading: true,
[action.payload]: {
loading: true,
},
};
},
[actions.leaderboard.getTcoHistoryChallengesDone]: onHistoryChallengesDone,
Expand Down