diff --git a/frontend/src/components/Displays/InspectionAreaVerificationDialogs/ScheduleMissionWithInspectionAreaVerification.tsx b/frontend/src/components/Displays/InspectionAreaVerificationDialogs/InspectionAreaVerificationDialog.tsx similarity index 55% rename from frontend/src/components/Displays/InspectionAreaVerificationDialogs/ScheduleMissionWithInspectionAreaVerification.tsx rename to frontend/src/components/Displays/InspectionAreaVerificationDialogs/InspectionAreaVerificationDialog.tsx index 9605e9f65..58b737ec3 100644 --- a/frontend/src/components/Displays/InspectionAreaVerificationDialogs/ScheduleMissionWithInspectionAreaVerification.tsx +++ b/frontend/src/components/Displays/InspectionAreaVerificationDialogs/InspectionAreaVerificationDialog.tsx @@ -14,7 +14,7 @@ interface IProps { missionInspectionAreas: InspectionArea[] } -export const ScheduleMissionWithInspectionAreaVerification = ({ +export const InspectionAreaVerificationDialog = ({ dialogType, closeDialog, robot, @@ -24,25 +24,24 @@ export const ScheduleMissionWithInspectionAreaVerification = ({ (area) => area?.inspectionAreaName ?? '' ) - return ( - <> - {dialogType === InspectionAreaDialogType.conflictingMissionInspectionAreas && ( + switch (dialogType) { + case InspectionAreaDialogType.conflictingMissionInspectionAreas: + return ( - )} - {dialogType === InspectionAreaDialogType.conflictingRobotInspectionArea && - robot?.currentInspectionAreaId && ( - - )} - {dialogType === InspectionAreaDialogType.unknownNewInspectionArea && ( - - )} - - ) + ) + case InspectionAreaDialogType.conflictingRobotInspectionArea: + if (!robot?.currentInspectionAreaId) return null + return ( + + ) + case InspectionAreaDialogType.unknownNewInspectionArea: + return + } } diff --git a/frontend/src/components/Displays/InspectionAreaVerificationDialogs/getInspectionAreaDialogType.ts b/frontend/src/components/Displays/InspectionAreaVerificationDialogs/getInspectionAreaDialogType.ts index 9ed547141..46e4072db 100644 --- a/frontend/src/components/Displays/InspectionAreaVerificationDialogs/getInspectionAreaDialogType.ts +++ b/frontend/src/components/Displays/InspectionAreaVerificationDialogs/getInspectionAreaDialogType.ts @@ -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 - 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 } diff --git a/frontend/src/components/Displays/MissionButtons/MissionRestartButton.tsx b/frontend/src/components/Displays/MissionButtons/MissionRestartButton.tsx index fc186a7e1..ad4133fc1 100644 --- a/frontend/src/components/Displays/MissionButtons/MissionRestartButton.tsx +++ b/frontend/src/components/Displays/MissionButtons/MissionRestartButton.tsx @@ -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, @@ -132,7 +132,7 @@ export const MissionRestartButton = ({ mission, hasFailedTasks, smallButton }: M {isLocationVerificationOpen && verificationDialogType !== null && ( - setIsLocationVerificationOpen(false)} robot={liveRobot} diff --git a/frontend/src/pages/InspectionPage/ScheduleMissionDialogs.tsx b/frontend/src/pages/InspectionPage/ScheduleMissionDialogs.tsx index 7c6cb1a52..2e23646be 100644 --- a/frontend/src/pages/InspectionPage/ScheduleMissionDialogs.tsx +++ b/frontend/src/pages/InspectionPage/ScheduleMissionDialogs.tsx @@ -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, @@ -210,7 +210,7 @@ export const ScheduleMissionDialog = (props: IProps) => { {isInspectionAreaVerificationDialogOpen && verificationDialogType !== null && ( -