Skip to content

Commit

Permalink
Display reason for robot not running mission
Browse files Browse the repository at this point in the history
  • Loading branch information
Eddasol committed Jan 15, 2025
1 parent 4191785 commit 97727d8
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { MissionHistoryButton } from './MissionHistoryButton'
import { Robot } from 'models/Robot'
import { RobotMissionQueueView } from './MissionQueueView'
import { FrontPageSectionId } from 'models/FrontPageSectionId'
import { getNoMissionReason } from 'utils/IsRobotReadyToRunMissions'

const MissionControlStyle = styled.div`
display: flex;
Expand Down Expand Up @@ -89,7 +90,11 @@ const MissionControlCard = ({ robot }: { robot: Robot }) => {
>
<OngoingMissionControlCardStyle>
<RobotCard robot={robot} />
{ongoingMission ? <OngoingMissionCard mission={ongoingMission} /> : <OngoingMissionPlaceholderCard />}
{ongoingMission ? (
<OngoingMissionCard mission={ongoingMission} />
) : (
<OngoingMissionPlaceholderCard noMissionReason={getNoMissionReason(robot)} />
)}
</OngoingMissionControlCardStyle>
<RobotMissionQueueView robot={robot} />
</MissionControlCardStyle>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,20 @@ export const OngoingMissionCard = ({ mission }: MissionProps): JSX.Element => {
)
}

export const OngoingMissionPlaceholderCard = (): JSX.Element => {
export const OngoingMissionPlaceholderCard = ({ noMissionReason }: { noMissionReason?: string }): JSX.Element => {
const { TranslateText } = useLanguageContext()

return (
<>
<StyledSmallScreenMissionCard style={{ backgroundColor: tokens.colors.ui.background__light.hex }}>
<StyledSmallScreenMissionCard
style={{ backgroundColor: tokens.colors.ui.background__light.hex, gap: '8px' }}
>
<Typography variant="h5">{TranslateText('No ongoing missions')}</Typography>
{noMissionReason && <Typography variant="body_short">{noMissionReason}</Typography>}
</StyledSmallScreenMissionCard>
<StyledLargeScreenMissionCard style={{ backgroundColor: tokens.colors.ui.background__light.hex }}>
<Typography variant="h5">{TranslateText('No ongoing missions')}</Typography>
{noMissionReason && <Typography variant="body_short">{noMissionReason}</Typography>}
</StyledLargeScreenMissionCard>
</>
)
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/language/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -279,5 +279,11 @@
"Tag": "Tag",
"Timestamp": "Timestamp",
"Last completed inspection": "Last completed inspection",
"Inspection report": "Inspection report"
"Inspection report": "Inspection report",
"Battery is too low to start a mission. Queued missions will start when the battery is over {0}%.": "Battery is too low to start a mission. Queued missions will start when the battery is over {0}%.",
"Battery is too low to start a mission.": "Battery is too low to start a mission.",
"Pressure is too high to start a mission. Queued missions will start when the pressure is under {0}mBar.": "Pressure is too high to start a mission. Queued missions will start when the pressure is under {0}mBar.",
"Pressure is too high to start a mission.": "Pressure is too high to start a mission.",
"Pressure is too low to start a mission. Queued missions will start when the pressure is over {0}mBar.": "Pressure is too low to start a mission. Queued missions will start when the pressure is over {0}mBar.",
"Pressure is too low to start a mission.": "Pressure is too low to start a mission."
}
8 changes: 7 additions & 1 deletion frontend/src/language/no.json
Original file line number Diff line number Diff line change
Expand Up @@ -279,5 +279,11 @@
"Tag": "Tag",
"Timestamp": "Tidspunkt",
"Last completed inspection": "Siste gjennomførte inspeksjon",
"Inspection report": "Inspeksjonsrapport"
"Inspection report": "Inspeksjonsrapport",
"Battery is too low to start a mission. Queued missions will start when the battery is over {0}%.": "Batterinivået er for lavt til å starte oppdrag. Oppdrag i kø vil starte når batterinivået er over {0}%",
"Battery is too low to start a mission.": "Batterinivået er for lavt til å starte oppdrag.",
"Pressure is too high to start a mission. Queued missions will start when the pressure is under {0}mBar.": "Trykket er for høyt til å starte oppdrag. Oppdrag i kø vil starte når trykket er under {0}mBar.",
"Pressure is too high to start a mission.": "Trykket er for høyt til å starte oppdrag.",
"Pressure is too low to start a mission. Queued missions will start when the pressure is over {0}mBar.": "Trykket er for lavt til å starte oppdrag. Oppdrag i kø vil starte når trykket er over {0}mBar.",
"Pressure is too low to start a mission.": "Trykket er for lavt til å starte oppdrag."
}
1 change: 1 addition & 0 deletions frontend/src/models/RobotModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface RobotModel {
id: string
type: RobotType
batteryWarningThreshold?: number
batteryMissionStartThreshold?: number
upperPressureWarningThreshold?: number
lowerPressureWarningThreshold?: number
}
Expand Down
59 changes: 59 additions & 0 deletions frontend/src/utils/IsRobotReadyToRunMissions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { useLanguageContext } from 'components/Contexts/LanguageContext'
import { Robot, RobotFlotillaStatus } from 'models/Robot'

export const isBatteryTooLow = (robot: Robot): boolean => {
if (robot.batteryLevel === undefined || robot.batteryLevel === null) return false

if (robot.model.batteryWarningThreshold && robot.batteryLevel < robot.model.batteryWarningThreshold) {
return true
} else if (
robot.model.batteryMissionStartThreshold &&
robot.batteryLevel < robot.model.batteryMissionStartThreshold &&
robot.flotillaStatus === RobotFlotillaStatus.Recharging
) {
return true
}
return false
}

export const isRobotPressureTooHigh = (robot: Robot): boolean => {
if (robot.model.upperPressureWarningThreshold && robot.pressureLevel) {
return robot.pressureLevel > robot.model.upperPressureWarningThreshold
}
return false
}

export const isRobotPressureTooLow = (robot: Robot): boolean => {
if (robot.model.lowerPressureWarningThreshold && robot.pressureLevel) {
return robot.pressureLevel < robot.model.lowerPressureWarningThreshold
}
return false
}

export const getNoMissionReason = (robot: Robot): string | undefined => {
const { TranslateText } = useLanguageContext()

if (isBatteryTooLow(robot)) {
return robot.model.batteryMissionStartThreshold
? TranslateText(
'Battery is too low to start a mission. Queued missions will start when the battery is over {0}%.',
[robot.model.batteryMissionStartThreshold.toString()]
)
: TranslateText('Battery is too low to start a mission.')
} else if (isRobotPressureTooHigh(robot)) {
return robot.model.upperPressureWarningThreshold
? TranslateText(
'Pressure is too high to start a mission. Queued missions will start when the pressure is under {0}mBar.',
[(robot.model.upperPressureWarningThreshold * 1000).toString()]
)
: TranslateText('Pressure is too high to start a mission.')
} else if (isRobotPressureTooLow(robot)) {
return robot.model.lowerPressureWarningThreshold
? TranslateText(
'Pressure is too low to start a mission. Queued missions will start when the pressure is over {0}mBar.',
[(robot.model.lowerPressureWarningThreshold * 1000).toString()]
)
: TranslateText('Pressure is too low to start a mission.')
}
return undefined
}

0 comments on commit 97727d8

Please sign in to comment.