Skip to content

Release v1.2.4 : MM Dashboard #326

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 18 commits into from
Dec 13, 2021
Merged
Changes from 1 commit
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
Next Next commit
Add support for fetching challenge statistics
  • Loading branch information
ThomasKranitsas committed Dec 10, 2021
commit 53bd448412ff5beec2070655080f96fc8db84d5a
21 changes: 21 additions & 0 deletions src/actions/challenge.js
Original file line number Diff line number Diff line change
@@ -392,6 +392,25 @@ function getSubmissionInformationDone(challengeId, submissionId, tokenV3) {
});
}

/**
* @static
* @desc Creates an action that signals beginning of fetching challenge statistics
* @return {Action}
*/
function fetchChallengeStatisticsInit() {}

/**
* @static
* @desc Creates an action that gets challenge statistics from the backend.
* @param {String} challengeId The challenge id
* @param {String} tokenV3 Topcoder auth token v3.
* @return {Action}
*/
function fetchChallengeStatisticsDone(challengeId, tokenV3) {
const challengeService = getChallengesService(tokenV3);
return challengeService.getChallengeStatistics(challengeId)
}

export default createActions({
CHALLENGE: {
DROP_CHECKPOINTS: dropCheckpoints,
@@ -417,5 +436,7 @@ export default createActions({
GET_MM_SUBMISSIONS_DONE: getMMSubmissionsDone,
GET_SUBMISSION_INFORMATION_INIT: getSubmissionInformationInit,
GET_SUBMISSION_INFORMATION_DONE: getSubmissionInformationDone,
GET_CHALLENGE_STATISTICS_INIT: fetchChallengeStatisticsInit,
GET_CHALLENGE_STATISTICS_DONE: fetchChallengeStatisticsDone,
},
});
36 changes: 36 additions & 0 deletions src/reducers/challenge.js
Original file line number Diff line number Diff line change
@@ -368,6 +368,39 @@ function onGetSubmissionInformationDone(state, action) {
};
}

/**
* Handles CHALLENGE/GET_CHALLENGE_STATISTICS_INIT action.
* @param {Object} state
* @param {Object} action
* @return {Object} New state.
*/
function onFetchChallengeStatisticsInit(state, action) {
return {
...state,
statisticsData: [],
};
}

/**
* Handles CHALLENGE/GET_CHALLENGE_STATISTICS_DONE action.
* @param {Object} state Previous state.
* @param {Object} action Action.
*/
function onFetchChallengeStatisticsDone(state, action) {
if (action.error) {
logger.error('Failed to get challenge statistics', action.payload);
return {
...state,
statisticsData: [],
};
}

return {
...state,
statisticsData: action.payload,
};
}

/**
* Creates a new Challenge reducer with the specified initial state.
* @param {Object} initialState Optional. Initial state.
@@ -411,6 +444,8 @@ function create(initialState) {
[a.getActiveChallengesCountDone]: onGetActiveChallengesCountDone,
[a.getSubmissionInformationInit]: onGetSubmissionInformationInit,
[a.getSubmissionInformationDone]: onGetSubmissionInformationDone,
[a.fetchChallengeStatisticsInit]: onFetchChallengeStatisticsInit,
[a.fetchChallengeStatisticsDone]: onFetchChallengeStatisticsDone,
}, _.defaults(initialState, {
details: null,
loadingCheckpoints: false,
@@ -427,6 +462,7 @@ function create(initialState) {
updatingChallengeUuid: '',
mmSubmissions: [],
submissionInformation: null,
statisticsData: []
}));
}

15 changes: 15 additions & 0 deletions src/services/challenges.js
Original file line number Diff line number Diff line change
@@ -253,6 +253,21 @@ class ChallengesService {
};
}

/**
* Gets challenge statistics.
* @param {Number} challengeId
* @return {Promise} The array of statistics
*/
async getChallengeStatistics (challengeId) {
return this.private.apiV5.get(`/challenges/${challengeId}/statistics`)
.then(res => (res.ok ? res.json() : new Error(res.statusText)))
.then(res => (
res.message
? new Error(res.message)
: res
));
}

/**
* Activates the specified challenge.
* @param {Number} challengeId