Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Filter project in My actions tab #1141

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
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
6 changes: 3 additions & 3 deletions frontend/src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,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: any[] | 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
Loading