From b1503daaf7e108af0e4f12578db08f3ad1c8b6a9 Mon Sep 17 00:00:00 2001 From: "Mariana R. Santos" Date: Mon, 12 Aug 2024 16:37:30 +0200 Subject: [PATCH] Fix dialogs during ongoing localization mission --- ...heduleMissionWithLocalizationVerification.tsx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/Displays/ConfirmScheduleDialogs/LocalizationVerification/ScheduleMissionWithLocalizationVerification.tsx b/frontend/src/components/Displays/ConfirmScheduleDialogs/LocalizationVerification/ScheduleMissionWithLocalizationVerification.tsx index 9415d25e3..e92305c8c 100644 --- a/frontend/src/components/Displays/ConfirmScheduleDialogs/LocalizationVerification/ScheduleMissionWithLocalizationVerification.tsx +++ b/frontend/src/components/Displays/ConfirmScheduleDialogs/LocalizationVerification/ScheduleMissionWithLocalizationVerification.tsx @@ -4,6 +4,7 @@ import { ConfirmLocalizationDialog } from './ConfirmLocalizationDialog' import { ConflictingMissionDecksDialog, ConflictingRobotDeckDialog } from './ConflictingLocalizationDialog' import { UnknownDeckDialog } from './UnknownDeckDialog' import { useRobotContext } from 'components/Contexts/RobotContext' +import { useMissionsContext } from 'components/Contexts/MissionRunsContext' interface IProps { scheduleMissions: () => void @@ -29,11 +30,17 @@ export const ScheduleMissionWithLocalizationVerificationDialog = ({ const { enabledRobots } = useRobotContext() const [dialogToOpen, setDialogToOpen] = useState(DialogTypes.unknown) const [selectedRobot, setSelectedRobot] = useState() + const { ongoingMissions } = useMissionsContext() const unikMissionDeckNames = missionDeckNames.filter( (deckName, index) => deckName !== '' && missionDeckNames.indexOf(deckName) === index ) + const ongoingLocalizationMissionOnSameDeckExists = + ongoingMissions.filter( + (mission) => mission.robot?.id === selectedRobot?.id && mission.area?.deckName === unikMissionDeckNames[0] + ).length > 0 + useEffect(() => { setSelectedRobot(enabledRobots.find((robot) => robot.id === robotId)) }, [robotId, enabledRobots]) @@ -42,9 +49,10 @@ export const ScheduleMissionWithLocalizationVerificationDialog = ({ if (!selectedRobot) return if ( - unikMissionDeckNames.length === 1 && - selectedRobot.currentArea?.deckName && - unikMissionDeckNames[0] === selectedRobot?.currentArea?.deckName + (unikMissionDeckNames.length === 1 && + selectedRobot.currentArea?.deckName && + unikMissionDeckNames[0] === selectedRobot?.currentArea?.deckName) || + ongoingLocalizationMissionOnSameDeckExists ) { scheduleMissions() return @@ -60,7 +68,7 @@ export const ScheduleMissionWithLocalizationVerificationDialog = ({ return } - if (!selectedRobot.currentArea?.deckName) { + if (!selectedRobot.currentArea?.deckName && !ongoingLocalizationMissionOnSameDeckExists) { setDialogToOpen(DialogTypes.verifyDeck) return }