Skip to content

Commit

Permalink
fix: Filter project in My actions tab (#1141)
Browse files Browse the repository at this point in the history
fix: Filter project in My actions tab
  • Loading branch information
DanielBohme authored Sep 6, 2024
1 parent 9b54c3f commit b091329
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 28 deletions.
7 changes: 3 additions & 4 deletions frontend/src/components/ActionTable/ActionTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,10 @@ interface Props {
personDetailsList: PersonDetails[]
onClickAction: (actionId: string) => void
showEvaluations?: boolean
projects?: Context[]
}

const ActionTable = ({ onClickAction, actionsWithAdditionalInfo, personDetailsList, showEvaluations = false, projects }: Props) => {
const {currentProject} = useAppContext()
const ActionTable = ({ onClickAction, actionsWithAdditionalInfo, personDetailsList, showEvaluations = false }: Props) => {
const {currentProject, projects} = useAppContext()

const columns = columnOptions.filter(
col =>
Expand Down Expand Up @@ -120,7 +119,7 @@ const ActionTable = ({ onClickAction, actionsWithAdditionalInfo, personDetailsLi
>
{action.title}
</Cell>
{!currentProject && <Cell>{getFusionProjectName(projects, action.question.evaluation.project.fusionProjectId)}</Cell>}
{!currentProject && <Cell>{getFusionProjectName(projects, action.question.evaluation.project.externalId)}</Cell>}
{showEvaluations && <Cell>{action.question.evaluation.name}</Cell>}
<Cell>{barrierToString(barrier)}</Cell>
<Cell>{organizationToString(organization)}</Cell>
Expand Down
9 changes: 4 additions & 5 deletions frontend/src/utils/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Context } from '@equinor/fusion'
import { Question, Progression, Role, Severity, Participant, Evaluation } from '../api/models'
import { Question, Progression, Role, Severity, Participant, Evaluation, Project } from '../api/models'
import { UserRolesInEvaluation } from './helperModels'
import { SeverityCount } from './Severity'
import jwtDecode from 'jwt-decode'
Expand Down Expand Up @@ -61,9 +60,9 @@ export const selectSeverity = (severityCount: SeverityCount) => {
return Severity.Na
}

export const getFusionProjectName = (projects: Context[] | undefined, fusionProjectId: string) => {
if (!fusionProjectId || !projects) { return undefined }
const fusionProject = projects?.find(project => project.id === fusionProjectId)
export const getFusionProjectName = (projects: Project[] | undefined, externalId: string) => {
if (!externalId || !projects) { return undefined }
const fusionProject = projects?.find(project => project.externalId === externalId)
return fusionProject?.title
}

Expand Down
24 changes: 6 additions & 18 deletions frontend/src/views/Project/Actions/ActionsView.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useState, useEffect } from 'react'
import { useState } from 'react'
import { ApolloError, gql, useQuery } from '@apollo/client'
import { Box } from '@mui/material'
import { Context } from '@equinor/fusion'
import ErrorMessage from '../../../components/ErrorMessage'

import { useAllPersonDetailsAsync } from '../../../utils/hooks'
Expand All @@ -18,14 +17,14 @@ import {
import { CircularProgress } from '@equinor/eds-core-react'
import { centered } from '../../../utils/styles'
import { genericErrorMessage } from '../../../utils/Variables'
import { useContextApi } from '../../../api/useContextApi'
import { useModuleCurrentContext } from '@equinor/fusion-framework-react-module-context'

interface Props {
azureUniqueId: string
}

const ActionsView = ({ azureUniqueId }: Props) => {
const apiClients = useContextApi()
const { currentContext } = useModuleCurrentContext()

const { loading: loadingActions, actions, error: errorLoadingActions } = useActionsQuery(azureUniqueId)
const nonCancelledActions = actions.filter(a => !a.isVoided)
Expand All @@ -34,24 +33,14 @@ const ActionsView = ({ azureUniqueId }: Props) => {
})

const { personDetailsList } = useAllPersonDetailsAsync([azureUniqueId])
const [projects, setProjects] = useState<Context[]>([])
const [isFetchingProjects, setIsFetchingProjects] = useState<boolean>(false)
const [isEditSidebarOpen, setIsEditSidebarOpen] = useState<boolean>(false)
const [actionIdToEdit, setActionIdToEdit] = useState<string>('')
const actionToEdit = actionsWithAdditionalInfo.find(actionWithInfo => actionWithInfo.action.id === actionIdToEdit)
const currentProjectActions = actionsWithAdditionalInfo.filter(actionWithInfo => actionWithInfo.action.question.evaluation.project.externalId === currentContext?.externalId)

const isFetchingData = loadingActions || isFetchingProjects

// useEffect(() => {
// if (projects.length === 0) {
// setIsFetchingProjects(true)
// apiClients.context.getContextsAsync().then(projects => {
// setProjects(projects.data)
// setIsFetchingProjects(false)
// })
// }
// }, [])

const onClose = () => {
setIsEditSidebarOpen(false)
setActionIdToEdit('')
Expand All @@ -74,11 +63,10 @@ const ActionsView = ({ azureUniqueId }: Props) => {
)}
{!isFetchingData && errorLoadingActions === undefined && actionsWithAdditionalInfo.length > 0 && (
<ActionTable
actionsWithAdditionalInfo={actionsWithAdditionalInfo}
actionsWithAdditionalInfo={currentContext?.externalId ? currentProjectActions : actionsWithAdditionalInfo}
personDetailsList={personDetailsList}
onClickAction={openEditActionPanel}
showEvaluations={true}
projects={projects}
/>
)}
{actionIdToEdit !== '' && actionToEdit !== undefined && (
Expand Down Expand Up @@ -120,7 +108,7 @@ const useActionsQuery = (currentUserId: string): ActionsQueryProps => {
name
...ParticipantsArray
project {
fusionProjectId
externalId
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/Project/ProjectTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const ProjectTabs = ({ match }: RouteComponentProps<Params>) => {
<Grid item>
<List>
<Tab>Evaluations</Tab>
{!currentContext ? <Tab>My actions</Tab> : <></>}
<Tab>My actions</Tab>
{isAdmin && !currentContext ? <Tab>Questionnaire editor</Tab> : <></>}
</List>
</Grid>
Expand Down

0 comments on commit b091329

Please sign in to comment.