Skip to content

Commit

Permalink
Fix navigation between projects and sorting evaluations table (#1083)
Browse files Browse the repository at this point in the history
  • Loading branch information
taustad committed Oct 27, 2023
1 parent 061ee64 commit a2e3a79
Show file tree
Hide file tree
Showing 8 changed files with 438 additions and 1,482 deletions.
1,843 changes: 404 additions & 1,439 deletions frontend/package-lock.json

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@
"@equinor/eds-tokens": "^0.9.2",
"@equinor/fusion": "^3.4.11",
"@equinor/fusion-components": "2.10.2",
"@equinor/fusion-framework-module-ag-grid": "^3.0.1",
"@equinor/fusion-framework-module-msal": "^1.0.23",
"@equinor/fusion-framework-react": "^4.0.6",
"@equinor/fusion-framework-react-app": "^3.0.14",
"@equinor/fusion-framework-react-module": "^2.0.2",
"@equinor/fusion-framework-react": "^5.3.3",
"@equinor/fusion-framework-react-app": "^4.1.11",
"@equinor/fusion-framework-react-module": "^3.0.6",
"@equinor/fusion-framework-react-module-context": "^6.0.16",
"@equinor/fusion-observable": "^7.0.3",
"@equinor/fusion-query": "^2.0.7",
"@floating-ui/react-dom-interactions": "^0.13.3",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/api/fragments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const EVALUATION_DASHBOARD_FIELDS_FRAGMENT = gql`
id
dueDate
completed
isVoided
}
}
}
Expand Down
1 change: 1 addition & 0 deletions frontend/src/api/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const errorLink = onError(({ graphQLErrors, networkError }) => {

export const getToken = async (): Promise<string> => {
const scopes = ["api://8829d4ca-93e8-499a-8ce1-bc0ef4840176/user_impersonation"]
// @ts-ignore
const token = await window.Fusion.modules.auth.acquireAccessToken({ scopes })
return token ?? ""
}
Expand Down
16 changes: 16 additions & 0 deletions frontend/src/configurator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { AppModuleInitiator } from "@equinor/fusion-framework-app"
import { enableContext } from "@equinor/fusion-framework-module-context"
import { enableNavigation } from "@equinor/fusion-framework-module-navigation"

export const configurator: AppModuleInitiator = (config) => {
config.useFrameworkServiceClient("portal")
enableNavigation(
config,
window.location.pathname.match(/^\/?apps/)
? "/apps/bmt"
: "/",
)
enableContext(config, (builder) => {
builder.setContextType(["ProjectMaster"])
})
}
23 changes: 9 additions & 14 deletions frontend/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect } from 'react'
import { registerApp, ContextTypes, Context, useAppConfig, useFusionContext, useCurrentUser, useFusionEnvironment } from '@equinor/fusion'
import { createLegacyApp } from "@equinor/fusion-framework-react-app"
import { createComponent, createLegacyApp } from "@equinor/fusion-framework-react-app"
import { ApolloProvider } from '@apollo/client'
import { ApplicationInsights } from '@microsoft/applicationinsights-web'
import { ReactPlugin } from '@microsoft/applicationinsights-react-js'
Expand All @@ -12,6 +12,7 @@ import { config } from './config'

import './styles.css'
import { ResolveConfiguration } from './utils/config'
import { configurator } from './configurator'

const browserHistory = createBrowserHistory()
const reactPlugin = new ReactPlugin()
Expand Down Expand Up @@ -48,6 +49,7 @@ const Start = () => {
(async () => {
try {
const scopes = ["api://8829d4ca-93e8-499a-8ce1-bc0ef4840176/user_impersonation"]
// @ts-ignore
const token = await window.Fusion.modules.auth.acquireAccessToken({ scopes })

window.sessionStorage.setItem("token", token ?? "")
Expand All @@ -73,22 +75,15 @@ const Start = () => {
)
}

registerApp('bmt', {
const render = createComponent(Start, configurator)

registerApp("bmt", {
AppComponent: Start,
context: {
types: [ContextTypes.ProjectMaster],
buildUrl: (context: Context | null) => {
const result = (context ? `/${context.id}` : "")
return result
},
// getContextFromUrl: (url: string) => {
// const result = url.split("/")[1]
// return result
// },
},
name: 'Barrier Management Tool',
render,
})

if (module.hot) {
module.hot.accept()
}

export default render
25 changes: 2 additions & 23 deletions frontend/src/utils/actionUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Action, Evaluation, Question } from '../api/models'
import { useEvaluationQuery } from '../views/Evaluation/EvaluationView'

export interface ActionQuestionAndEvaluation {
action: Action
Expand Down Expand Up @@ -29,37 +28,17 @@ export const getActionQuestionsAndEvaluations = (evaluations: Evaluation[]): Act
return actionQuestionAndEvaluations
}

export const getVoidedActions = (e: Evaluation): Action[] => {
const { evaluation } = useEvaluationQuery(e.id)
const actions: Action[] = []

if (evaluation === null || evaluation === undefined) {
return actions
}
evaluation.questions.forEach((question: Question) => {
question.actions.forEach(action => {
if (action.isVoided) {
actions.push(action)
}
})
})
return actions
}

export const getEvaluationActionsByState = (evaluation: Evaluation): ActionByState => {
const overdueActions: Action[] = []
const openActions: Action[] = []
const closedActions: Action[] = []
const now = new Date()
const voidedActions = getVoidedActions(evaluation)

evaluation.questions.forEach((question: Question) => {
question.actions.forEach(action => {
const dueDate = new Date(action.dueDate)
if (now >= dueDate && action.completed === false) {
if (!voidedActions.some(a => a.id === action.id)) {
overdueActions.push(action)
}
if (now >= dueDate && action.completed === false && !action.isVoided) {
overdueActions.push(action)
} else if (now < dueDate && action.completed === false) {
openActions.push(action)
} else if (action.completed === true) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/Evaluation/EvaluationView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ interface EvaluationQueryProps {
error: ApolloError | undefined
}

export const useEvaluationQuery = (evaluationId: string): EvaluationQueryProps => {
const useEvaluationQuery = (evaluationId: string): EvaluationQueryProps => {
const GET_EVALUATION = gql`
query ($evaluationId: String!) {
evaluations(where: { id: { eq: $evaluationId } }) {
Expand Down

0 comments on commit a2e3a79

Please sign in to comment.