Skip to content

Commit

Permalink
Reuse function to check if robot can run mission
Browse files Browse the repository at this point in the history
  • Loading branch information
Eddasol committed Jan 15, 2025
1 parent 2295ba7 commit 0237dcf
Showing 1 changed file with 3 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,26 +25,6 @@ export const ScheduleMissionWithConfirmDialogs = ({
const [robot, setRobot] = useState<Robot>()
const [shouldScheduleWithoutLocalization, setShouldScheduleWithoutLocalization] = useState<boolean>()

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])
Expand All @@ -57,9 +38,9 @@ export const ScheduleMissionWithConfirmDialogs = ({

if (!robot) {
return <></>
} else if (isBatteryInsufficient(robot)) {
} else if (isBatteryTooLow(robot)) {
return <InsufficientBatteryDialog robot={robot} cancel={closeDialog} />
} else if (isPressureInsufficient(robot)) {
} else if (isRobotPressureTooLow(robot) || isRobotPressureTooHigh(robot)) {
return <InsufficientPressureDialog robot={robot} cancel={closeDialog} />
} else {
// Auto-localizing robots don't need to confirmation localization. Localization dialog can be skipped
Expand Down

0 comments on commit 0237dcf

Please sign in to comment.