From 0237dcf74866cbc050b34b7a6f44007fc8daaf6b Mon Sep 17 00:00:00 2001 From: Eddasol Date: Wed, 15 Jan 2025 15:04:51 +0100 Subject: [PATCH] Reuse function to check if robot can run mission --- .../ConfirmScheduleDialog.tsx | 25 +++---------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/frontend/src/components/Displays/ConfirmScheduleDialogs/ConfirmScheduleDialog.tsx b/frontend/src/components/Displays/ConfirmScheduleDialogs/ConfirmScheduleDialog.tsx index 866ad32a..7de02aac 100644 --- a/frontend/src/components/Displays/ConfirmScheduleDialogs/ConfirmScheduleDialog.tsx +++ b/frontend/src/components/Displays/ConfirmScheduleDialogs/ConfirmScheduleDialog.tsx @@ -6,6 +6,7 @@ import { InsufficientPressureDialog, } from 'components/Displays/ConfirmScheduleDialogs/InsufficientValueDialogs' import { ScheduleMissionWithLocalizationVerificationDialog } from './LocalizationVerification/ScheduleMissionWithLocalizationVerification' +import { isBatteryTooLow, isRobotPressureTooHigh, isRobotPressureTooLow } from 'utils/IsRobotReadyToRunMissions' interface ConfirmScheduleDialogProps { scheduleMissions: () => void @@ -24,26 +25,6 @@ export const ScheduleMissionWithConfirmDialogs = ({ const [robot, setRobot] = useState() const [shouldScheduleWithoutLocalization, setShouldScheduleWithoutLocalization] = useState() - 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) => { - 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) - ) - } - useEffect(() => { setRobot(enabledRobots.find((robot) => robot.id === robotId)) }, [robotId, enabledRobots]) @@ -57,9 +38,9 @@ export const ScheduleMissionWithConfirmDialogs = ({ if (!robot) { return <> - } else if (isBatteryInsufficient(robot)) { + } else if (isBatteryTooLow(robot)) { return - } else if (isPressureInsufficient(robot)) { + } else if (isRobotPressureTooLow(robot) || isRobotPressureTooHigh(robot)) { return } else { // Auto-localizing robots don't need to confirmation localization. Localization dialog can be skipped