Skip to content

Commit

Permalink
Add location verification to rerun functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Eddasol authored and aeshub committed Jan 8, 2024
1 parent bc4b8d8 commit 9646abf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import styled from 'styled-components'
import { useRef, useState } from 'react'
import { AlertType, useAlertContext } from 'components/Contexts/AlertContext'
import { FailedRequestAlertContent } from 'components/Alerts/FailedRequestAlert'
import { ScheduleMissionWithLocalizationVerificationDialog } from 'components/Displays/LocalizationVerification/ScheduleMissionWithLocalizationVerification'
import { Mission } from 'models/Mission'

const Centered = styled.div`
display: flex;
Expand All @@ -17,7 +19,7 @@ const Centered = styled.div`
`

interface MissionProps {
missionId: string
mission: Mission
hasFailedTasks: boolean
}

Expand All @@ -26,10 +28,12 @@ enum ReRunOptions {
ReRunFailed,
}

export const MissionRestartButton = ({ missionId, hasFailedTasks }: MissionProps) => {
export const MissionRestartButton = ({ mission, hasFailedTasks }: MissionProps) => {
const { TranslateText } = useLanguageContext()
const { setAlert } = useAlertContext()
const [isOpen, setIsOpen] = useState<boolean>(false)
const [isLocationVerificationOpen, setIsLocationVerificationOpen] = useState<boolean>(false)
const [selectedRerunOption, setSelectedRerunOption] = useState<ReRunOptions>()
const anchorRef = useRef<HTMLButtonElement>(null)

let navigate = useNavigate()
Expand All @@ -38,15 +42,17 @@ export const MissionRestartButton = ({ missionId, hasFailedTasks }: MissionProps
navigate(path)
}

const startReRun = (option: ReRunOptions) =>
BackendAPICaller.reRunMission(missionId, option === ReRunOptions.ReRunFailed)
const startReRun = (option: ReRunOptions) => {
BackendAPICaller.reRunMission(mission.id, option === ReRunOptions.ReRunFailed)
.then(() => navigateToHome())
.catch(() =>
setAlert(
AlertType.RequestFail,
<FailedRequestAlertContent message={TranslateText('Failed to rerun mission')} />
)
)
setIsLocationVerificationOpen(false)
}

return (
<Centered>
Expand Down Expand Up @@ -75,16 +81,34 @@ export const MissionRestartButton = ({ missionId, hasFailedTasks }: MissionProps
onClose={() => setIsOpen(false)}
anchorEl={anchorRef.current}
>
<Menu.Item onClick={() => startReRun(ReRunOptions.ReRun)}>
<Menu.Item
onClick={() => {
setSelectedRerunOption(ReRunOptions.ReRun)
setIsLocationVerificationOpen(true)
}}
>
{TranslateText('Re-run full mission')}
</Menu.Item>
{hasFailedTasks && (
<Menu.Item onClick={() => startReRun(ReRunOptions.ReRunFailed)}>
<Menu.Item
onClick={() => {
setSelectedRerunOption(ReRunOptions.ReRunFailed)
setIsLocationVerificationOpen(true)
}}
>
{TranslateText('Re-run failed and cancelled tasks in the mission')}
</Menu.Item>
)}
</Menu>
</EdsProvider>
{isLocationVerificationOpen && (
<ScheduleMissionWithLocalizationVerificationDialog
scheduleMissions={() => startReRun(selectedRerunOption!)}
closeDialog={() => setIsLocationVerificationOpen(false)}
robotId={mission.robot.id}
missionDeckNames={[mission.area?.deckName ?? '']}
/>
)}
</Centered>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,7 @@ export const MissionHeader = ({ mission }: { mission: Mission }) => {
missionStatus={mission.status}
/>
)}
{mission.endTime && (
<MissionRestartButton missionId={mission.id} hasFailedTasks={missionHasFailedTasks} />
)}
{mission.endTime && <MissionRestartButton mission={mission} hasFailedTasks={missionHasFailedTasks} />}
</TitleSection>
<Typography variant="body_long" group="paragraph" color={tokens.colors.text.static_icons__secondary.hex}>
{mission.description && `${translatedDescription}: ${mission.description}`}
Expand Down

0 comments on commit 9646abf

Please sign in to comment.