Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface IProps {
missionInspectionAreas: InspectionArea[]
}

export const ScheduleMissionWithInspectionAreaVerification = ({
export const InspectionAreaVerificationDialog = ({
dialogType,
closeDialog,
robot,
Expand All @@ -24,25 +24,24 @@ export const ScheduleMissionWithInspectionAreaVerification = ({
(area) => area?.inspectionAreaName ?? ''
)

return (
<>
{dialogType === InspectionAreaDialogType.conflictingMissionInspectionAreas && (
switch (dialogType) {
case InspectionAreaDialogType.conflictingMissionInspectionAreas:
return (
<ConflictingMissionInspectionAreasDialog
closeDialog={closeDialog}
missionInspectionAreaNames={uniqueMissionInspectionAreaNames}
/>
)}
{dialogType === InspectionAreaDialogType.conflictingRobotInspectionArea &&
robot?.currentInspectionAreaId && (
<ConflictingRobotInspectionAreaDialog
closeDialog={closeDialog}
robotInspectionAreaId={robot.currentInspectionAreaId}
desiredInspectionAreaName={uniqueMissionInspectionAreaNames[0]}
/>
)}
{dialogType === InspectionAreaDialogType.unknownNewInspectionArea && (
<UnknownInspectionAreaDialog closeDialog={closeDialog} />
)}
</>
)
)
case InspectionAreaDialogType.conflictingRobotInspectionArea:
if (!robot?.currentInspectionAreaId) return null
return (
<ConflictingRobotInspectionAreaDialog
closeDialog={closeDialog}
robotInspectionAreaId={robot.currentInspectionAreaId}
desiredInspectionAreaName={uniqueMissionInspectionAreaNames[0]}
/>
)
case InspectionAreaDialogType.unknownNewInspectionArea:
return <UnknownInspectionAreaDialog closeDialog={closeDialog} />
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,23 @@ export enum InspectionAreaDialogType {
unknownNewInspectionArea,
conflictingMissionInspectionAreas,
conflictingRobotInspectionArea,
unknown,
}

export const getUniqueInspectionAreas = (inspectionAreas: InspectionArea[]): InspectionArea[] =>
inspectionAreas.filter((area, index, self) => self.findIndex((i) => i.id === area.id) === index)

/**
* Decides which inspection-area verification dialog (if any) must be shown before a
* mission can be scheduled. Returns null when scheduling can proceed directly.
*
* Kept as a pure function so the decision happens in the click handler rather than in a
* render effect, which avoids duplicate scheduling requests under React StrictMode.
*/
export const getInspectionAreaDialogType = (
robot: RobotWithoutTelemetry | undefined,
missionInspectionAreas: InspectionArea[]
): InspectionAreaDialogType | null => {
if (!robot) return InspectionAreaDialogType.unknown

@marianards marianards Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No robot check needed: a missing robot only skips the "robot in different area" warning below, and scheduling/rerun targets the mission's own robot anyway. If the robot happens to be null there will be logic for that later on


const uniqueInspectionAreas = getUniqueInspectionAreas(missionInspectionAreas)

if (uniqueInspectionAreas.length > 1) return InspectionAreaDialogType.conflictingMissionInspectionAreas
if (uniqueInspectionAreas.length === 0) return InspectionAreaDialogType.unknownNewInspectionArea
if (robot.currentInspectionAreaId && uniqueInspectionAreas[0]?.id !== robot.currentInspectionAreaId)
return InspectionAreaDialogType.conflictingRobotInspectionArea
if (uniqueInspectionAreas.length > 1) return InspectionAreaDialogType.conflictingMissionInspectionAreas

const robotIsInDifferentArea =
!!robot?.currentInspectionAreaId && uniqueInspectionAreas[0]?.id !== robot.currentInspectionAreaId
if (robotIsInDifferentArea) return InspectionAreaDialogType.conflictingRobotInspectionArea

return null
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AlertType, useAlertContext } from 'components/Contexts/AlertContext'
import { FailedRequestAlertContent, FailedRequestAlertListContent } from 'components/Alerts/FailedRequestAlert'
import { Mission } from 'models/Mission'
import { AlertCategory } from 'components/Alerts/AlertsBanner'
import { ScheduleMissionWithInspectionAreaVerification } from '../InspectionAreaVerificationDialogs/ScheduleMissionWithInspectionAreaVerification'
import { InspectionAreaVerificationDialog } from '../InspectionAreaVerificationDialogs/InspectionAreaVerificationDialog'
import {
getInspectionAreaDialogType,
InspectionAreaDialogType,
Expand Down Expand Up @@ -132,7 +132,7 @@ export const MissionRestartButton = ({ mission, hasFailedTasks, smallButton }: M
</Menu>
</EdsProvider>
{isLocationVerificationOpen && verificationDialogType !== null && (
<ScheduleMissionWithInspectionAreaVerification
<InspectionAreaVerificationDialog
dialogType={verificationDialogType}
closeDialog={() => setIsLocationVerificationOpen(false)}
robot={liveRobot}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/InspectionPage/ScheduleMissionDialogs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useMissionsContext } from 'components/Contexts/MissionRunsContext'
import { FailedRequestAlertContent, FailedRequestAlertListContent } from 'components/Alerts/FailedRequestAlert'
import { AlertType, useAlertContext } from 'components/Contexts/AlertContext'
import { AlertCategory } from 'components/Alerts/AlertsBanner'
import { ScheduleMissionWithInspectionAreaVerification } from 'components/Displays/InspectionAreaVerificationDialogs/ScheduleMissionWithInspectionAreaVerification'
import { InspectionAreaVerificationDialog } from 'components/Displays/InspectionAreaVerificationDialogs/InspectionAreaVerificationDialog'
import {
getInspectionAreaDialogType,
InspectionAreaDialogType,
Expand Down Expand Up @@ -210,7 +210,7 @@ export const ScheduleMissionDialog = (props: IProps) => {
</StyledDialog>
</StyledMissionDialog>
{isInspectionAreaVerificationDialogOpen && verificationDialogType !== null && (
<ScheduleMissionWithInspectionAreaVerification
<InspectionAreaVerificationDialog
dialogType={verificationDialogType}
closeDialog={closeScheduleDialogs}
robot={selectedRobot}
Expand Down
Loading