Skip to content

Commit

Permalink
Fix dialogs during ongoing localization mission
Browse files Browse the repository at this point in the history
  • Loading branch information
mrica-equinor committed Aug 13, 2024
1 parent a69ba25 commit b1503da
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,11 +30,17 @@ export const ScheduleMissionWithLocalizationVerificationDialog = ({
const { enabledRobots } = useRobotContext()
const [dialogToOpen, setDialogToOpen] = useState<DialogTypes>(DialogTypes.unknown)
const [selectedRobot, setSelectedRobot] = useState<Robot>()
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])
Expand All @@ -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
Expand All @@ -60,7 +68,7 @@ export const ScheduleMissionWithLocalizationVerificationDialog = ({
return
}

if (!selectedRobot.currentArea?.deckName) {
if (!selectedRobot.currentArea?.deckName && !ongoingLocalizationMissionOnSameDeckExists) {
setDialogToOpen(DialogTypes.verifyDeck)
return
}
Expand Down

0 comments on commit b1503da

Please sign in to comment.