Skip to content

Commit b5e045b

Browse files
Fix code quality issues from V4 changes
1 parent 626aa51 commit b5e045b

File tree

11 files changed

+64
-103
lines changed

11 files changed

+64
-103
lines changed

.eslintrc

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,3 @@
11
{
2-
"extends": "./node_modules/topcoder-react-utils/config/eslint/default.json",
3-
"rules": {
4-
"jsx-a11y/label-has-for": [
5-
2,
6-
{
7-
"components": [
8-
"Label"
9-
],
10-
"required": {
11-
"some": [
12-
"nesting",
13-
"id"
14-
]
15-
},
16-
"allowChildren": false
17-
}
18-
],
19-
"jsx-a11y/label-has-associated-control": [
20-
2,
21-
{
22-
"labelComponents": [
23-
"CustomLabel"
24-
],
25-
"labelAttributes": [
26-
"inputLabel"
27-
],
28-
"controlComponents": [
29-
"CustomInput"
30-
],
31-
"depth": 3
32-
}
33-
],
34-
"no-unused-vars": 0,
35-
"no-undef": 0,
36-
"react/jsx-no-undef": 0,
37-
"react/require-default-props": 0
38-
}
2+
"extends": "./node_modules/topcoder-react-utils/config/eslint/default.json"
393
}

__tests__/__snapshots__/index.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,8 @@ Object {
309309
"Iterative Review": "Iterative Review",
310310
"Spec Review": "Specification Review",
311311
},
312-
"getApiResponsePayloadV3": [Function],
313-
"getApiResponsePayloadV4": [Function],
312+
"getApiResponsePayload": [Function],
313+
"getLookerApiResponsePayload": [Function],
314314
},
315315
"time": Object {
316316
"default": undefined,

docs/tc.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ Collection of small Topcoder-related functions.
1010

1111
* [tc](#module_tc)
1212
* [.REVIEW_OPPORTUNITY_TYPES](#module_tc.REVIEW_OPPORTUNITY_TYPES)
13-
* [.getApiResponsePayloadV3(res)](#module_tc.getApiResponsePayloadV3) ⇒ <code>Promise</code>
13+
* [.getApiResponsePayload(res)](#module_tc.getApiResponsePayload) ⇒ <code>Promise</code>
1414

1515
<a name="module_tc.REVIEW_OPPORTUNITY_TYPES"></a>
1616

1717
### tc.REVIEW_OPPORTUNITY_TYPES
1818
Review Opportunity types
1919

2020
**Kind**: static constant of [<code>tc</code>](#module_tc)
21-
<a name="module_tc.getApiResponsePayloadV3"></a>
21+
<a name="module_tc.getApiResponsePayload"></a>
2222

23-
### tc.getApiResponsePayloadV3(res) ⇒ <code>Promise</code>
24-
Gets payload from a standard success response from TC API v3; or throws
23+
### tc.getApiResponsePayload(res) ⇒ <code>Promise</code>
24+
Gets payload from a standard success response from TC API; or throws
2525
an error in case of a failure response.
2626

2727
**Kind**: static method of [<code>tc</code>](#module_tc)

src/services/api.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import { config, isomorphy } from 'topcoder-react-utils';
99
import { delay } from '../utils/time';
1010
import { setErrorIcon, ERROR_ICON_TYPES } from '../utils/errors';
1111

12-
// config.API.V4 = 'https://api.topcoder.com/v4';
13-
1412
/* The minimal delay [ms] between API calls. To avoid problems with the requests
1513
* rate limits configured in Topcoder APIs, we throttle requests rate at the
1614
* client side, and at server-side, in dev mode (which is meant to be used for

src/services/challenges.js

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import qs from 'qs';
1010
import { decodeToken } from 'tc-accounts';
1111
import logger from '../utils/logger';
1212
import { setErrorIcon, ERROR_ICON_TYPES } from '../utils/errors';
13-
import { COMPETITION_TRACKS, getApiResponsePayloadV3 } from '../utils/tc';
14-
import { getApiV2, getApiV3, getApiV4 } from './api';
13+
import { COMPETITION_TRACKS, getApiResponsePayload } from '../utils/tc';
14+
import { getApiV2, getApiV4 } from './api';
1515

1616
export const ORDER_BY = {
1717
SUBMISSION_END_DATE: 'submissionEndDate',
@@ -86,7 +86,7 @@ export function normalizeChallengeDetails(v4, v4Filtered, v4User, username) {
8686
registrants: v4.registrants || [],
8787
};
8888

89-
// v4 Winners have different field names, needs to be normalized to match v4 filtered and v3
89+
// v4 Winners have different field names, needs to be normalized to match v4 filtered and v4
9090
challenge.winners = _.map(
9191
v4.winners,
9292
(winner, index) => ({
@@ -117,22 +117,22 @@ export function normalizeChallengeDetails(v4, v4Filtered, v4User, username) {
117117
componentId: v4Filtered.componentId,
118118
contestId: v4Filtered.contestId,
119119

120-
submissionEndDate: v4Filtered.submissionEndDate, // Dates are not correct in v3
121-
submissionEndTimestamp: v4Filtered.submissionEndDate, // Dates are not correct in v3
120+
submissionEndDate: v4Filtered.submissionEndDate, // Dates are not correct in v4
121+
submissionEndTimestamp: v4Filtered.submissionEndDate, // Dates are not correct in v4
122122

123-
/* Taking phases from v3_filtered, because dates are not correct in v3 */
123+
/* Taking phases from v4_filtered, because dates are not correct in v4 */
124124
allPhases: v4Filtered.allPhases || [],
125125

126-
/* Taking phases from v3_filtered, because dates are not correct in v3 */
126+
/* Taking phases from v4_filtered, because dates are not correct in v4 */
127127
currentPhases: v4Filtered.currentPhases || [],
128128

129-
/* v3 returns incorrect value for numberOfSubmissions for some reason */
129+
/* v4 returns incorrect value for numberOfSubmissions for some reason */
130130
numSubmissions: v4Filtered.numSubmissions,
131131
groups,
132132
});
133133
}
134134

135-
// Fill missing data from v3_user
135+
// Fill missing data from v4_user
136136
if (v4User) {
137137
_.defaults(challenge, {
138138
userDetails: v4User.userDetails,
@@ -168,7 +168,7 @@ export function normalizeChallengeDetails(v4, v4Filtered, v4User, username) {
168168
* Normalizes a regular challenge object received from the backend.
169169
* NOTE: This function is copied from the existing code in the challenge listing
170170
* component. It is possible, that this normalization is not necessary after we
171-
* have moved to Topcoder API v3, but it is kept for now to minimize a risk of
171+
* have moved to Topcoder API v4, but it is kept for now to minimize a risk of
172172
* breaking anything.
173173
* @todo Should be used only internally!
174174
* @param {Object} challenge Challenge object received from the backend.
@@ -251,7 +251,7 @@ class ChallengesService {
251251
...params,
252252
};
253253
const url = `${endpoint}?${qs.stringify(query)}`;
254-
const res = await this.private.apiV4.get(url).then(checkError);
254+
const res = await this.private.api.get(url).then(checkError);
255255
return {
256256
challenges: res.content || [],
257257
totalCount: res.metadata.totalCount,
@@ -261,7 +261,6 @@ class ChallengesService {
261261
this.private = {
262262
api: getApiV4(tokenV3),
263263
apiV2: getApiV2(tokenV2),
264-
apiV4: getApiV4(tokenV3),
265264
getChallenges,
266265
tokenV2,
267266
tokenV3,
@@ -359,14 +358,14 @@ class ChallengesService {
359358

360359
/**
361360
* Gets challenge details from Topcoder API v4.
362-
* NOTE: This function also uses API v2 and other v3 endpoints for now, due
361+
* NOTE: This function also uses API v2 and other v4 endpoints for now, due
363362
* to some information is missing or
364-
* incorrect in the main v3 endpoint. This may change in the future.
363+
* incorrect in the main v4 endpoint. This may change in the future.
365364
* @param {Number|String} challengeId
366365
* @return {Promise} Resolves to the challenge object.
367366
*/
368367
async getChallengeDetails(challengeId) {
369-
const challengeV4 = await this.private.apiV4.get(`/challenges/${challengeId}`)
368+
const challengeV4 = await this.private.api.get(`/challenges/${challengeId}`)
370369
.then(checkError).then(res => res.content);
371370

372371
const challengeV4Filtered = await this.private.getChallenges('/challenges/', { id: challengeId })
@@ -437,7 +436,7 @@ class ChallengesService {
437436
*/
438437
async getSrms(params) {
439438
const res = await this.private.api.get(`/srms/?${qs.stringify(params)}`);
440-
return getApiResponsePayloadV3(res);
439+
return getApiResponsePayload(res);
441440
}
442441

443442
/**
@@ -466,7 +465,7 @@ class ChallengesService {
466465
async getUserSrms(handle, params) {
467466
const url = `/members/${handle}/srms/?${qs.stringify(params)}`;
468467
const res = await this.private.api.get(url);
469-
return getApiResponsePayloadV3(res);
468+
return getApiResponsePayload(res);
470469
}
471470

472471
/**
@@ -476,7 +475,7 @@ class ChallengesService {
476475
*/
477476
async register(challengeId) {
478477
const endpoint = `/challenges/${challengeId}/register`;
479-
const res = await this.private.apiV4.postJson(endpoint);
478+
const res = await this.private.api.postJson(endpoint);
480479
if (!res.ok) throw new Error(res.statusText);
481480
return res.json();
482481
}
@@ -488,7 +487,7 @@ class ChallengesService {
488487
*/
489488
async unregister(challengeId) {
490489
const endpoint = `/challenges/${challengeId}/unregister`;
491-
const res = await this.private.apiV4.post(endpoint);
490+
const res = await this.private.api.post(endpoint);
492491
if (!res.ok) throw new Error(res.statusText);
493492
return res.json();
494493
}

src/services/looker.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @desc This module provides a service to get look data json
44
* via API V4.
55
*/
6-
import { getApiResponsePayloadV4 } from '../utils/tc';
6+
import { getLookerApiResponsePayload } from '../utils/tc';
77
import { getApiV4 } from './api';
88

99
/**
@@ -27,7 +27,7 @@ class LookerService {
2727
*/
2828
async getLooker(lookerId) {
2929
const res = await this.private.api.get(`/looks/${lookerId}/run/json`);
30-
return getApiResponsePayloadV4(res);
30+
return getLookerApiResponsePayload(res);
3131
}
3232
}
3333

src/services/lookup.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* via API V3.
55
*/
66
import qs from 'qs';
7-
import { getApiResponsePayloadV3 } from '../utils/tc';
7+
import { getApiResponsePayload } from '../utils/tc';
88
import { getApiV3 } from './api';
99

1010
class LookupService {
@@ -25,7 +25,7 @@ class LookupService {
2525
*/
2626
async getTags(params) {
2727
const res = await this.private.api.get(`/tags/?${qs.stringify(params)}`);
28-
return getApiResponsePayloadV3(res);
28+
return getApiResponsePayload(res);
2929
}
3030
}
3131

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy