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

Navigate to All projects when removing context from evaluation view #1134

Merged
merged 5 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
34 changes: 17 additions & 17 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions frontend/src/components/Header/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ const BreadCrumbs = () => {
>
All projects
</Breadcrumb>
{currentProject &&
{currentProject &&
<Breadcrumb
href={basepath + currentProject.fusionProjectId}
as={!currentEvaluation ? 'span' : 'a'}
>
{String(currentProject.title)}
</Breadcrumb>
}
{currentEvaluation &&
{currentEvaluation &&
<Breadcrumb
as="span"
>
Expand Down
90 changes: 50 additions & 40 deletions frontend/src/context/AppContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { useCurrentUser } from '@equinor/fusion-framework-react-app/framework'
import { gql, useQuery, useApolloClient } from '@apollo/client'
import { EVALUATION_DASHBOARD_FIELDS_FRAGMENT, PARTICIPANTS_ARRAY_FRAGMENT } from '../api/fragments'


interface ProjectOption {
title: string
id: string
Expand Down Expand Up @@ -76,11 +75,11 @@ const GET_EVALUATIONS = gql`
const GET_EVALUATIONS_BY_USER = gql`
query ($status: Status!, $azureUniqueId: String!) {
evaluations(
where: {
status: {
where: {
status: {
eq: $status
},
participants: {
participants: {
some: {
azureUniqueId: {
eq: $azureUniqueId
Expand All @@ -97,18 +96,11 @@ const GET_EVALUATIONS_BY_USER = gql`
${PARTICIPANTS_ARRAY_FRAGMENT}
`
const GET_EVALUATIONS_BY_USER_HIDDEN = gql`
query ($status: Status!, $azureUniqueId: String!) {
query ($status: Status!) {
evaluations(
where: {
status: {
where: {
status: {
eq: $status
},
participants: {
some: {
azureUniqueId: {
eq: $azureUniqueId
}
}
}
}
) {
Expand All @@ -123,16 +115,16 @@ const GET_EVALUATIONS_BY_USER_HIDDEN = gql`
const GET_EVALUATIONS_BY_USER_PROJECT = gql`
query ($status: Status!, $azureUniqueId: String!, $projectId: String!) {
evaluations(
where: {
status: {
where: {
status: {
eq: $status
},
project: {
externalId: {
eq: $projectId
}
}
participants: {
participants: {
some: {
azureUniqueId: {
eq: $azureUniqueId
Expand All @@ -151,16 +143,16 @@ const GET_EVALUATIONS_BY_USER_PROJECT = gql`
const GET_EVALUATIONS_BY_USER_PROJECT_HIDDEN = gql`
query ($status: Status!, $azureUniqueId: String!, $projectId: String!) {
evaluations(
where: {
status: {
eq: $status
where: {
status: {
eq: $status
},
project: {
externalId: {
eq: $projectId
}
}
participants: {
participants: {
some: {
azureUniqueId: {
eq: $azureUniqueId
Expand All @@ -180,8 +172,8 @@ const GET_EVALUATIONS_BY_USER_PROJECT_HIDDEN = gql`
const GET_EVALUATIONS_BY_PROJECT = gql`
query ($status: Status!, $projectId: String!) {
evaluations(
where: {
status: {
where: {
status: {
eq: $status
},
project: {
Expand All @@ -201,9 +193,9 @@ const GET_EVALUATIONS_BY_PROJECT = gql`
const GET_EVALUATIONS_BY_PROJECT_HIDDEN = gql`
query ($status: Status!, $projectId: String!) {
evaluations(
where: {
status: {
eq: $status
where: {
status: {
eq: $status
},
project: {
externalId: {
Expand All @@ -226,16 +218,19 @@ interface QueryProps {

const useGetAllProjects = (): QueryProps => {
const { data } = useQuery<{ projects: Project[] }>(GET_PROJECTS)
return { dbProjects: data?.projects ? data?.projects : []}
return { dbProjects: data?.projects ? data?.projects : [] }
}

const AppContextProvider: FC<{ children: ReactNode }> = ({ children }) => {
const apiClients = useContextApi()
const user = useCurrentUser()
const apolloClient = useApolloClient()

const [pageReload, setPageReload] = useState<boolean>(false)
const [contexts, setContexts] = useState<any[]>([])

const { currentContext } = useModuleCurrentContext()

const [isFetchingProjects, setIsFetchingProjects] = useState<boolean>(true)
const { dbProjects } = useGetAllProjects()
const [projects, setProjects] = useState<Project[]>([])
Expand Down Expand Up @@ -263,6 +258,18 @@ const AppContextProvider: FC<{ children: ReactNode }> = ({ children }) => {
const [evaluationsByProjectHiddenFetched, setEvaluationsByProjectHiddenFetched] = useState<boolean>(false)
const [currentEvaluation, setCurrentEvaluation] = useState<Evaluation | undefined>(undefined)

useEffect(() => {
setEvaluationsByProjectFetched(false)
setEvaluationsByProjectHiddenFetched(false)
setEvaluationsByUserProjectHiddenFetched(false)
setEvaluationsByUserProjectFetched(false)
setEvaluationsByUserHiddenFetched(false)
setEvaluationsByUserFetched(false)
setEvaluationsFetched(false)
setProjectsByUserHiddenFetched(false)
setProjectsByUserFetched(false)
}, [currentContext])

useEffect(() => {
setPageReload(currentContext !== undefined && currentContext !== null)
if ((currentContext === undefined || currentContext === null) && pageReload) {
Expand Down Expand Up @@ -292,9 +299,9 @@ const AppContextProvider: FC<{ children: ReactNode }> = ({ children }) => {
})
tempProjects = tempProjects.filter((value, index, self) =>
index === self.findIndex((t) => (
t.id === value.id || t.externalId === value.externalId || t.fusionProjectId === value.fusionProjectId
t.id === value.id || t.externalId === value.externalId || t.fusionProjectId === value.fusionProjectId
))
)
)
setProjects(tempProjects)
setIsFetchingProjects(false)
}
Expand All @@ -303,8 +310,8 @@ const AppContextProvider: FC<{ children: ReactNode }> = ({ children }) => {
projects.forEach((project: Project) => {
if (project.title && project.fusionProjectId !== '') {
tempProjectOptions.push({
title: project.title,
id: project.externalId,
title: project.title,
id: project.externalId,
})
}
})
Expand Down Expand Up @@ -342,18 +349,21 @@ const AppContextProvider: FC<{ children: ReactNode }> = ({ children }) => {
let tempProjectsByUserHidden: Project[] = []
evaluationsByUserHidden.forEach((ebu: Evaluation) => {
if (tempProjectsByUserHidden.filter((tpbu: Project) => tpbu.externalId === ebu.project.externalId).length === 0) {
tempProjectsByUserHidden.push(projects.filter((p: Project) => p.externalId === ebu.project.externalId)[0])
const temp = projects.filter((p: Project) => p.externalId === ebu.project.externalId)[0]
if (temp) {
tempProjectsByUserHidden.push(temp)
}
}
})
setProjectsByUserHidden(tempProjectsByUserHidden)
setProjectsByUserHiddenFetched(true)
setLoadingProjects(false)
}
}, [projects, evaluationsByUserHidden, evaluationsByUserHiddenFetched, projectsByUserHiddenFetched])

useEffect(() => {
if (!evaluationsFetched) {
apolloClient.query({ query: GET_EVALUATIONS}).then(data => {
apolloClient.query({ query: GET_EVALUATIONS }).then(data => {
setLoadingEvaluations(true)
if (data.data.evaluations) {
setEvaluations(data.data.evaluations)
Expand All @@ -366,7 +376,7 @@ const AppContextProvider: FC<{ children: ReactNode }> = ({ children }) => {

useEffect(() => {
if (user && !evaluationsByUserFetched) {
apolloClient.query({ query: GET_EVALUATIONS_BY_USER, variables: { status: Status.Active, azureUniqueId: user.localAccountId}}).then(data => {
apolloClient.query({ query: GET_EVALUATIONS_BY_USER, variables: { status: Status.Active, azureUniqueId: user.localAccountId } }).then(data => {
setLoadingEvaluations(true)
if (data.data.evaluations) {
setEvaluationsByUser(data.data.evaluations)
Expand All @@ -379,7 +389,7 @@ const AppContextProvider: FC<{ children: ReactNode }> = ({ children }) => {

useEffect(() => {
if (user && !evaluationsByUserHiddenFetched) {
apolloClient.query({ query: GET_EVALUATIONS_BY_USER_HIDDEN, variables: { status: Status.Voided, azureUniqueId: user.localAccountId}}).then(data => {
apolloClient.query({ query: GET_EVALUATIONS_BY_USER_HIDDEN, variables: { status: Status.Voided } }).then(data => {
setLoadingEvaluations(true)
if (data.data.evaluations) {
setEvaluationsByUserHidden(data.data.evaluations)
Expand All @@ -392,7 +402,7 @@ const AppContextProvider: FC<{ children: ReactNode }> = ({ children }) => {

useEffect(() => {
if (user && currentProject && !evaluationsByUserProjectFetched) {
apolloClient.query({ query: GET_EVALUATIONS_BY_USER_PROJECT, variables: { status: Status.Active, azureUniqueId: user.localAccountId, projectId: currentProject.externalId }}).then(data => {
apolloClient.query({ query: GET_EVALUATIONS_BY_USER_PROJECT, variables: { status: Status.Active, azureUniqueId: user.localAccountId, projectId: currentProject.externalId } }).then(data => {
setLoadingEvaluations(true)
if (data.data.evaluations) {
setEvaluationsByUserProject(data.data.evaluations)
Expand All @@ -405,7 +415,7 @@ const AppContextProvider: FC<{ children: ReactNode }> = ({ children }) => {

useEffect(() => {
if (user && currentProject && !evaluationsByUserProjectHiddenFetched) {
apolloClient.query({ query: GET_EVALUATIONS_BY_USER_PROJECT_HIDDEN, variables: { status: Status.Voided, azureUniqueId: user.localAccountId, projectId: currentProject.externalId }}).then(data => {
apolloClient.query({ query: GET_EVALUATIONS_BY_USER_PROJECT_HIDDEN, variables: { status: Status.Voided, azureUniqueId: user.localAccountId, projectId: currentProject.externalId } }).then(data => {
setLoadingEvaluations(true)
if (data.data.evaluations) {
setEvaluationsByUserProjectHidden(data.data.evaluations)
Expand All @@ -418,7 +428,7 @@ const AppContextProvider: FC<{ children: ReactNode }> = ({ children }) => {

useEffect(() => {
if (currentProject && !evaluationsByProjectFetched) {
apolloClient.query({ query: GET_EVALUATIONS_BY_PROJECT, variables: { status: Status.Active, projectId: currentProject.externalId }}).then(data => {
apolloClient.query({ query: GET_EVALUATIONS_BY_PROJECT, variables: { status: Status.Active, projectId: currentProject.externalId } }).then(data => {
setLoadingEvaluations(true)
if (data.data.evaluations) {
setEvaluationsByProject(data.data.evaluations)
Expand All @@ -431,7 +441,7 @@ const AppContextProvider: FC<{ children: ReactNode }> = ({ children }) => {

useEffect(() => {
if (currentProject && !evaluationsByProjectHiddenFetched) {
apolloClient.query({ query: GET_EVALUATIONS_BY_PROJECT_HIDDEN, variables: { status: Status.Voided, projectId: currentProject.externalId }}).then(data => {
apolloClient.query({ query: GET_EVALUATIONS_BY_PROJECT_HIDDEN, variables: { status: Status.Voided, projectId: currentProject.externalId } }).then(data => {
setLoadingEvaluations(true)
if (data.data.evaluations) {
setEvaluationsByProjectHidden(data.data.evaluations)
Expand Down
21 changes: 19 additions & 2 deletions frontend/src/views/Evaluation/EvaluationView.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState, useEffect } from 'react'
import { RouteComponentProps } from 'react-router-dom'
import { RouteComponentProps, useHistory } from 'react-router-dom'
import { ApolloError, gql, useApolloClient, useMutation, useQuery } from '@apollo/client'
import ErrorMessage from '../../components/ErrorMessage'
import { CircularProgress } from '@equinor/eds-core-react'
Expand All @@ -21,14 +21,18 @@ import {
} from '../../api/fragments'
import { centered } from '../../utils/styles'
import { useAppContext } from '../../context/AppContext'
import { useModuleCurrentContext } from '@equinor/fusion-framework-react-module-context'

interface Params {
fusionProjectId: string
evaluationId: string
}

const EvaluationView = ({ match }: RouteComponentProps<Params>) => {
const { setCurrentEvaluation } = useAppContext()
const { setCurrentEvaluation, setCurrentProject } = useAppContext()
const { currentContext } = useModuleCurrentContext()
const history = useHistory()

const evaluationId: string = match.params.evaluationId
const azureUniqueId = useAzureUniqueId()

Expand All @@ -38,6 +42,19 @@ const EvaluationView = ({ match }: RouteComponentProps<Params>) => {

const [isProgressDialogOpen, setIsProgressDialogOpen] = useState<boolean>(false)

useEffect(() => {
if (!currentContext) {
setCurrentProject(undefined)
setCurrentEvaluation(undefined)
history.push("/apps/bmt/")
}
else if (!loading && currentContext.externalId !== evaluation?.project.externalId) {
setCurrentProject(undefined)
setCurrentEvaluation(undefined)
history.push(`/apps/bmt/${currentContext.id}`)
}
}, [currentContext])

const onConfirmProgressEvaluationClick = () => {
const newProgression = getNextProgression(evaluation!.progression)
progressEvaluation(evaluationId, newProgression)
Expand Down
Loading
Loading