Skip to content

Commit

Permalink
fix project metrics on finished challenges
Browse files Browse the repository at this point in the history
  • Loading branch information
CollinBeczak committed Jan 8, 2024
1 parent 0ab7543 commit 5416b59
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import _clone from 'lodash/clone'
import _findIndex from 'lodash/findIndex'
import _isEmpty from 'lodash/isEmpty'
import _omit from 'lodash/omit'
import _find from 'lodash/find'
import { Link } from 'react-router-dom'
import { FormattedMessage, injectIntl } from 'react-intl'
import { boundsWithinAllowedMaxDegrees }
Expand All @@ -19,6 +20,8 @@ import WithFeatured from '../../HOCs/WithFeatured/WithFeatured'
import ChallengeResultItem from '../ChallengeResultItem/ChallengeResultItem'
import ProjectResultItem from '../ProjectResultItem/ProjectResultItem'
import PageResultsButton from './PageResultsButton'
import { isUsableChallengeStatus }
from '../../../services/Challenge/ChallengeStatus/ChallengeStatus'
import messages from './Messages'
import './ChallengeResultList.scss'

Expand Down Expand Up @@ -101,13 +104,21 @@ export class ChallengeResultList extends Component {
const query = search.query ? search.query : this.props.searchFilters.project ? this.props.searchFilters.project : this.props.searchFilters.task

const challengeResultsUnbound = _clone(this.props.pagedChallenges);
const challengeResults = this.props.location?.pathname?.includes("browse/challenges")
const allChallenges = this.props.location?.pathname?.includes("browse/challenges")
&& (this.props.searchSort?.sortBy === "created"
|| _isEmpty(this.props.searchSort)
|| this.props.location.search.includes("default"))
? limitUserResults(challengeResultsUnbound)
: challengeResultsUnbound;

? limitUserResults(challengeResultsUnbound)
: challengeResultsUnbound;

const challengeResults = this.props.project?.id ? _filter(allChallenges, (challenge) => {
return (isUsableChallengeStatus(challenge.status))
}) : allChallenges

const finishedChallengeResults = this.props.project?.id ? _filter(allChallenges, (challenge) => {
return (!isUsableChallengeStatus(challenge.status))
}) : []

const uniqueParents = new Set();

const projectResults = this.props.challenges?.reduce((result, challenge) => {
Expand Down Expand Up @@ -271,7 +282,7 @@ export class ChallengeResultList extends Component {
}

let results = null
if (challengeResults.length === 0) {
if (challengeResults.length === 0 && finishedChallengeResults.length == 0) {
if (!isFetching) {
results = (
<div className="mr-text-white mr-text-lg mr-pt-4">
Expand All @@ -296,6 +307,32 @@ export class ChallengeResultList extends Component {
);
}
}))
if(finishedChallengeResults?.length > 0){
results.push(
<div className="mr-text-sm mr-text-yellow mr-uppercase mr-mb-4">
<FormattedMessage
{...messages.completedChallengeCount}
values={{
count: finishedChallengeResults.length,
}}
/>
</div>,
..._compact(_map(finishedChallengeResults, (result) => {
if (result.parent) {
return (
<ChallengeResultItem
key={`challenge_${result.id}`}
{...this.props}
className="mr-mb-4"
challenge={result}
listRef={this.listRef}
sort={search?.sort}
/>
)
}
}))
)
}
} else if (!this.props.excludeProjectResults && searchType === "projects" && projectResults) {
results = _compact(_map(projectResults, (result) => {
return (
Expand Down
7 changes: 7 additions & 0 deletions src/components/ChallengePane/ChallengeResultList/Messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ export default defineMessages({
defaultMessage: "Challenge ",
},

completedChallengeCount: {
id: "Challenge.fields.ChallengeResultList.label",
defaultMessage:
"{count,plural,=0{No challenges} one{# challenge} other{# challenges}} " +
"completed in project"
},

project: {
id: "Challenge.detectedIds.project",
defaultMessage: "Project ",
Expand Down
5 changes: 1 addition & 4 deletions src/components/HOCs/WithProject/WithProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import _isObject from 'lodash/isObject'
import _values from 'lodash/values'
import _filter from 'lodash/filter'
import _find from 'lodash/find'
import { isUsableChallengeStatus }
from '../../../services/Challenge/ChallengeStatus/ChallengeStatus'
import { fetchProject } from '../../../services/Project/Project'
import { fetchProjectChallenges,
fetchProjectChallengeActions }
Expand Down Expand Up @@ -42,8 +40,7 @@ const WithProject = function(WrappedComponent, options={}) {
})

return ((challenge.parent === projectId || matchingVP)
&& challenge.enabled
&& isUsableChallengeStatus(challenge.status))
&& challenge.enabled)
})
}

Expand Down
8 changes: 7 additions & 1 deletion src/components/ProjectDetail/ProjectDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { FormattedMessage, FormattedDate, injectIntl }
from 'react-intl'
import _isObject from 'lodash/isObject'
import _get from 'lodash/get'
import _find from 'lodash/find'
import _filter from 'lodash/filter'
import parse from 'date-fns/parse'
import messages from './Messages'
import BusySpinner from '../BusySpinner/BusySpinner'
Expand All @@ -18,6 +20,7 @@ import WithCurrentUser from '../HOCs/WithCurrentUser/WithCurrentUser'
import WithComputedMetrics from '../AdminPane/HOCs/WithComputedMetrics/WithComputedMetrics'
import ChallengeResultList from '../ChallengePane/ChallengeResultList/ChallengeResultList'
import { PROJECT_CHALLENGE_LIMIT } from '../../services/Project/Project'
import { isUsableChallengeStatus } from '../../services/Challenge/ChallengeStatus/ChallengeStatus'

const ProjectProgress = WithComputedMetrics(ChallengeProgress)

Expand All @@ -37,6 +40,9 @@ export class ProjectDetail extends Component {
</div>
)
}
const challengeResults = _filter(this.props.challenges, (challenge) => {
return (isUsableChallengeStatus(challenge.status))
})

// Does this user own (or can manage) the current project?
const isManageable = AsManager(this.props.user).canManage(project)
Expand All @@ -58,7 +64,7 @@ export class ProjectDetail extends Component {
<FormattedMessage
{...messages.challengeCount}
values={{
count:_get(this.props, 'challenges.length', 0),
count: challengeResults.length,
isVirtual: this.props.project.isVirtual
}}
/>
Expand Down

0 comments on commit 5416b59

Please sign in to comment.