diff --git a/src/components/Table.tsx b/src/components/Table.tsx index e447beb6..5020fb19 100644 --- a/src/components/Table.tsx +++ b/src/components/Table.tsx @@ -1,19 +1,25 @@ /* eslint-disable max-lines-per-function */ +import { useMsal } from '@azure/msal-react'; import { Button, Chip, Scrim, SideSheet } from '@equinor/eds-core-react'; import { EdsDataGrid } from '@equinor/eds-data-grid-react'; import { useQuery } from '@tanstack/react-query'; import { useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { AnalogueModelsService } from '../api/generated'; +import { useAccessToken } from '../hooks/useAccessToken'; import { AreaCoordinates } from './AreaCoordinates/AreaCoordinates'; import * as Styled from './Table.styled'; export const Table = () => { + const { instance, accounts } = useMsal(); + const token = useAccessToken(instance, accounts[0]); + const [toggle, setToggle] = useState(false); const [activeModel, setActiveModel] = useState(); const { isLoading, data } = useQuery({ queryKey: ['analogue-models'], queryFn: () => AnalogueModelsService.getApiAnalogueModels(), + enabled: !!token, }); const navigate = useNavigate(); diff --git a/src/features/ModelView/ModelMetadataView/ModelMetadataView.tsx b/src/features/ModelView/ModelMetadataView/ModelMetadataView.tsx index 07c242f9..3da9488f 100644 --- a/src/features/ModelView/ModelMetadataView/ModelMetadataView.tsx +++ b/src/features/ModelView/ModelMetadataView/ModelMetadataView.tsx @@ -1,16 +1,23 @@ +import { useMsal } from '@azure/msal-react'; import { Button, Table, Typography } from '@equinor/eds-core-react'; import { useQuery } from '@tanstack/react-query'; import { useParams } from 'react-router-dom'; import { AnalogueModelsService } from '../../../api/generated/services/AnalogueModelsService'; +import { useAccessToken } from '../../../hooks/useAccessToken'; export type ModelParam = { id: string; }; export const ModelMetadataView = () => { - const { id } = useParams(); + const { modelId } = useParams(); + const { instance, accounts } = useMsal(); + const token = useAccessToken(instance, accounts[0]); + const { isLoading, data } = useQuery({ - queryKey: ['analogue-models', id], - queryFn: () => AnalogueModelsService.getApiAnalogueModels1(id as string), + queryKey: ['analogue-models', modelId], + queryFn: () => + AnalogueModelsService.getApiAnalogueModels1(modelId as string), + enabled: !!token, }); if (isLoading || !data?.success) return

Loading ...

; diff --git a/src/features/ModelView/ModelNameFrame/ModelNameFrame.styled.tsx b/src/features/ModelView/ModelNameFrame/ModelNameFrame.styled.tsx index 479bd3ff..9f35b5e7 100644 --- a/src/features/ModelView/ModelNameFrame/ModelNameFrame.styled.tsx +++ b/src/features/ModelView/ModelNameFrame/ModelNameFrame.styled.tsx @@ -4,6 +4,7 @@ import { theme } from '../../../tokens/theme'; export const NameFrame = styled.div` width: 100%; + min-height: ${spacings.NAME_FRAME}; padding: ${spacings.LARGE} 0; background-color: ${theme.light.ui.background.light}; border-left: solid ${spacings.XX_SMALL} ${theme.light.ui.background.medium}; diff --git a/src/features/ModelView/ModelNameFrame/ModelNameFrame.tsx b/src/features/ModelView/ModelNameFrame/ModelNameFrame.tsx index d2f91148..ff0ae7bf 100644 --- a/src/features/ModelView/ModelNameFrame/ModelNameFrame.tsx +++ b/src/features/ModelView/ModelNameFrame/ModelNameFrame.tsx @@ -1,10 +1,10 @@ import { AnalogueModelDetail } from '../../../api/generated'; import * as Styled from './ModelNameFrame.styled'; -export const ModelNameFrame = ({ model }: { model: AnalogueModelDetail }) => { +export const ModelNameFrame = ({ model }: { model?: AnalogueModelDetail }) => { return ( -

{model.name}

+ {model ?

{model.name}

:

Loading ....

}
); }; diff --git a/src/features/ModelView/ModelNavigationBar/ModelNavigationBar.tsx b/src/features/ModelView/ModelNavigationBar/ModelNavigationBar.tsx index 51ac08de..6fc35c1e 100644 --- a/src/features/ModelView/ModelNavigationBar/ModelNavigationBar.tsx +++ b/src/features/ModelView/ModelNavigationBar/ModelNavigationBar.tsx @@ -21,6 +21,8 @@ type MenuItems = SidebarLinkProps & { export const ModelNavigationBar = () => { const location = useLocation(); + const navigate = useNavigate(); + const tab = location.pathname.split('/'); const path = tab[tab.length - 1]; const path2 = tab[tab.length - 2]; @@ -59,20 +61,20 @@ export const ModelNavigationBar = () => { }, ], }; - const navigate = useNavigate(); return ( { navigate('details'); }} > + { }} > ))} + { navigate('results'); diff --git a/src/features/ModelView/ModelSourceView/ModelSourceView.tsx b/src/features/ModelView/ModelSourceView/ModelSourceView.tsx index 7c0c54d3..e5c93fc2 100644 --- a/src/features/ModelView/ModelSourceView/ModelSourceView.tsx +++ b/src/features/ModelView/ModelSourceView/ModelSourceView.tsx @@ -1,13 +1,20 @@ +import { useMsal } from '@azure/msal-react'; import { Table, Typography } from '@equinor/eds-core-react'; import { useQuery } from '@tanstack/react-query'; import { useParams } from 'react-router-dom'; import { AnalogueModelsService, UploadList } from '../../../api/generated'; +import { useAccessToken } from '../../../hooks/useAccessToken'; export const ModelSourceView = () => { - const { id } = useParams(); + const { modelId } = useParams(); + const { instance, accounts } = useMsal(); + const token = useAccessToken(instance, accounts[0]); + const { isLoading, data } = useQuery({ - queryKey: ['analogue-models', id], - queryFn: () => AnalogueModelsService.getApiAnalogueModels1(id as string), + queryKey: ['analogue-models', modelId], + queryFn: () => + AnalogueModelsService.getApiAnalogueModels1(modelId as string), + enabled: !!token, }); if (isLoading || !data?.success) return

Loading ...

; diff --git a/src/features/Results/CaseResult/CaseResultCard/CaseResultCard.tsx b/src/features/Results/CaseResult/CaseResultCard/CaseResultCard.tsx index 13816c2a..f797179b 100644 --- a/src/features/Results/CaseResult/CaseResultCard/CaseResultCard.tsx +++ b/src/features/Results/CaseResult/CaseResultCard/CaseResultCard.tsx @@ -5,7 +5,7 @@ import * as Styled from './CaseResultCard.styled'; export const CaseResultCard = ({ result }: { result: ResultType }) => { const navigate = useNavigate(); const handleClick = () => { - navigate(`${result.id}`); + navigate(`${result.caseId}`); }; return ( diff --git a/src/features/Results/CaseResult/CaseResultList/CaseResultList.tsx b/src/features/Results/CaseResult/CaseResultList/CaseResultList.tsx index 31e1ef03..78a08596 100644 --- a/src/features/Results/CaseResult/CaseResultList/CaseResultList.tsx +++ b/src/features/Results/CaseResult/CaseResultList/CaseResultList.tsx @@ -6,7 +6,7 @@ export const CaseResultList = ({ results }: { results: ResultType[] }) => { return ( {results.map((res: ResultType) => ( - + ))} ); diff --git a/src/features/Results/CaseResult/CaseResultView/CaseResultView.tsx b/src/features/Results/CaseResult/CaseResultView/CaseResultView.tsx index 9ea723b0..c1183780 100644 --- a/src/features/Results/CaseResult/CaseResultView/CaseResultView.tsx +++ b/src/features/Results/CaseResult/CaseResultView/CaseResultView.tsx @@ -8,7 +8,7 @@ import Img from './vargrest_output-0-_variogram_slices_.png'; import Img1 from './vargrest_output-1-_variogram_slices_.png'; export const CaseResultView = () => { const caseResult: ResultType = { - id: '1', + caseId: '1', case: 'Variogramcase 1', finished: true, }; @@ -22,9 +22,9 @@ export const CaseResultView = () => {

Case Results

{caseResult.case}

- - - + + + ); @@ -106,23 +106,23 @@ const ResultMetadata = ({ - - + + Family {data[caseNumner].family} - + Quality factor {data[caseNumner].quality} - + Attribute {data[caseNumner].attribute} - + Sigma {data[caseNumner].sigma} diff --git a/src/hooks/useAccessToken.tsx b/src/hooks/useAccessToken.tsx index 89f6e9c7..c3152445 100644 --- a/src/hooks/useAccessToken.tsx +++ b/src/hooks/useAccessToken.tsx @@ -1,6 +1,6 @@ +import { AccountInfo, IPublicClientApplication } from '@azure/msal-browser'; import { useEffect, useState } from 'react'; import { loginRequest } from '../auth/authConfig'; -import { AccountInfo, IPublicClientApplication } from '@azure/msal-browser'; export const useAccessToken = ( instance: IPublicClientApplication, diff --git a/src/pages/Layout.tsx b/src/pages/Layout.tsx index 3a3f63cc..07796045 100644 --- a/src/pages/Layout.tsx +++ b/src/pages/Layout.tsx @@ -1,5 +1,4 @@ import { useMsal } from '@azure/msal-react'; -import { useEffect } from 'react'; import { Outlet } from 'react-router-dom'; import * as Styled from '../App.styled'; import { OpenAPI } from '../api/generated/core/OpenAPI'; @@ -11,9 +10,7 @@ export const Layout = () => { const { instance, accounts } = useMsal(); const token = useAccessToken(instance, accounts[0]); - useEffect(() => { - OpenAPI.TOKEN = token; - }, [token, accounts]); + if (token) OpenAPI.TOKEN = token; return ( <> diff --git a/src/pages/ModelPages/Model/Model.tsx b/src/pages/ModelPages/Model/Model.tsx index 5a61cc93..0ac97ea1 100644 --- a/src/pages/ModelPages/Model/Model.tsx +++ b/src/pages/ModelPages/Model/Model.tsx @@ -1,16 +1,22 @@ +import { useMsal } from '@azure/msal-react'; +import { useQuery } from '@tanstack/react-query'; import { Outlet, useParams } from 'react-router-dom'; +import { AnalogueModelsService } from '../../../api/generated'; import { ModelNameFrame } from '../../../features/ModelView/ModelNameFrame/ModelNameFrame'; import { ModelNavigationBar } from '../../../features/ModelView/ModelNavigationBar/ModelNavigationBar'; +import { useAccessToken } from '../../../hooks/useAccessToken'; import * as Styled from './Model.styled'; -import { useQuery } from '@tanstack/react-query'; -import { AnalogueModelsService } from '../../../api/generated'; export const Model = () => { - const { id } = useParams<{ id: string }>(); + const { modelId } = useParams<{ modelId: string }>(); + const { instance, accounts } = useMsal(); + const token = useAccessToken(instance, accounts[0]); const { data, isLoading } = useQuery({ - queryKey: ['analogue-models', id], - queryFn: () => AnalogueModelsService.getApiAnalogueModels1(id as string), + queryKey: ['analogue-models', modelId], + queryFn: () => + AnalogueModelsService.getApiAnalogueModels1(modelId as string), + enabled: !!token, }); if (isLoading)

Loading.....

; @@ -22,7 +28,7 @@ export const Model = () => { - {data?.success && } + diff --git a/src/pages/ModelPages/Results/Results.tsx b/src/pages/ModelPages/Results/Results.tsx index 6e47be16..0c44c49a 100644 --- a/src/pages/ModelPages/Results/Results.tsx +++ b/src/pages/ModelPages/Results/Results.tsx @@ -2,15 +2,15 @@ import { CaseResultList } from '../../../features/Results/CaseResult/CaseResultL import { NoResults } from '../../../features/Results/NoResults/NoResults'; export type ResultType = { - id: string; + caseId: string; case: string; finished: boolean; }; export const Results = () => { const loaded = true; const results: ResultType[] = [ - { id: '1', case: 'Variogramcase 1', finished: true }, - { id: '2', case: 'Variogramcase 2', finished: false }, + { caseId: '1', case: 'Variogramcase 1', finished: true }, + { caseId: '2', case: 'Variogramcase 2', finished: false }, ]; return ( diff --git a/src/router.tsx b/src/router.tsx index 4523c253..98159b2d 100644 --- a/src/router.tsx +++ b/src/router.tsx @@ -26,7 +26,7 @@ const tabs: Tab[] = [ ]; const appRoutes = (tabs as NonIndexRouteObject[]).concat([ { - path: 'model/:id/', + path: 'model/:modelId/', element: , children: [ { @@ -47,7 +47,7 @@ const appRoutes = (tabs as NonIndexRouteObject[]).concat([ path: 'results', element: , }, - { path: 'results/:id', element: }, + { path: 'results/:caseId', element: }, ], }, ]); diff --git a/src/tokens/spacings.ts b/src/tokens/spacings.ts index eac16066..4dcc9f5b 100644 --- a/src/tokens/spacings.ts +++ b/src/tokens/spacings.ts @@ -23,6 +23,8 @@ export const spacings = { XXX_LARGE: comfortable.xxx_large, /** 64px */ XXXX_LARGE: '64px', + /** 75,5px */ + NAME_FRAME: '75,5px', /** 92px */ COMPUTE_BUTTON: '92px', /** 5px */