Skip to content

Code 30108491 #116

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
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
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -10,6 +10,10 @@ The [Topcoder](https://www.topcoder.com) lib for internal ReactJS projects.

Change the property in `AV_SCAN_SCORER_REVIEW_TYPE_ID` in config.

### Configuration for AV-Scan scorer review type ID

Change the property in `PROVISIONAL_SCORING_COMPLETED_REVIEW_TYPE_ID` in config.

### Development
```shell
# Install dependencies
@@ -19,7 +23,7 @@ npm install
npm test
npm run build

# Go to other project which depends on the topcoder-react-lib, config its package.json so
# Go to other project which depends on the topcoder-react-lib, config its package.json so
# that the 'topcoder-react-lib' points to the local foler path of topcoder-react-lib:
#
# "dependencies": {
2 changes: 2 additions & 0 deletions __tests__/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
@@ -62,6 +62,8 @@ Object {
"getAllCountriesInit": [Function],
"getCountriesDone": [Function],
"getCountriesInit": [Function],
"getReviewTypesDone": [Function],
"getReviewTypesInit": [Function],
"getSkillTagsDone": [Function],
"getSkillTagsInit": [Function],
},
2 changes: 2 additions & 0 deletions __tests__/actions/__snapshots__/lookup.js.snap
Original file line number Diff line number Diff line change
@@ -7,6 +7,8 @@ Object {
"getAllCountriesInit": [Function],
"getCountriesDone": [Function],
"getCountriesInit": [Function],
"getReviewTypesDone": [Function],
"getReviewTypesInit": [Function],
"getSkillTagsDone": [Function],
"getSkillTagsInit": [Function],
},
10 changes: 10 additions & 0 deletions __tests__/reducers/__snapshots__/lookup.js.snap
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ Object {
],
"loadingCountriesError": false,
"loadingSkillTagsError": true,
"reviewTypes": Array [],
"skillTags": Array [
Object {
"domain": "SKILLS",
@@ -33,6 +34,7 @@ Object {
],
"loadingCountriesError": true,
"loadingSkillTagsError": true,
"reviewTypes": Array [],
"skillTags": Array [
Object {
"domain": "SKILLS",
@@ -49,6 +51,7 @@ Object {
"allCountries": Array [],
"countries": Array [],
"loadingSkillTagsError": false,
"reviewTypes": Array [],
"skillTags": Array [
Object {
"domain": "SKILLS",
@@ -65,6 +68,7 @@ Object {
"allCountries": Array [],
"countries": Array [],
"loadingSkillTagsError": true,
"reviewTypes": Array [],
"skillTags": Array [
Object {
"domain": "SKILLS",
@@ -80,6 +84,7 @@ exports[`Default reducer Initial state 1`] = `
Object {
"allCountries": Array [],
"countries": Array [],
"reviewTypes": Array [],
"skillTags": Array [],
}
`;
@@ -95,6 +100,7 @@ Object {
],
"loadingCountriesError": false,
"loadingSkillTagsError": true,
"reviewTypes": Array [],
"skillTags": Array [
Object {
"domain": "SKILLS",
@@ -117,6 +123,7 @@ Object {
],
"loadingCountriesError": true,
"loadingSkillTagsError": true,
"reviewTypes": Array [],
"skillTags": Array [
Object {
"domain": "SKILLS",
@@ -133,6 +140,7 @@ Object {
"allCountries": Array [],
"countries": Array [],
"loadingSkillTagsError": false,
"reviewTypes": Array [],
"skillTags": Array [
Object {
"domain": "SKILLS",
@@ -149,6 +157,7 @@ Object {
"allCountries": Array [],
"countries": Array [],
"loadingSkillTagsError": true,
"reviewTypes": Array [],
"skillTags": Array [
Object {
"domain": "SKILLS",
@@ -164,6 +173,7 @@ exports[`Factory without server side rendering Initial state 1`] = `
Object {
"allCountries": Array [],
"countries": Array [],
"reviewTypes": Array [],
"skillTags": Array [],
}
`;
1 change: 1 addition & 0 deletions config/default.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"AV_SCAN_SCORER_REVIEW_TYPE_ID": "",
"PROVISIONAL_SCORING_COMPLETED_REVIEW_TYPE_ID": "",
"PAGE_SIZE": 50,
"REVIEW_OPPORTUNITY_PAGE_SIZE": 1000
}
3 changes: 2 additions & 1 deletion config/development.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"AV_SCAN_SCORER_REVIEW_TYPE_ID": "68c5a381-c8ab-48af-92a7-7a869a4ee6c3"
"AV_SCAN_SCORER_REVIEW_TYPE_ID": "68c5a381-c8ab-48af-92a7-7a869a4ee6c3",
"PROVISIONAL_SCORING_COMPLETED_REVIEW_TYPE_ID": "df51ca7d-fb0a-4147-9569-992fcf5aae48"
}
3 changes: 2 additions & 1 deletion config/production.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"AV_SCAN_SCORER_REVIEW_TYPE_ID": "55bbb17d-aac2-45a6-89c3-a8d102863d05"
"AV_SCAN_SCORER_REVIEW_TYPE_ID": "55bbb17d-aac2-45a6-89c3-a8d102863d05",
"PROVISIONAL_SCORING_COMPLETED_REVIEW_TYPE_ID": ""
}
114 changes: 57 additions & 57 deletions dist/dev/index.js

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions docs/actions.lookup.md
Original file line number Diff line number Diff line change
@@ -11,6 +11,8 @@ Actions related to lookup data.
* [.getCountriesDone()](#module_actions.lookup.getCountriesDone) ⇒ <code>Action</code>
* [.getAllCountriesInit()](#module_actions.lookup.getCountriesInit) ⇒ <code>Action</code>
* [.getAllCountriesDone(tokenV3)](#module_actions.lookup.getCountriesDone) ⇒ <code>Action</code>
* [.getReviewTypesInit()](#module_actions.lookup.getReviewTypesInit) ⇒ <code>Action</code>
* [.getReviewTypesDone(tokenV3)](#module_actions.lookup.ggetReviewTypesDone) ⇒ <code>Action</code>

<a name="module_actions.lookup.getSkillTagsInit"></a>

@@ -40,3 +42,19 @@ Creates an action that gets all countries new version.
| Param | Type | Description |
| --- | --- | --- |
| tokenV3 | <code>String</code> | Topcoder v3 auth token. |
<a name="module_actions.lookup.getReviewTypesInit"></a>

### actions.lookup.getReviewTypesInit() ⇒ <code>Action</code>
Creates an action that gets all reiview types.

**Kind**: static method of [<code>actions.lookup</code>](#module_actions.lookup)
<a name="module_actions.lookup.getReviewTypesDone"></a>

### actions.lookup.getReviewTypesDone(tokenV3) ⇒ <code>Action</code>
Creates an action that gets all review types.

**Kind**: static method of [<code>actions.lookup</code>](#module_actions.lookup)

| Param | Type | Description |
| --- | --- | --- |
| tokenV3 | <code>String</code> | Topcoder v3 auth token. |
31 changes: 22 additions & 9 deletions docs/reducers.lookup.md
Original file line number Diff line number Diff line change
@@ -18,35 +18,48 @@ State segment managed by this reducer has the following structure:
* _inner_
* [~onGetSkillTagsDone(state, action)](#module_reducers.lookup..onGetSkillTagsDone) ⇒ <code>Object</code>
* [~onGetCountriesDone(state, action)](#module_reducers.lookup..onGetCountriesDone) ⇒ <code>Object</code>
* [~onGetReviewTypesDone(state, action)](#module_reducers.lookup..onGetReviewTypesDone) ⇒ <code>Object</code>
* [~create(initialState)](#module_reducers.lookup..create) ⇒ <code>function</code>

<a name="module_reducers.lookup.default"></a>

### reducers.lookup.default
Reducer with default initial state.

**Kind**: static property of [<code>reducers.lookup</code>](#module_reducers.lookup)
**Kind**: static property of [<code>reducers.lookup</code>](#module_reducers.lookup)
<a name="module_reducers.lookup.factory"></a>

### reducers.lookup.factory() ⇒ <code>Promise</code>
Factory which creates a new reducer.

**Kind**: static method of [<code>reducers.lookup</code>](#module_reducers.lookup)
**Resolves**: <code>Function(state, action): state</code> New reducer.
**Kind**: static method of [<code>reducers.lookup</code>](#module_reducers.lookup)
**Resolves**: <code>Function(state, action): state</code> New reducer.
<a name="module_reducers.lookup..onGetSkillTagsDone"></a>

### reducers.lookup~onGetSkillTagsDone(state, action) ⇒ <code>Object</code>
Handles LOOKUP/GET_SKILL_TAGS_DONE action.

**Kind**: static method of [<code>reducers.lookup</code>](#module_reducers.lookup)
**Resolves**: <code>Function(state, action): state</code> New reducer.
**Kind**: static method of [<code>reducers.lookup</code>](#module_reducers.lookup)
**Resolves**: <code>Function(state, action): state</code> New reducer.
<a name="module_reducers.lookup..onGetCountriesDone"></a>

### reducers.lookup~onGetCountriesDone(state, action) ⇒ <code>Object</code>
Handles LOOKUP/GET_COUNTRIES_DONE action.

**Kind**: inner method of [<code>reducers.lookup</code>](#module_reducers.lookup)
**Returns**: <code>Object</code> - New state
**Kind**: inner method of [<code>reducers.lookup</code>](#module_reducers.lookup)
**Returns**: <code>Object</code> - New state

| Param | Type | Description |
| --- | --- | --- |
| state | <code>Object</code> | |
| action | <code>Object</code> | Payload will be JSON from api call |
<a name="module_reducers.lookup..onGetReviewTypesDone"></a>

### reducers.lookup~onGetReviewTypesDone(state, action) ⇒ <code>Object</code>
Handles LOOKUP/GET_REVIEW_TYPES_DONE action.

**Kind**: inner method of [<code>reducers.lookup</code>](#module_reducers.lookup)
**Returns**: <code>Object</code> - New state

| Param | Type | Description |
| --- | --- | --- |
@@ -58,8 +71,8 @@ Handles LOOKUP/GET_COUNTRIES_DONE action.
### reducers.lookup~create(initialState) ⇒ <code>function</code>
Creates a new Lookup reducer with the specified initial state.

**Kind**: inner method of [<code>reducers.lookup</code>](#module_reducers.lookup)
**Returns**: <code>function</code> - Lookup reducer.
**Kind**: inner method of [<code>reducers.lookup</code>](#module_reducers.lookup)
**Returns**: <code>function</code> - Lookup reducer.

| Param | Type | Description |
| --- | --- | --- |
14 changes: 14 additions & 0 deletions docs/services.submissions.md
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ via API V5.
* [new SubmissionsService(tokenV3)](#new_module_services.submissions..SubmissionsService_new)
* [.getSubmissions(filters, params)](#module_services.submissions..SubmissionsService+getSubmissions) ⇒ <code>Promise</code>
* [.getSubmissionInformation(submissionId)](#module_services.submissions..SubmissionsService+getSubmissionInformation) ⇒ <code>Promise</code>
* [.downloadSubmission(submissionId)](#module_services.submissions..SubmissionsService+downloadSubmission) ⇒ <code>Promise</code>

<a name="module_services.submissions.getService"></a>

@@ -35,6 +36,7 @@ Returns a new or existing submissions service.
* [new SubmissionsService(tokenV3)](#new_module_services.submissions..SubmissionsService_new)
* [.getSubmissions(filters, params)](#module_services.submissions..SubmissionsService+getSubmissions) ⇒ <code>Promise</code>
* [.getSubmissionInformation(submissionId)](#module_services.submissions..SubmissionsService+getSubmissionInformation) ⇒ <code>Promise</code>
* [.downloadSubmission(submissionId)](#module_services.submissions..SubmissionsService+downloadSubmission) ⇒ <code>Promise</code>

<a name="new_module_services.submissions..SubmissionsService_new"></a>

@@ -68,3 +70,15 @@ Gets submission information.
| Param | Type | Description |
| --- | --- | --- |
| submissionId | <code>String</code> | The id of submission |

<a name="module_services.submissions..SubmissionsService+downloadSubmission"></a>

#### submissionsService.downloadSubmission(submissionId) ⇒ <code>Promise</code>
Download submission.

**Kind**: instance method of [<code>SubmissionsService</code>](#module_services.submissions..SubmissionsService)
**Returns**: <code>Promise</code> - Resolves to the submission file.

| Param | Type | Description |
| --- | --- | --- |
| submissionId | <code>String</code> | The id of submission |
19 changes: 19 additions & 0 deletions src/actions/lookup.js
Original file line number Diff line number Diff line change
@@ -42,6 +42,23 @@ function getCountriesDone() {
return getService().getCountries();
}

/**
* @static
* @desc Creates an action that signals beginning of getting all review types.
* @return {Action}
*/
function getReviewTypesInit() {}

/**
* @static
* @desc Creates an action that gets all review types.
* @param {String} tokenV3 Optional. Auth token for Topcoder API v3.
* @return {Action}
*/
function getReviewTypesDone(tokenV3) {
return getService(tokenV3).getReviewTypes();
}

/**
* @static
* @desc Creates an action that signals beginning of getting all countries api version 5.
@@ -65,6 +82,8 @@ export default createActions({
GET_SKILL_TAGS_DONE: getSkillTagsDone,
GET_COUNTRIES_INIT: getCountriesInit,
GET_COUNTRIES_DONE: getCountriesDone,
GET_REVIEW_TYPES_INIT: getReviewTypesInit,
GET_REVIEW_TYPES_DONE: getReviewTypesDone,
GET_ALL_COUNTRIES_INIT: getAllCountriesInit,
GET_ALL_COUNTRIES_DONE: getAllCountriesDone,
},
22 changes: 22 additions & 0 deletions src/reducers/lookup.js
Original file line number Diff line number Diff line change
@@ -48,6 +48,25 @@ function onGetCountriesDone(state, { payload, error }) {
});
}

/**
* Handles LOOKUP/GET_REVIEW_TYPES_DONE action.
* @param {Object} state
* @param {Object} action Payload will be JSON from api call
* @return {Object} New state
*/
function onGetReviewTypesDone(state, { payload, error }) {
if (error) {
logger.error('Failed to get review types', payload);
return { ...state, loadingReviewTypesError: true };
}

return ({
...state,
loadingReviewTypesError: false,
reviewTypes: payload,
});
}

/**
* Handles LOOKUP/GET_ALL_COUNTRIES_DONE action.
* @param {Object} state
@@ -79,12 +98,15 @@ function create(initialState = {}) {
[a.getSkillTagsDone]: onGetSkillTagsDone,
[a.getCountriesInit]: state => state,
[a.getCountriesDone]: onGetCountriesDone,
[a.getReviewTypesInit]: state => state,
[a.getReviewTypesDone]: onGetReviewTypesDone,
[a.getAllCountriesInit]: state => state,
[a.getAllCountriesDone]: onGetAllCountriesDone,
}, _.defaults(initialState, {
skillTags: [],
countries: [],
allCountries: [],
reviewTypes: [],
}));
}

10 changes: 10 additions & 0 deletions src/services/lookup.js
Original file line number Diff line number Diff line change
@@ -48,6 +48,16 @@ class LookupService {
const jsonResult = await res.json();
return jsonResult;
}

/**
* Gets all reviewTypes.
* @return {Promise} Resolves to the review types.
*/
async getReviewTypes() {
const res = await this.private.apiV5.get('/reviewTypes');
const jsonResult = await res.json();
return jsonResult;
}
}

let lastInstance = null;
10 changes: 10 additions & 0 deletions src/services/submissions.js
Original file line number Diff line number Diff line change
@@ -50,6 +50,16 @@ class SubmissionsService {
.then(res => (res.ok ? res.json() : new Error(res.statusText)))
.then(res => res);
}

/**
* Download submission.
* @param {Number|String} submissionId Submission ID.
* @return {Promise} Resolves to the list of submission object.
*/
async downloadSubmission(submissionId) {
return this.private.apiV5.get(`/submissions/${submissionId}/download`)
.then(response => response.blob());
}
}

let lastInstance = null;
8 changes: 7 additions & 1 deletion src/utils/submission.js
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
/* eslint-disable no-param-reassign */
import _ from 'lodash';

const { AV_SCAN_SCORER_REVIEW_TYPE_ID } = CONFIG;
const { AV_SCAN_SCORER_REVIEW_TYPE_ID, PROVISIONAL_SCORING_COMPLETED_REVIEW_TYPE_ID } = CONFIG;

function removeDecimal(num) {
const re = new RegExp('^-?\\d+');
@@ -142,6 +142,10 @@ export function processMMSubmissions(submissions, resources, registrants) {
return dateB - dateA;
});

const provisionalScoringIsCompleted = _.some(
submission.review,
{ id: PROVISIONAL_SCORING_COMPLETED_REVIEW_TYPE_ID },
);
const provisionalScore = toFixed(_.get(validReviews, '[0].score', '-'), 5);
const finalScore = toFixed(_.get(submission, 'reviewSummation[0].aggregateScore', '-'), 5);

@@ -150,6 +154,8 @@ export function processMMSubmissions(submissions, resources, registrants) {
submissionTime: submission.created,
provisionalScore,
finalScore,
provisionalScoringIsCompleted,
review: submission.review,
});
});