Skip to content

Commit

Permalink
fix: Allow setting finished evaluations as indicator (#1116)
Browse files Browse the repository at this point in the history
Remove indicator activity for finished evaluations
  • Loading branch information
taustad committed Apr 19, 2024
1 parent 1d3c28b commit 82db610
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions backend/api/GQL/Mutation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ public Project SetIndicatorEvaluation(string projectId, string evaluationId)
{
Evaluation evaluation = _evaluationService.GetEvaluation(evaluationId);

if (evaluation.Progression != Progression.FollowUp)
if (evaluation.Progression != Progression.FollowUp && evaluation.Progression != Progression.Finished)
{
string msg = "Evaluation must be in FollowUp progression to set as active indicator for project";
string msg = "Evaluation must be in FollowUp or Finished progression to set as active indicator for project";
throw new InvalidOperationException(msg);
}

Expand Down
10 changes: 5 additions & 5 deletions frontend/src/components/EvaluationScoreIndicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ const Circle = styled.div<{ color: string }>`
const EvaluationScoreIndicator: React.FC<EvaluationScoreIndicatorProps> = ({ date }) => {
const [diffInMonths, setDiffInMonths] = React.useState<number>(0)

if (!date) {
return null
}

React.useEffect(() => {
const currentDate = new Date()
const evaluationDate = new Date(date)
Expand Down Expand Up @@ -47,6 +43,10 @@ const EvaluationScoreIndicator: React.FC<EvaluationScoreIndicatorProps> = ({ dat
}
}

if (!date) {
return null
}

return (
<Tooltip placement='right' title={getTooltipText()}>
<Circle color={getColor()} />
Expand All @@ -55,4 +55,4 @@ const EvaluationScoreIndicator: React.FC<EvaluationScoreIndicatorProps> = ({ dat

};

export default EvaluationScoreIndicator
export default EvaluationScoreIndicator
10 changes: 5 additions & 5 deletions frontend/src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const canSetEvaluationAsIndicator = (evaluation: Evaluation, userRoles: U
const userRole = userRoles.find(role => role.evaluationId === evaluation.id)?.role
const isFacilitator = userRole === Role.Facilitator
const evaluationIsNotActive = evaluation.project.indicatorEvaluationId !== evaluation.id
const evaluationIsNotInFollowUp = evaluation.progression === Progression.FollowUp
const evaluationIsNotInFollowUpOrFinished = evaluation.progression === Progression.FollowUp || evaluation.progression === Progression.Finished

let reasonsForNotBeingAbleToSelect = []

Expand All @@ -107,15 +107,15 @@ export const canSetEvaluationAsIndicator = (evaluation: Evaluation, userRoles: U
if (!evaluationIsNotActive) {
reasonsForNotBeingAbleToSelect.push("this evaluation is already active")
}
if (!evaluationIsNotInFollowUp) {
reasonsForNotBeingAbleToSelect.push("this evaluation is not in follow-up")
if (!evaluationIsNotInFollowUpOrFinished) {
reasonsForNotBeingAbleToSelect.push("this evaluation is not in follow-up or finished stage")
}

const toolTipMessage = reasonsForNotBeingAbleToSelect.length > 0
? reasonsForNotBeingAbleToSelect.join(" & ")
: "Set as active evaluation"

const canUserSetAsIndicator = (isFacilitator || userIsAdmin) && evaluationIsNotInFollowUp && evaluationIsNotActive
const canUserSetAsIndicator = (isFacilitator || userIsAdmin) && evaluationIsNotInFollowUpOrFinished && evaluationIsNotActive

return { "canSetAsIndicator": canUserSetAsIndicator, "toolTipMessage": toolTipMessage }
}
}
20 changes: 10 additions & 10 deletions frontend/src/views/Project/Dashboard/Components/TablesAndTitles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import FollowUpIndicator from '../../../../components/FollowUpIndicator'
import { noProjectMasterTitle } from '../../../../utils/hooks'
import styled from 'styled-components'
import { ApolloQueryResult } from '@apollo/client'
import { Evaluation } from '../../../../api/models'
import { Evaluation, Progression } from '../../../../api/models'
import React from 'react'
import { ProjectBMTScore, ProjectIndicator } from '../../../../utils/helperModels'

Expand Down Expand Up @@ -45,20 +45,20 @@ const TablesAndTitles = ({
let activityDate = ""
let projectId = ""
let followUpScore = null
Object.entries(evaluations).map((info) => {

if (info[1].projectId !== projectId) {
projectId = info[1].projectId
Object.entries(evaluations).forEach((evaluation) => {
if (evaluation[1].projectId !== projectId) {
projectId = evaluation[1].projectId
}

if (projectIndicators.findIndex(pi => pi.evaluationId === info[1].project.indicatorEvaluationId) > -1) {
if (info[1].indicatorActivityDate) {
activityDate = info[1].indicatorActivityDate
if (projectIndicators.findIndex(pi => pi.evaluationId === evaluation[1].id) > -1 && evaluation[1].project.indicatorEvaluationId === evaluation[1].id) {
if (evaluation[1].indicatorActivityDate && evaluation[1].progression === Progression.FollowUp) {
activityDate = evaluation[1].indicatorActivityDate
}
}
else if (info[1].project.indicatorEvaluationId === info[1].id) {
if (info[1].indicatorActivityDate) {
activityDate = info[1].indicatorActivityDate
else if (evaluation[1].project.indicatorEvaluationId === evaluation[1].id) {
if (evaluation[1].indicatorActivityDate && evaluation[1].progression === Progression.FollowUp) {
activityDate = evaluation[1].indicatorActivityDate
}
}
})
Expand Down

0 comments on commit 82db610

Please sign in to comment.