Skip to content

Commit

Permalink
Set list alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
haakonsf committed Aug 29, 2024
1 parent 74943e9 commit 9fe5ab6
Show file tree
Hide file tree
Showing 18 changed files with 261 additions and 51 deletions.
39 changes: 34 additions & 5 deletions frontend/src/components/Contexts/AlertContext.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { createContext, FC, ReactNode, useContext, useEffect, useState } from 'react'
import { addMinutes, max } from 'date-fns'
import { Mission, MissionStatus } from 'models/Mission'
import { FailedMissionAlertContent } from 'components/Alerts/FailedMissionAlert'
import { FailedMissionAlertContent, FailedMissionAlertListContent } from 'components/Alerts/FailedMissionAlert'
import { BackendAPICaller } from 'api/ApiCaller'
import { SignalREventLabels, useSignalRContext } from './SignalRContext'
import { useInstallationContext } from './InstallationContext'
import { Alert } from 'models/Alert'
import { useRobotContext } from './RobotContext'
import { BlockedRobotAlertContent } from 'components/Alerts/BlockedRobotAlert'
import { BlockedRobotAlertContent, BlockedRobotAlertListContent } from 'components/Alerts/BlockedRobotAlert'
import { RobotStatus } from 'models/Robot'
import { FailedAlertContent } from 'components/Alerts/FailedAlertContent'
import { FailedAlertContent, FailedAlertListContent } from 'components/Alerts/FailedAlertContent'
import { convertUTCDateToLocalDate } from 'utils/StringFormatting'
import { AlertCategory } from 'components/Alerts/AlertsBanner'
import { SafeZoneAlertContent } from 'components/Alerts/SafeZoneAlert'
import { SafeZoneAlertContent, SafeZoneAlertListContent } from 'components/Alerts/SafeZoneAlert'
import { useLanguageContext } from './LanguageContext'
import { FailedRequestAlertContent } from 'components/Alerts/FailedRequestAlert'
import { FailedRequestAlertContent, FailedRequestAlertListContent } from 'components/Alerts/FailedRequestAlert'

export enum AlertType {
MissionFail,
Expand Down Expand Up @@ -165,6 +165,13 @@ export const AlertProvider: FC<Props> = ({ children }) => {
/>,
AlertCategory.ERROR
)
setListAlert(
AlertType.RequestFail,
<FailedRequestAlertListContent
translatedMessage={TranslateText('Failed to retrieve failed missions')}
/>,
AlertCategory.ERROR
)
})
}
if (!recentFailedMissions || recentFailedMissions.length === 0) updateRecentFailedMissions()
Expand Down Expand Up @@ -213,12 +220,23 @@ export const AlertProvider: FC<Props> = ({ children }) => {
AlertCategory.INFO
)
clearAlert(AlertType.RequestSafeZone)
setListAlert(
alertType,
<SafeZoneAlertListContent alertType={alertType} alertCategory={AlertCategory.INFO} />,
AlertCategory.INFO
)
clearListAlert(AlertType.RequestSafeZone)
} else {
setAlert(
alertType,
<FailedAlertContent title={backendAlert.alertTitle} message={backendAlert.alertMessage} />,
AlertCategory.ERROR
)
setListAlert(
alertType,
<FailedAlertListContent title={backendAlert.alertTitle} message={backendAlert.alertMessage} />,
AlertCategory.ERROR
)
}
})
}
Expand All @@ -232,6 +250,11 @@ export const AlertProvider: FC<Props> = ({ children }) => {
<FailedMissionAlertContent missions={newFailedMissions} />,
AlertCategory.ERROR
)
setListAlert(
AlertType.MissionFail,
<FailedMissionAlertListContent missions={newFailedMissions} />,
AlertCategory.ERROR
)
setNewFailedMissions([])
}
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand All @@ -253,8 +276,14 @@ export const AlertProvider: FC<Props> = ({ children }) => {
<BlockedRobotAlertContent robotNames={newBlockedRobotNames} />,
AlertCategory.WARNING
)
setListAlert(
AlertType.BlockedRobot,
<BlockedRobotAlertListContent robotNames={newBlockedRobotNames} />,
AlertCategory.WARNING
)
} else {
clearAlert(AlertType.BlockedRobot)
clearListAlert(AlertType.BlockedRobot)
}
}
setBlockedRobotNames(newBlockedRobotNames)
Expand Down
29 changes: 27 additions & 2 deletions frontend/src/components/Contexts/InstallationContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { SignalREventLabels, useSignalRContext } from './SignalRContext'
import { Area } from 'models/Area'
import { useLanguageContext } from './LanguageContext'
import { AlertType, useAlertContext } from './AlertContext'
import { FailedRequestAlertContent } from 'components/Alerts/FailedRequestAlert'
import { FailedRequestAlertContent, FailedRequestAlertListContent } from 'components/Alerts/FailedRequestAlert'
import { AlertCategory } from 'components/Alerts/AlertsBanner'

interface IInstallationContext {
Expand Down Expand Up @@ -42,7 +42,7 @@ export const InstallationContext = createContext<IInstallationContext>(defaultIn
export const InstallationProvider: FC<Props> = ({ children }) => {
const { registerEvent, connectionReady } = useSignalRContext()
const { TranslateText } = useLanguageContext()
const { setAlert } = useAlertContext()
const { setAlert, setListAlert } = useAlertContext()
const [allPlantsMap, setAllPlantsMap] = useState<Map<string, string>>(new Map())
const [installationName, setInstallationName] = useState<string>(
window.localStorage.getItem('installationName') || ''
Expand All @@ -66,6 +66,13 @@ export const InstallationProvider: FC<Props> = ({ children }) => {
/>,
AlertCategory.ERROR
)
setListAlert(
AlertType.RequestFail,
<FailedRequestAlertListContent
translatedMessage={TranslateText('Failed to retrieve installations from Echo')}
/>,
AlertCategory.ERROR
)
})
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
Expand Down Expand Up @@ -99,6 +106,15 @@ export const InstallationProvider: FC<Props> = ({ children }) => {
/>,
AlertCategory.ERROR
)
setListAlert(
AlertType.RequestFail,
<FailedRequestAlertListContent
translatedMessage={TranslateText('Failed to retrieve areas on deck {0}', [
deck.deckName,
])}
/>,
AlertCategory.ERROR
)
})
)
})
Expand All @@ -112,6 +128,15 @@ export const InstallationProvider: FC<Props> = ({ children }) => {
/>,
AlertCategory.ERROR
)
setListAlert(
AlertType.RequestFail,
<FailedRequestAlertListContent
translatedMessage={TranslateText('Failed to retrieve decks on installation {0}', [
installationCode,
])}
/>,
AlertCategory.ERROR
)
})
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [installationCode])
Expand Down
44 changes: 36 additions & 8 deletions frontend/src/components/Contexts/MissionControlContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createContext, useContext, useState, FC } from 'react'
import { BackendAPICaller } from 'api/ApiCaller'
import { MissionStatusRequest } from 'components/Pages/FrontPage/MissionOverview/StopDialogs'
import { AlertType, useAlertContext } from './AlertContext'
import { FailedRequestAlertContent } from 'components/Alerts/FailedRequestAlert'
import { FailedRequestAlertContent, FailedRequestAlertListContent } from 'components/Alerts/FailedRequestAlert'
import { AlertCategory } from 'components/Alerts/AlertsBanner'
import { useLanguageContext } from './LanguageContext'
import { useRobotContext } from './RobotContext'
Expand Down Expand Up @@ -33,7 +33,7 @@ const defaultManagementState: IMissionControlState = {
export const MissionControlProvider: FC<Props> = ({ children }) => {
const { TranslateText } = useLanguageContext()
const { enabledRobots } = useRobotContext()
const { setAlert } = useAlertContext()
const { setAlert, setListAlert } = useAlertContext()
const [missionControlState, setMissionControlState] = useState<IMissionControlState>(defaultManagementState)

const setIsWaitingForResponse = (robotId: string, isWaiting: boolean) => {
Expand All @@ -52,6 +52,13 @@ export const MissionControlProvider: FC<Props> = ({ children }) => {
/>,
AlertCategory.ERROR
)
setListAlert(
AlertType.RequestFail,
<FailedRequestAlertListContent
translatedMessage={TranslateText('Unable to find robot with ID {0}', [robotId])}
/>,
AlertCategory.ERROR
)
return
}

Expand All @@ -61,45 +68,66 @@ export const MissionControlProvider: FC<Props> = ({ children }) => {
setIsWaitingForResponse(robotId, true)
BackendAPICaller.pauseMission(robotId)
.then((_) => setIsWaitingForResponse(robotId, false))
.catch((_) =>
.catch((_) => {
setAlert(
AlertType.RequestFail,
<FailedRequestAlertContent
translatedMessage={TranslateText('Failed to pause mission on {0}', [robotName])}
/>,
AlertCategory.ERROR
)
)
setListAlert(
AlertType.RequestFail,
<FailedRequestAlertListContent
translatedMessage={TranslateText('Failed to pause mission on {0}', [robotName])}
/>,
AlertCategory.ERROR
)
})
break
}
case MissionStatusRequest.Resume: {
setIsWaitingForResponse(robotId, true)
BackendAPICaller.resumeMission(robotId)
.then((_) => setIsWaitingForResponse(robotId, false))
.catch((_) =>
.catch((_) => {
setAlert(
AlertType.RequestFail,
<FailedRequestAlertContent
translatedMessage={TranslateText('Failed to resume mission on {0}', [robotName])}
/>,
AlertCategory.ERROR
)
)
setListAlert(
AlertType.RequestFail,
<FailedRequestAlertListContent
translatedMessage={TranslateText('Failed to resume mission on {0}', [robotName])}
/>,
AlertCategory.ERROR
)
})
break
}
case MissionStatusRequest.Stop: {
setIsWaitingForResponse(robotId, true)
BackendAPICaller.stopMission(robotId)
.then((_) => setIsWaitingForResponse(robotId, false))
.catch((_) =>
.catch((_) => {
setAlert(
AlertType.RequestFail,
<FailedRequestAlertContent
translatedMessage={TranslateText('Failed to stop mission on {0}', [robotName])}
/>,
AlertCategory.ERROR
)
)
setListAlert(
AlertType.RequestFail,
<FailedRequestAlertListContent
translatedMessage={TranslateText('Failed to stop mission on {0}', [robotName])}
/>,
AlertCategory.ERROR
)
})
break
}
}
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/components/Contexts/MissionDefinitionsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CondensedMissionDefinition } from 'models/MissionDefinition'
import { useInstallationContext } from './InstallationContext'
import { useLanguageContext } from './LanguageContext'
import { AlertType, useAlertContext } from './AlertContext'
import { FailedRequestAlertContent } from 'components/Alerts/FailedRequestAlert'
import { FailedRequestAlertContent, FailedRequestAlertListContent } from 'components/Alerts/FailedRequestAlert'
import { AlertCategory } from 'components/Alerts/AlertsBanner'

interface IMissionDefinitionsContext {
Expand Down Expand Up @@ -48,7 +48,7 @@ export const useMissionDefinitions = (): IMissionDefinitionsContext => {
const { registerEvent, connectionReady } = useSignalRContext()
const { installationCode } = useInstallationContext()
const { TranslateText } = useLanguageContext()
const { setAlert } = useAlertContext()
const { setAlert, setListAlert } = useAlertContext()

useEffect(() => {
if (connectionReady) {
Expand Down Expand Up @@ -92,6 +92,13 @@ export const useMissionDefinitions = (): IMissionDefinitionsContext => {
/>,
AlertCategory.ERROR
)
setListAlert(
AlertType.RequestFail,
<FailedRequestAlertListContent
translatedMessage={TranslateText('Failed to retrieve inspection plans')}
/>,
AlertCategory.ERROR
)
})
setMissionDefinitions(missionDefinitionsInInstallation ?? [])
}
Expand Down
18 changes: 16 additions & 2 deletions frontend/src/components/Contexts/MissionRunsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { SignalREventLabels, useSignalRContext } from './SignalRContext'
import { TaskStatus } from 'models/Task'
import { useLanguageContext } from './LanguageContext'
import { AlertType, useAlertContext } from './AlertContext'
import { FailedRequestAlertContent } from 'components/Alerts/FailedRequestAlert'
import { FailedRequestAlertContent, FailedRequestAlertListContent } from 'components/Alerts/FailedRequestAlert'
import { AlertCategory } from 'components/Alerts/AlertsBanner'
import { useInstallationContext } from './InstallationContext'

Expand Down Expand Up @@ -82,7 +82,7 @@ export const useMissionRuns = (): IMissionRunsContext => {
const [loadingMissionSet, setLoadingMissionSet] = useState<Set<string>>(new Set())
const { registerEvent, connectionReady } = useSignalRContext()
const { TranslateText } = useLanguageContext()
const { setAlert } = useAlertContext()
const { setAlert, setListAlert } = useAlertContext()
const { installationCode } = useInstallationContext()

useEffect(() => {
Expand Down Expand Up @@ -137,6 +137,13 @@ export const useMissionRuns = (): IMissionRunsContext => {
<FailedRequestAlertContent translatedMessage={TranslateText('Failed to retrieve mission runs')} />,
AlertCategory.ERROR
)
setListAlert(
AlertType.RequestFail,
<FailedRequestAlertListContent
translatedMessage={TranslateText('Failed to retrieve mission runs')}
/>,
AlertCategory.ERROR
)
})

setOngoingMissions(ongoing ?? [])
Expand All @@ -151,6 +158,13 @@ export const useMissionRuns = (): IMissionRunsContext => {
<FailedRequestAlertContent translatedMessage={TranslateText('Failed to retrieve mission runs')} />,
AlertCategory.ERROR
)
setListAlert(
AlertType.RequestFail,
<FailedRequestAlertListContent
translatedMessage={TranslateText('Failed to retrieve mission runs')}
/>,
AlertCategory.ERROR
)
})

setMissionQueue(queue ?? [])
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/components/Contexts/RobotContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Robot } from 'models/Robot'
import { SignalREventLabels, useSignalRContext } from './SignalRContext'
import { useLanguageContext } from './LanguageContext'
import { AlertType, useAlertContext } from './AlertContext'
import { FailedRequestAlertContent } from 'components/Alerts/FailedRequestAlert'
import { FailedRequestAlertContent, FailedRequestAlertListContent } from 'components/Alerts/FailedRequestAlert'
import { AlertCategory } from 'components/Alerts/AlertsBanner'
import { useInstallationContext } from './InstallationContext'

Expand Down Expand Up @@ -34,7 +34,7 @@ export const RobotProvider: FC<Props> = ({ children }) => {
const [enabledRobots, setEnabledRobots] = useState<Robot[]>(defaultRobotState.enabledRobots)
const { registerEvent, connectionReady } = useSignalRContext()
const { TranslateText } = useLanguageContext()
const { setAlert } = useAlertContext()
const { setAlert, setListAlert } = useAlertContext()
const { installationCode } = useInstallationContext()

useEffect(() => {
Expand Down Expand Up @@ -84,6 +84,13 @@ export const RobotProvider: FC<Props> = ({ children }) => {
<FailedRequestAlertContent translatedMessage={TranslateText('Failed to retrieve robots')} />,
AlertCategory.ERROR
)
setListAlert(
AlertType.RequestFail,
<FailedRequestAlertListContent
translatedMessage={TranslateText('Failed to retrieve robots')}
/>,
AlertCategory.ERROR
)
})
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
Expand Down
Loading

0 comments on commit 9fe5ab6

Please sign in to comment.