Skip to content
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
47 changes: 21 additions & 26 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ApplicationInsights } from '@microsoft/applicationinsights-web'
import { AuthenticatedTemplate, UnauthenticatedTemplate } from '@azure/msal-react'
import { LoginPage } from 'pages/LoginPage/LoginPage'
import { FlotillaSite } from 'pages/FlotillaSite'
import { LanguageProvider } from 'components/Contexts/LanguageContext'
import { MissionControlProvider } from 'components/Contexts/MissionControlContext'
Expand Down Expand Up @@ -30,34 +29,30 @@ export const queryClient = new QueryClient()

const App = () => (
<AuthProvider>
<LanguageProvider>
<SignalRProvider>
<QueryClientProvider client={queryClient}>
<AssetProvider>
<InspectionsProvider>
<MissionDefinitionsProvider>
<MissionRunsProvider>
<AlertProvider>
<MissionControlProvider>
<UnauthenticatedTemplate>
<div className="sign-in-page">
<LoginPage />
</div>
</UnauthenticatedTemplate>
<AuthenticatedTemplate>
<UnauthenticatedTemplate />
<AuthenticatedTemplate>
<LanguageProvider>
<SignalRProvider>
<QueryClientProvider client={queryClient}>
<AssetProvider>
<InspectionsProvider>
<MissionDefinitionsProvider>
<MissionRunsProvider>
<AlertProvider>
<MissionControlProvider>
<MediaStreamProvider>
<FlotillaSite />
</MediaStreamProvider>
</AuthenticatedTemplate>
</MissionControlProvider>
</AlertProvider>
</MissionRunsProvider>
</MissionDefinitionsProvider>
</InspectionsProvider>
</AssetProvider>
</QueryClientProvider>
</SignalRProvider>
</LanguageProvider>
</MissionControlProvider>
</AlertProvider>
</MissionRunsProvider>
</MissionDefinitionsProvider>
</InspectionsProvider>
</AssetProvider>
</QueryClientProvider>
</SignalRProvider>
</LanguageProvider>
</AuthenticatedTemplate>
</AuthProvider>
)

Expand Down
5 changes: 0 additions & 5 deletions frontend/src/components/Contexts/AssetContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ interface Props {
}

interface IAssetContext {
isLoading: boolean
enabledRobots: RobotWithoutTelemetry[]
installationCode: string
installationName: string
Expand All @@ -33,7 +32,6 @@ interface IAssetContext {
}

const defaultAssetState = {
isLoading: true,
enabledRobots: [],
installationCode: '',
installationName: '',
Expand All @@ -50,7 +48,6 @@ export const AssetProvider: FC<Props> = ({ children }) => {
const [activeInstallations, setActiveInstallations] = useState<Installation[]>([])
const [selectedInstallation, setSelectedInstallation] = useState<Installation | undefined>(undefined)
const [installationInspectionAreas, setInstallationInspectionAreas] = useState<InspectionArea[]>([])
const [isLoading, setIsLoading] = useState<boolean>(true)

const { registerEvent, connectionReady, resetConnection } = useSignalRContext()
const { TranslateText } = useLanguageContext()
Expand Down Expand Up @@ -127,7 +124,6 @@ export const AssetProvider: FC<Props> = ({ children }) => {
.getEnabledRobots()
.then((robots) => {
setEnabledRobots(robots)
setIsLoading(false)
})
.catch(() => {
setAlert(
Expand Down Expand Up @@ -251,7 +247,6 @@ export const AssetProvider: FC<Props> = ({ children }) => {
return (
<AssetContext.Provider
value={{
isLoading,
enabledRobots: filteredRobots,
installationCode,
installationName,
Expand Down
11 changes: 10 additions & 1 deletion frontend/src/components/Contexts/AuthProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useMsal } from '@azure/msal-react'
import { useCallback, useMemo } from 'react'
import { useCallback, useEffect, useMemo } from 'react'
import { InteractionStatus } from '@azure/msal-browser'
import { loginRequest } from 'api/AuthConfig'
import { AuthContext } from './AuthContext'
import { InteractionRequiredAuthError } from '@azure/msal-browser'
Expand Down Expand Up @@ -44,6 +45,14 @@ export const AuthProvider = ({ children }: Props) => {
}
}, [accounts, inProgress, instance])

useEffect(() => {
if (accounts.length > 0 || instance.getActiveAccount()) return

if (inProgress !== InteractionStatus.None) return

instance.loginRedirect(loginRequest)
}, [accounts.length, inProgress, instance])

const value = useMemo(() => ({ getAccessToken, isAuthenticated }), [getAccessToken, isAuthenticated])

return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/pages/FlotillaSite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ import { MissionDefinitionPageRouter, MissionPageRouter, RobotPageRouter, Simple
import { PageNotFound } from './NotFoundPage'
import { useAssetContext } from 'components/Contexts/AssetContext'
import { DataViewPage } from './MissionHistory/DataViewPage'
import { PageLoading } from './LoadingPage'

export const FlotillaSite = () => {
const frontPageTabOptions = Object.values(TabNames)
const { isLoading, installationCode } = useAssetContext()
const { installationCode } = useAssetContext()

const installationCodePath = `${config.FRONTEND_BASE_ROUTE}/${installationCode}`

Expand Down Expand Up @@ -60,7 +59,7 @@ export const FlotillaSite = () => {
{installationCode ? installationSpecificPages : <></>}

<Route path={`${config.FRONTEND_BASE_ROUTE}/info`} element={<InfoPage />} />
<Route path="*" element={isLoading ? <PageLoading /> : <PageNotFound />} />
<Route path="*" element={<PageNotFound />} />
</Routes>
</BrowserRouter>
</>
Expand Down
27 changes: 0 additions & 27 deletions frontend/src/pages/LoadingPage.tsx

This file was deleted.

38 changes: 0 additions & 38 deletions frontend/src/pages/LoginPage/LoginPage.tsx

This file was deleted.

Loading