Skip to content

PR for private stats feature #4060

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 13 commits into from
Mar 4, 2020
6 changes: 2 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ workflows:
filters:
branches:
only:
- develop
- feature-m2m-token
- feature-m2m-with-stats
# This is alternate dev env for parallel testing
- "build-test":
context : org-global
Expand All @@ -191,8 +190,7 @@ workflows:
filters:
branches:
only:
- develop
- feature-contentful
- develop
# Production builds are exectuted only on tagged commits to the
# master branch.
- "build-prod":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ exports[`renders a full Profile correctly 1`] = `
className=""
handle="testHandle"
inModal={false}
meta={null}
stats={
Object {
"COPILOT": Object {
Expand Down Expand Up @@ -699,6 +700,7 @@ exports[`renders an empty Profile correctly 1`] = `
className=""
handle="testHandle"
inModal={false}
meta={null}
stats={
Object {
"COPILOT": null,
Expand Down
2 changes: 1 addition & 1 deletion src/shared/components/ProfilePage/Skill/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const Skill = ({
Skill.propTypes = {
tagId: PT.string.isRequired,
tagName: PT.string.isRequired,
isVerified: PT.string.isRequired,
isVerified: PT.bool.isRequired,
};

export default Skill;
11 changes: 7 additions & 4 deletions src/shared/components/ProfilePage/Stats/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
import _ from 'lodash';
import React from 'react';
import PT from 'prop-types';
import { Link } from 'react-router-dom';
import ReactSVG from 'react-svg';
import { isomorphy } from 'topcoder-react-utils';
import { Link, isomorphy } from 'topcoder-react-utils';
import { getRatingColor } from 'utils/tc';
import Th from 'assets/images/th.svg';
import LeftArrow from 'assets/images/arrow-prev.svg';
Expand Down Expand Up @@ -50,7 +49,6 @@ class ProfileStats extends React.Component {

render() {
const {
stats,
statsDistribution,
statsHistory,
track,
Expand All @@ -60,6 +58,11 @@ class ProfileStats extends React.Component {
handleParam,
activeChallengesCount,
} = this.props;
let { stats } = this.props;
if (_.isArray(stats)) {
// eslint-disable-next-line prefer-destructuring
stats = stats[0];
}

const { activeGraph, showModal } = this.state;

Expand Down Expand Up @@ -300,7 +303,7 @@ ProfileStats.defaultProps = {
};

ProfileStats.propTypes = {
stats: PT.shape().isRequired,
stats: PT.arrayOf(PT.shape()).isRequired,
handleParam: PT.string.isRequired,
track: PT.string.isRequired,
subTrack: PT.string.isRequired,
Expand Down
13 changes: 10 additions & 3 deletions src/shared/components/ProfilePage/StatsCategory/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ const isActiveSubtrack = (subtrack) => {

class StatsCategory extends React.Component {
getActiveTracks() {
const { stats } = this.props;
let { stats } = this.props;
if (_.isArray(stats)) {
// eslint-disable-next-line prefer-destructuring
stats = stats[0];
}
const activeTracks = [];

if (stats.COPILOT && stats.COPILOT.fulfillment) {
Expand Down Expand Up @@ -89,6 +93,7 @@ class StatsCategory extends React.Component {
handle,
className,
inModal,
meta,
} = this.props;

const activeTracks = this.getActiveTracks();
Expand All @@ -113,7 +118,7 @@ class StatsCategory extends React.Component {
<Link
to={`/members/${handle}/details/?track=${track.name}&subTrack=${subtrack.name.replace(' ', '_')}`}
key={subtrack.name}
styleName={`subtrack ${index === 0 ? 'first' : ''}`}
styleName={`subtrack ${index === 0 ? 'first' : ''} ${meta ? 'disablelink' : ''}`}
>
<div
styleName="name"
Expand Down Expand Up @@ -179,13 +184,15 @@ class StatsCategory extends React.Component {
StatsCategory.defaultProps = {
className: '',
inModal: false,
meta: null,
};

StatsCategory.propTypes = {
handle: PT.string.isRequired,
stats: PT.shape().isRequired,
stats: PT.arrayOf(PT.shape()).isRequired,
inModal: PT.bool,
className: PT.string,
meta: PT.shape(),
};

export default StatsCategory;
4 changes: 4 additions & 0 deletions src/shared/components/ProfilePage/StatsCategory/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@
}
}

.disablelink {
pointer-events: none;
}

.icon {
width: 80px;
height: 80px;
Expand Down
14 changes: 11 additions & 3 deletions src/shared/components/ProfilePage/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ class ProfilePage extends React.Component {
}

getActiveTracks() {
const { copilot, stats } = this.props;
const { copilot } = this.props;
let { stats } = this.props;
if (_.isArray(stats)) {
// eslint-disable-next-line prefer-destructuring
stats = stats[0];
}
const activeTracks = [];

if (copilot && stats && stats.COPILOT && stats.COPILOT.fulfillment) {
Expand Down Expand Up @@ -118,6 +123,7 @@ class ProfilePage extends React.Component {
skills: propSkills,
stats,
lookupData,
meta,
} = this.props;

const {
Expand Down Expand Up @@ -257,7 +263,7 @@ class ProfilePage extends React.Component {
{
stats && (
<div id="profile-activity">
<StatsCategory handle={info.handle} stats={stats} />
<StatsCategory handle={info.handle} stats={stats} meta={meta} />
</div>
)
}
Expand Down Expand Up @@ -297,6 +303,7 @@ ProfilePage.defaultProps = {
achievements: [],
skills: null,
stats: null,
meta: null,
};

ProfilePage.propTypes = {
Expand All @@ -306,8 +313,9 @@ ProfilePage.propTypes = {
externalLinks: PT.arrayOf(PT.shape()),
info: PT.shape().isRequired,
skills: PT.shape(),
stats: PT.shape(),
stats: PT.arrayOf(PT.shape()),
lookupData: PT.shape().isRequired,
meta: PT.shape(),
};

export default ProfilePage;
16 changes: 11 additions & 5 deletions src/shared/containers/Profile.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* Connects the Redux store to the Profile display components.
*/
import _ from 'lodash';
import React from 'react';
import PT from 'prop-types';
import { connect } from 'react-redux';
Expand All @@ -15,20 +16,22 @@ class ProfileContainer extends React.Component {
const {
handleParam,
loadProfile,
meta,
} = this.props;

loadProfile(handleParam);
loadProfile(handleParam, _.join(_.get(meta, 'groupIds', [])));
}

componentWillReceiveProps(nextProps) {
const {
handleParam,
profileForHandle,
loadProfile,
meta,
} = nextProps;

if (handleParam !== profileForHandle) {
loadProfile(handleParam);
loadProfile(handleParam, _.join(_.get(meta, 'groupIds', [])));
}
}

Expand Down Expand Up @@ -75,6 +78,7 @@ ProfileContainer.defaultProps = {
profileForHandle: '',
skills: null,
stats: null,
meta: null,
};

ProfileContainer.propTypes = {
Expand All @@ -89,8 +93,9 @@ ProfileContainer.propTypes = {
loadProfile: PT.func.isRequired,
profileForHandle: PT.string,
skills: PT.shape(),
stats: PT.shape(),
stats: PT.arrayOf(PT.shape()),
lookupData: PT.shape().isRequired,
meta: PT.shape(),
};

const mapStateToProps = (state, ownProps) => ({
Expand All @@ -100,6 +105,7 @@ const mapStateToProps = (state, ownProps) => ({
externalAccounts: state.profile.externalAccounts,
externalLinks: state.profile.externalLinks,
handleParam: ownProps.match.params.handle,
meta: ownProps.meta,
info: state.profile.info,
loadingError: state.profile.loadingError,
profileForHandle: state.profile.profileForHandle,
Expand All @@ -112,7 +118,7 @@ function mapDispatchToProps(dispatch) {
const a = actions.profile;
const lookupActions = actions.lookup;
return {
loadProfile: (handle) => {
loadProfile: (handle, groupIds) => {
dispatch(a.clearProfile());
dispatch(a.loadProfile(handle));
dispatch(a.getAchievementsInit());
Expand All @@ -127,7 +133,7 @@ function mapDispatchToProps(dispatch) {
dispatch(a.getExternalLinksDone(handle));
dispatch(a.getInfoDone(handle));
dispatch(a.getSkillsDone(handle));
dispatch(a.getStatsDone(handle));
dispatch(a.getStatsDone(handle, groupIds));
dispatch(lookupActions.getCountriesDone());
},
};
Expand Down
26 changes: 18 additions & 8 deletions src/shared/containers/ProfileStats.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ class ProfileStatsContainer extends React.Component {
location,
loadStats,
loadStatsHistoryAndDistribution,
meta,
} = this.props;

const trackAndSubTrack = getQueryParamsQuery(location);
loadStats(handleParam);
loadStats(handleParam, _.join(_.get(meta, 'groupIds', [])));
if (shouldShowGraph(trackAndSubTrack)) {
loadStatsHistoryAndDistribution(
handleParam,
_.join(_.get(meta, 'groupIds', [])),
trackAndSubTrack.track,
trackAndSubTrack.subTrack,
);
Expand All @@ -41,6 +44,7 @@ class ProfileStatsContainer extends React.Component {
location: nextLocation,
loadStats,
loadStatsHistoryAndDistribution,
meta,
} = nextProps;
const {
handleParam,
Expand All @@ -51,7 +55,7 @@ class ProfileStatsContainer extends React.Component {
const trackAndSubTrack = getQueryParamsQuery(location);

if (nextHandleParam !== handleParam) {
loadStats(nextHandleParam);
loadStats(nextHandleParam, _.join(_.get(meta, 'groupIds', [])));
if (
nextQueryParams.track !== trackAndSubTrack.track
|| nextQueryParams.subTrack !== trackAndSubTrack.subTrack
Expand All @@ -60,6 +64,7 @@ class ProfileStatsContainer extends React.Component {
&& !nextQueryParams.tab) {
loadStatsHistoryAndDistribution(
nextHandleParam,
_.join(_.get(meta, 'groupIds', [])),
nextQueryParams.track,
nextQueryParams.subTrack,
);
Expand All @@ -73,6 +78,7 @@ class ProfileStatsContainer extends React.Component {
loadingError,
location,
isLoading,
meta,
} = this.props;

const { track, subTrack, tab } = getQueryParamsQuery(location);
Expand All @@ -88,6 +94,7 @@ class ProfileStatsContainer extends React.Component {
track={track}
subTrack={subTrack}
tab={tab}
meta={meta}
/>
);
}
Expand All @@ -100,6 +107,7 @@ ProfileStatsContainer.defaultProps = {
stats: null,
info: null,
achievements: null,
meta: null,
};

ProfileStatsContainer.propTypes = {
Expand All @@ -110,10 +118,11 @@ ProfileStatsContainer.propTypes = {
handleParam: PT.string.isRequired,
statsHistory: PT.shape(),
statsDistribution: PT.shape(),
stats: PT.shape(),
stats: PT.arrayOf(PT.shape()),
info: PT.shape(),
achievements: PT.arrayOf(PT.shape()),
isLoading: PT.bool.isRequired,
meta: PT.shape(),
};

const mapStateToProps = (state, ownProps) => {
Expand All @@ -131,6 +140,7 @@ const mapStateToProps = (state, ownProps) => {
statsDistribution: _.get(obj, 'statsDistribution.data'),
activeChallengesCount: _.get(obj, 'activeChallengesCount'),
info: state.profile.info,
meta: ownProps.meta,
achievements: state.profile.achievements,
});
};
Expand All @@ -140,17 +150,17 @@ function mapDispatchToProps(dispatch) {
const pa = actions.profile;

return {
loadStats: (handle) => {
loadStats: (handle, groupIds) => {
dispatch(a.getStatsInit(handle));
dispatch(a.getStatsDone(handle));
dispatch(a.getStatsDone(handle, groupIds));
dispatch(pa.getInfoInit(handle));
dispatch(pa.getInfoDone(handle));
dispatch(a.getActiveChallengesInit(handle));
dispatch(a.getActiveChallengesDone(handle));
},
loadStatsHistoryAndDistribution: (handle, track, subTrack) => {
dispatch(a.getStatsHistoryInit(handle));
dispatch(a.getStatsHistoryDone(handle));
loadStatsHistoryAndDistribution: (handle, groupIds, track, subTrack) => {
dispatch(a.getStatsHistoryInit(handle, groupIds));
dispatch(a.getStatsHistoryDone(handle, groupIds));
dispatch(a.getStatsDistributionInit(handle));
dispatch(a.getStatsDistributionDone(handle, track, subTrack));
},
Expand Down
Loading