From 5ea60398873eee0a80ce9f3a74aa43498a80d7c2 Mon Sep 17 00:00:00 2001 From: Eddasol Date: Fri, 25 Oct 2024 16:01:29 +0200 Subject: [PATCH] Include pressure/battery checks for 0 values --- .../ConfirmScheduleDialog.tsx | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/frontend/src/components/Displays/ConfirmScheduleDialogs/ConfirmScheduleDialog.tsx b/frontend/src/components/Displays/ConfirmScheduleDialogs/ConfirmScheduleDialog.tsx index 2b7370785..89401d2ea 100644 --- a/frontend/src/components/Displays/ConfirmScheduleDialogs/ConfirmScheduleDialog.tsx +++ b/frontend/src/components/Displays/ConfirmScheduleDialogs/ConfirmScheduleDialog.tsx @@ -23,17 +23,25 @@ export const ScheduleMissionWithConfirmDialogs = ({ const { enabledRobots } = useRobotContext() const [robot, setRobot] = useState() - const isBatteryInsufficient = (currentRobot: Robot) => - currentRobot.batteryLevel && - currentRobot.model.batteryWarningThreshold && - currentRobot.batteryLevel < currentRobot.model.batteryWarningThreshold + const isBatteryInsufficient = (currentRobot: Robot) => { + const hasBatteryValue = currentRobot.batteryLevel !== null && currentRobot.batteryLevel !== undefined + return ( + hasBatteryValue && + currentRobot.model.batteryWarningThreshold && + currentRobot.batteryLevel! < currentRobot.model.batteryWarningThreshold + ) + } - const isPressureInsufficient = (currentRobot: Robot) => - currentRobot.pressureLevel && - ((currentRobot.model.lowerPressureWarningThreshold && - currentRobot.pressureLevel < currentRobot.model.lowerPressureWarningThreshold) || + const isPressureInsufficient = (currentRobot: Robot) => { + const hasPressureValue = currentRobot.pressureLevel !== null && currentRobot.pressureLevel !== undefined + return ( + (hasPressureValue && + currentRobot.model.lowerPressureWarningThreshold && + currentRobot.pressureLevel! < currentRobot.model.lowerPressureWarningThreshold) || (currentRobot.model.upperPressureWarningThreshold && - currentRobot.pressureLevel > currentRobot.model.upperPressureWarningThreshold)) + currentRobot.pressureLevel! > currentRobot.model.upperPressureWarningThreshold) + ) + } useEffect(() => { setRobot(enabledRobots.find((robot) => robot.id === robotId))