Skip to content
Open
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
15 changes: 11 additions & 4 deletions src/components/ChallengesComponent/ChallengeCard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class ChallengeCard extends React.Component {
this.deleteModalLaunch = this.deleteModalLaunch.bind(this)
this.resetModal = this.resetModal.bind(this)
this.onLaunchChallenge = this.onLaunchChallenge.bind(this)
this.openChallengeView = this.openChallengeView.bind(this)
}

getForumLink (challenge) {
Expand Down Expand Up @@ -204,9 +205,14 @@ class ChallengeCard extends React.Component {
}
}

openChallengeView (challenge) {
this.props.setActiveProject(parseInt(challenge.projectId))

Choose a reason for hiding this comment

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

The openChallengeView method should be bound to this in the constructor if it is intended to be used as an event handler or passed around as a callback. This ensures the correct this context is maintained.

Choose a reason for hiding this comment

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

Consider adding error handling for the parseInt(challenge.projectId) call to ensure that challenge.projectId is a valid number and handle cases where it might not be.

this.props.resetFilter()
}

render () {
const { isLaunch, isConfirm, isSaving, isDeleteLaunch, isCheckChalengePermission, hasEditChallengePermission, currentPhase, forumLink } = this.state
const { setActiveProject, challenge, reloadChallengeList, isBillingAccountExpired, disableHover, getStatusText, challengeTypes, loginUserRoleInProject } = this.props
const { challenge, reloadChallengeList, isBillingAccountExpired, disableHover, getStatusText, challengeTypes, loginUserRoleInProject } = this.props
const deleteMessage = isCheckChalengePermission
? 'Checking permissions...'
: `Do you want to delete "${challenge.name}"?`
Expand Down Expand Up @@ -265,7 +271,7 @@ class ChallengeCard extends React.Component {
/>
</div>

<Link className={styles.col2} to={`/projects/${challenge.projectId}/challenges/${challenge.id}/view`} onClick={() => setActiveProject(parseInt(challenge.projectId))}>
<Link className={styles.col2} to={`/projects/${challenge.projectId}/challenges/${challenge.id}/view`} onClick={() => this.openChallengeView(challenge)}>

Choose a reason for hiding this comment

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

The function openChallengeView is being called with challenge as an argument. Ensure that openChallengeView is defined and handles the challenge parameter correctly. If openChallengeView is not defined within this component, it should be imported or defined appropriately.

<div className={styles.name}>
<span className={styles.link}>{challenge.name}</span>
</div>
Expand All @@ -291,7 +297,7 @@ class ChallengeCard extends React.Component {
{
!isReadOnly && (
<div className={styles.col6}>
{(disableHover ? <Link className={styles.link} to={`/projects/${challenge.projectId}/challenges/${challenge.id}/edit`}>Edit</Link> : hoverComponents(challenge, this.onUpdateLaunch, this.deleteModalLaunch))}
{(disableHover ? <Link className={styles.link} to={`/projects/${challenge.projectId}/challenges/${challenge.id}/edit`} onClick={() => this.props.resetFilter()}>Edit</Link> : hoverComponents(challenge, this.onUpdateLaunch, this.deleteModalLaunch))}

Choose a reason for hiding this comment

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

Consider checking if this.props.resetFilter is defined before calling it to prevent potential runtime errors if the prop is not passed correctly. For example: onClick={() => this.props.resetFilter && this.props.resetFilter()}.

</div>
)
}
Expand Down Expand Up @@ -328,7 +334,8 @@ ChallengeCard.propTypes = {
getStatusText: PropTypes.func,
challengeTypes: PropTypes.arrayOf(PropTypes.shape()),
auth: PropTypes.object.isRequired,
loginUserRoleInProject: PropTypes.string
loginUserRoleInProject: PropTypes.string,
resetFilter: PropTypes.func

Choose a reason for hiding this comment

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

The resetFilter prop type should be more specific. Consider defining the expected shape or type for this function using PropTypes.func.isRequired if it is mandatory, or PropTypes.func if it is optional.

}

export default withRouter(ChallengeCard)
1 change: 1 addition & 0 deletions src/components/ChallengesComponent/ChallengeList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,7 @@ class ChallengeList extends Component {
challengeTypes={challengeTypes}
loginUserRoleInProject={loginUserRoleInProject}
auth={this.props.auth}
resetFilter={this.resetFilter}
/>
</li>
)
Expand Down