Skip to content

Commit

Permalink
Allow everyone to view all evaluations
Browse files Browse the repository at this point in the history
  • Loading branch information
maiaht committed Sep 8, 2021
1 parent 858b84e commit 5c137bc
Show file tree
Hide file tree
Showing 20 changed files with 346 additions and 227 deletions.
9 changes: 8 additions & 1 deletion frontend/src/components/Action/EditForm/ActionEditForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface Props {
isClosingRemarkSaved: boolean
apiErrorClosingRemark: string
apiErrorAction: string
disableEditAction: boolean
}

const ActionEditForm = ({
Expand All @@ -41,6 +42,7 @@ const ActionEditForm = ({
createClosingRemark,
apiErrorClosingRemark,
apiErrorAction,
disableEditAction,
}: Props) => {
const [title, setTitle] = useState<string>((action && action.title) || '')
const [titleValidity, setTitleValidity] = useState<Validity>('default')
Expand All @@ -60,6 +62,7 @@ const ActionEditForm = ({
title: personDetails.name,
key: personDetails.azureUniqueId,
isSelected: personDetails.azureUniqueId === assignedToId,
isDisabled: disableEditAction
}))

const createdDateString = new Date(action.createDate).toLocaleDateString()
Expand Down Expand Up @@ -177,6 +180,7 @@ const ActionEditForm = ({
variant={titleValidity}
helperText={titleValidity === 'error' ? 'required' : ''}
helperIcon={titleValidity === 'error' ? ErrorIcon : <></>}
disabled={disableEditAction}
/>
</Grid>
<Grid item xs={5}>
Expand All @@ -193,6 +197,7 @@ const ActionEditForm = ({
label="Due date"
onChange={newDate => setDueDate(newDate !== null ? newDate : new Date())}
selectedDate={dueDate}
disabled={disableEditAction}
/>
</Grid>
<Grid item xs={3}>
Expand Down Expand Up @@ -220,6 +225,7 @@ const ActionEditForm = ({
onSelect={option => {
setPriority(option.key as Priority)
}}
disabled={disableEditAction}
/>
</Grid>
<Grid item xs={12}>
Expand All @@ -239,6 +245,7 @@ const ActionEditForm = ({
}}
variant="default"
style={{ height: 150 }}
disabled={disableEditAction}
/>
</Grid>
{!completed && (
Expand All @@ -249,7 +256,7 @@ const ActionEditForm = ({
setCompleteActionViewOpen(true)
setCompletingReason('')
}}
disabled={completeActionViewOpen}
disabled={completeActionViewOpen || disableEditAction}
data-testid="complete_action_button"
>
Complete action
Expand Down
12 changes: 11 additions & 1 deletion frontend/src/components/Action/EditForm/ActionEditSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { SavingState } from '../../../utils/Variables'
import { useAllPersonDetailsAsync, useEffectNotOnMount } from '../../../utils/hooks'
import NotesAndClosingRemarksList from './NotesAndClosingRemarksList'
import NoteCreateForm from './NoteCreateForm'
import { useParticipant } from '../../../globals/contexts'
import { participantCanEditAction } from '../../../utils/RoleBasedAccess'

const WRITE_DELAY_MS = 1000

Expand Down Expand Up @@ -57,6 +59,8 @@ const ActionEditSidebar = ({
const [delayedAction, setDelayedAction] = useState<Action | undefined>(undefined)
const notesAndClosingRemarks: (Note | ClosingRemark)[] = action.notes.map(note => note)

const participant = useParticipant()

if (action.closingRemarks !== undefined) {
action.closingRemarks.forEach(closingRemark => {
notesAndClosingRemarks.push(closingRemark)
Expand Down Expand Up @@ -138,6 +142,7 @@ const ActionEditSidebar = ({
isClosingRemarkSaved={isClosingRemarkSaved}
apiErrorClosingRemark={apiErrorClosingRemark}
apiErrorAction={apiErrorAction}
disableEditAction={!participantCanEditAction(participant)}
/>
{apiErrorAction && (
<div style={{ marginTop: 20 }}>
Expand All @@ -149,7 +154,12 @@ const ActionEditSidebar = ({
<TextArea value={apiErrorNote} onChange={() => {}} />
</div>
)}
<NoteCreateForm text={note} onChange={onChangeNote} onCreateClick={onCreateNote} disabled={isNoteSaving} />
<NoteCreateForm
text={note}
onChange={onChangeNote}
onCreateClick={onCreateNote}
disabled={isNoteSaving || !participantCanEditAction(participant)}
/>
<NotesAndClosingRemarksList notesAndClosingRemarks={notesAndClosingRemarks} participantsDetails={personDetailsList} />
</div>
)}
Expand Down
11 changes: 7 additions & 4 deletions frontend/src/components/Action/QuestionActionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import PriorityIndicator from './PriorityIndicator'
import ActionEditSidebarWithApi from './EditForm/ActionEditSidebarWithApi'
import ActionCreateSidebarWithApi from './CreateForm/ActionCreateSidebarWithApi'
import ConfirmationDialog from './../ConfirmationDialog'
import { useParticipant } from '../../globals/contexts'
import { participantCanCreateAction, participantCanDeleteAction } from '../../utils/RoleBasedAccess'

interface Props {
question: Question
Expand All @@ -26,6 +28,7 @@ const QuestionActionsList = ({ question, participants, deleteAction, errorDeleti
const [actionIdToEdit, setActionIdToEdit] = useState<string | undefined>()
const [actionToDelete, setActionToDelete] = useState<string | undefined>()
const actions = [...question.actions]
const participant = useParticipant()

const openActionEditSidebar = (action: Action) => {
setIsEditSidebarOpen(true)
Expand All @@ -47,12 +50,12 @@ const QuestionActionsList = ({ question, participants, deleteAction, errorDeleti
Actions
</Typography>
</Box>
<Box>
{participantCanCreateAction(participant) && <Box>
<Button variant="ghost" onClick={() => setIsCreateSidebarOpen(true)}>
<Icon data={add}></Icon>
Add action
</Button>
</Box>
</Box>}
</Box>
{actions
.sort((a1, a2) => {
Expand Down Expand Up @@ -90,15 +93,15 @@ const QuestionActionsList = ({ question, participants, deleteAction, errorDeleti
</Box>
)}
</Box>
<IconButton
{participantCanDeleteAction(participant) && <IconButton
data-testid={`delete_action_button_${action.id}`}
onClick={() => {
setIsConfirmDeleteDialogOpen(true)
setActionToDelete(action.id)
}}
>
<DeleteIcon />
</IconButton>
</IconButton>}
</Box>
</div>
)
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/QuestionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ interface Props {


const QuestionItem = ({ question, viewProgression, disable, displayActions = false, onQuestionSummarySelected }: Props) => {
const { azureUniqueId } = useParticipant()
const participant = useParticipant()

const useSharedAnswer = useSharedFacilitatorAnswer(viewProgression)
const answer = findCorrectAnswer(
question,
viewProgression,
useSharedAnswer,
azureUniqueId
participant
)

return (
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/QuestionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ type Props = {
}

const QuestionsList = ({ questions, viewProgression, disable, displayActions, onQuestionSummarySelected, severityFilter, organizationFilter }: Props) => {
const { azureUniqueId: currentUserAzureUniqueId } = useParticipant()
const participant = useParticipant()

const severityFilteredQuestions = severityFilter !== undefined
? questions.filter(q =>
hasSeverity(
q,
severityFilter,
currentUserAzureUniqueId,
participant,
viewProgression
)
)
Expand Down
9 changes: 6 additions & 3 deletions frontend/src/components/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { Context } from '@equinor/fusion'
import { Question, Progression, Role, Severity } from '../api/models'
import { Question, Progression, Role, Severity, Participant } from '../api/models'
import { SeverityCount } from '../utils/Severity'

export const findCorrectAnswer = (question: Question, viewProgression: Progression, useFacilitatorAnswer: boolean, userId: string) => {
export const findCorrectAnswer = (question: Question, viewProgression: Progression, useFacilitatorAnswer: boolean, participant: Participant | undefined) => {
const answers = question.answers.filter(a => a.progression === viewProgression)
if (!participant) {
return undefined
}

if (useFacilitatorAnswer) {
return answers.find(a => a.answeredBy?.role === Role.Facilitator)
} else {
return answers.find(a => a.answeredBy?.azureUniqueId === userId)
return answers.find(a => a.answeredBy?.azureUniqueId === participant.azureUniqueId)
}
}

Expand Down
5 changes: 1 addition & 4 deletions frontend/src/globals/contexts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ export const CurrentParticipantContext = createContext<Participant | undefined>(
export const EvaluationContext = createContext<Evaluation | undefined>(undefined)
export const ProjectContext = createContext<Project | undefined>(undefined)

export const useParticipant = (): Participant => {
export const useParticipant = (): Participant | undefined => {
const participant = useContext(CurrentParticipantContext)
if (participant === undefined) {
throw new Error(`You might not be a participant on this evaluation. No participant provided for context. `)
}
return participant
}

Expand Down
6 changes: 3 additions & 3 deletions frontend/src/utils/QuestionAndAnswerUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Answer, Organization, Progression, Question, Severity } from '../api/models'
import { Answer, Organization, Participant, Progression, Question, Severity } from '../api/models'
import { findCorrectAnswer, useSharedFacilitatorAnswer } from '../components/helpers'

export const checkIfAnswerFilled = (answer: Answer): boolean => {
Expand All @@ -16,12 +16,12 @@ export const getFilledUserAnswersForProgression = (questions: Question[], progre
return participantAnswers.filter(a => checkIfAnswerFilled(a))
}

export const hasSeverity = (question: Question, severityFilter: Severity[], AzureUniqueId: string, viewProgression: Progression) => {
export const hasSeverity = (question: Question, severityFilter: Severity[], participant: Participant | undefined, viewProgression: Progression) => {
if (severityFilter.length === 0) {
return true
} else {
const useSharedAnswer = useSharedFacilitatorAnswer(viewProgression)
const answer = findCorrectAnswer(question, viewProgression, useSharedAnswer, AzureUniqueId)
const answer = findCorrectAnswer(question, viewProgression, useSharedAnswer, participant)
const severity = (answer && answer.severity) || Severity.Na
return severityFilter.includes(severity)
}
Expand Down
Loading

0 comments on commit 5c137bc

Please sign in to comment.