Skip to content
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
27 changes: 11 additions & 16 deletions __tests__/shared/components/__snapshots__/Content.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,17 @@ exports[`Matches shallow shapshot 1`] = `
<code>
topcoder-react-lib/src/services/api.js
</code>
), with support of TC authentication (look for auth tokens either in
<code>
store.auth
</code>

of Redux store, or in
<code>
v3jwt
</code>

and
<code>
tcjwt
</code>

cookies of the front-end requests to the server);
), with support of TC authentication (look for auth tokens either in
<code>
store.auth
</code>

of Redux store, or in the

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[❗❗ correctness]
The change from v3jwt to tcjwt in the authentication token lookup might affect the authentication flow. Ensure that tcjwt is the correct and intended token to use in all contexts where this code is executed.

<code>
tcjwt
</code>

cookie of the front-end requests to the server);
</li>
<li>
Stylefmt;
Expand Down
1 change: 0 additions & 1 deletion __tests__/shared/reducers/challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ describe('Factory with server-side rendering', () => {
reducers.factory({
cookies: {
tcjwt: 'TcAuthTokenV2',
v3jwt: 'TcAuthTokenV3',
},
url: '/challenges/12345/my-submissions',
}).then((res) => {
Expand Down
270 changes: 222 additions & 48 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"dependencies": {
"@hapi/joi": "^16.1.4",
"@optimizely/react-sdk": "^2.5.0",
"@topcoder-platform/tc-auth-lib": "topcoder-platform/tc-auth-lib#1.0.4",
"@topcoder-platform/tc-auth-lib": "topcoder-platform/tc-auth-lib#v2.0",
"aos": "^2.3.4",
"atob": "^2.1.1",
"babel-register": "^6.26.0",
Expand Down Expand Up @@ -164,7 +164,7 @@
"supertest": "^3.1.0",
"tc-core-library-js": "github:appirio-tech/tc-core-library-js#v2.6.3.1",
"tc-ui": "^1.0.12",
"topcoder-react-lib": "github:topcoder-platform/topcoder-react-lib#v6",
"topcoder-react-lib": "github:topcoder-platform/topcoder-react-lib#auth0",
"topcoder-react-ui-kit": "2.0.1",
"topcoder-react-utils": "github:topcoder-platform/topcoder-react-utils#v6",
"turndown": "^4.0.2",
Expand Down
9 changes: 2 additions & 7 deletions src/shared/components/Content/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,12 @@ export default function Content() {
</code>
{' '}
of Redux store, or
in
<code>
v3jwt
</code>
{' '}
and
in the
<code>
tcjwt
</code>
{' '}
cookies of the front-end
cookie of the front-end
requests to the server);
</li>
<li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ const getDisplaySubmissionId = (submission) => {
return '';
};

const getSubmissionCreatedTime = (submission) => {
if (!submission) return undefined;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
The function getSubmissionCreatedTime returns undefined if submission is falsy. Consider returning null instead to explicitly indicate the absence of a value, which is more semantically correct and can prevent potential issues when this function's output is used elsewhere.

return (
submission.created
|| submission.createdAt
|| submission.submissionTime
|| submission.updated
|| submission.updatedAt
);
};

class SubmissionsListView extends React.Component {
constructor(props) {
Expand All @@ -73,7 +83,7 @@ class SubmissionsListView extends React.Component {
statusClicked: false,
finalClicked: false,
provisionClicked: false,
timeClicked: false,
timeClicked: true,
openModal: false,
selectedSubmission: {},
};
Expand Down Expand Up @@ -106,7 +116,7 @@ class SubmissionsListView extends React.Component {
} = this.props;
let { field, sort } = submissionsSort;
if (!field) {
field = 'Submission ID';
field = 'Time';
}

if (!sort) {
Expand Down Expand Up @@ -172,8 +182,8 @@ class SubmissionsListView extends React.Component {
break;
}
case 'Time': {
valueA = new Date(a.submissionTime);
valueB = new Date(b.submissionTime);
valueA = new Date(getSubmissionCreatedTime(a));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[❗❗ correctness]
When creating a new Date object with getSubmissionCreatedTime, ensure that the returned value is a valid date string or timestamp. If getSubmissionCreatedTime returns undefined, new Date(undefined) will result in an invalid date object, which could lead to unexpected behavior.

valueB = new Date(getSubmissionCreatedTime(b));
break;
}
default:
Expand Down Expand Up @@ -444,6 +454,10 @@ class SubmissionsListView extends React.Component {
const statusStyleName = isAccepted ? 'accepted' : 'queue';
const statusLabel = isAccepted ? 'Accepted' : 'In Queue';
const displaySubmissionId = getDisplaySubmissionId(mySubmission);
const submissionCreatedTime = getSubmissionCreatedTime(mySubmission);
const submissionTimeDisplay = submissionCreatedTime

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[❗❗ correctness]
Consider handling the case where submissionCreatedTime is an invalid date. Using moment with an invalid date will result in 'Invalid date' being displayed. Ensure that getSubmissionCreatedTime returns a valid date or handle the invalid case explicitly.

? moment(submissionCreatedTime).format('MMM DD, YYYY HH:mm:ss')
: 'N/A';
return (
<div
key={displaySubmissionId || mySubmission.submissionId || mySubmission.id}
Expand Down Expand Up @@ -498,7 +512,7 @@ class SubmissionsListView extends React.Component {
)}
>
<div styleName="mobile-header">Time</div>
<span>{moment(mySubmission.submissionTime).format('MMM DD, YYYY HH:mm:ss')}</span>
<span>{submissionTimeDisplay}</span>
</div>
<div styleName="submission-table-column column-2-4">
{ !isTopCrowdChallenge
Expand Down
55 changes: 38 additions & 17 deletions src/shared/containers/challenge-detail/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ class ChallengeDetailPageContainer extends React.Component {
sort: '',
},
mySubmissionsSort: {
field: '',
sort: '',
field: 'Time',
sort: 'desc',
},
notFoundCountryFlagUrl: {},
viewAsTable: false,
Expand Down Expand Up @@ -849,11 +849,43 @@ ChallengeDetailPageContainer.propTypes = {
getSubmissionArtifacts: PT.func,
};

function extractArrayFromStateSlice(slice, challengeId) {
if (Array.isArray(slice)) {
return slice;
}
if (slice && Array.isArray(slice.data)) {
return slice.data;
}
const key = challengeId ? String(challengeId) : null;
if (key && slice && slice[key]) {
const scoped = slice[key];
if (Array.isArray(scoped)) {
return scoped;
}
if (scoped && Array.isArray(scoped.data)) {
return scoped.data;
}
}
return [];
}

function mapStateToProps(state, props) {
const challengeId = String(props.match.params.challengeId);
const cl = state.challengeListing;
const { lookup: { allCountries, reviewTypes } } = state;
let { challenge: { mmSubmissions } } = state;
const reviewSummations = extractArrayFromStateSlice(
state.challenge.reviewSummations,
challengeId,
);
let mmSubmissions = extractArrayFromStateSlice(state.challenge.mmSubmissions, challengeId);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
The variable mmSubmissions is reassigned with the result of buildMmSubmissionData without checking if reviewSummations is an array. Consider adding a check to ensure reviewSummations is an array before reassigning mmSubmissions to prevent potential runtime errors.

if (!mmSubmissions.length && reviewSummations.length) {
mmSubmissions = buildMmSubmissionData(reviewSummations);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
The function buildMmSubmissionData is called without checking if reviewSummations is an array. Consider adding a check to ensure reviewSummations is an array before calling this function to prevent potential runtime errors.

}
const { auth } = state;
let statisticsData = extractArrayFromStateSlice(state.challenge.statisticsData, challengeId);
if ((!Array.isArray(statisticsData) || !statisticsData.length) && reviewSummations.length) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
The variable statisticsData is reassigned with the result of buildStatisticsData without checking if reviewSummations is an array. Consider adding a check to ensure reviewSummations is an array before reassigning statisticsData to prevent potential runtime errors.

statisticsData = buildStatisticsData(reviewSummations);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
The function buildStatisticsData is called without checking if reviewSummations is an array. Consider adding a check to ensure reviewSummations is an array before calling this function to prevent potential runtime errors.

}
const challenge = state.challenge.details || {};
let mySubmissions = [];
if (challenge.registrants) {
Expand Down Expand Up @@ -1087,7 +1119,7 @@ function mapStateToProps(state, props) {
// recommendedChallenges: cl.recommendedChallenges,
// loadingRecommendedChallengesUUID: cl.loadingRecommendedChallengesUUID,
expandedTags: cl.expandedTags,
challengeId: String(props.match.params.challengeId),
challengeId,
challengesUrl: props.challengesUrl,
challengeTypesMap: state.challengeListing.challengeTypesMap,
checkpointResults: checkpoints.checkpointResults,
Expand All @@ -1099,7 +1131,7 @@ function mapStateToProps(state, props) {
isLoadingChallenge: Boolean(state.challenge.loadingDetailsForChallengeId),
isLoadingTerms: _.isEqual(state.terms.loadingTermsForEntity, {
type: 'challenge',
id: props.match.params.challengeId,
id: challengeId,
}),
loadingCheckpointResults: state.challenge.loadingCheckpoints,
loadingResultsForChallengeId: state.challenge.loadingResultsForChallengeId,
Expand All @@ -1124,31 +1156,20 @@ function mapStateToProps(state, props) {
mySubmissions,
reviewTypes,
openForRegistrationChallenges: state.challengeListing.openForRegistrationChallenges,
statisticsData: state.challenge.statisticsData,
statisticsData,
};
}

const mapDispatchToProps = (dispatch) => {
const ca = communityActions.tcCommunity;
const lookupActions = actions.lookup;
const challengeActions = actions.challenge || {};
const hasReviewSummationsActions = (
typeof challengeActions.getReviewSummationsInit === 'function'
&& typeof challengeActions.getReviewSummationsDone === 'function'
);

const dispatchReviewSummations = (challengeId, tokenV3) => {
const challengeIdStr = _.toString(challengeId);
if (!challengeIdStr) {
return;
}

if (hasReviewSummationsActions) {
dispatch(challengeActions.getReviewSummationsInit(challengeIdStr));
dispatch(challengeActions.getReviewSummationsDone(challengeIdStr, tokenV3));
return;
}

dispatch({
type: 'CHALLENGE/GET_REVIEW_SUMMATIONS_INIT',
payload: challengeIdStr,
Expand Down
3 changes: 2 additions & 1 deletion src/shared/utils/tc.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ export function getUnSelectedColors(rating) {
export function getAuthTokens(req = {}) {
const cookies = req.cookies || {};
let tokenV2 = cookies.tcjwt;
let tokenV3 = cookies.v3jwt;
let tokenV3 = cookies.tcjwt;
Comment thread
jmgasper marked this conversation as resolved.

if (!tokenV2 || isTokenExpired(tokenV2, config.AUTH_DROP_TIME)) {
tokenV2 = '';
}
Expand Down
Loading