@@ -7,6 +7,7 @@ import { LabwareOffsetCreateData } from '@opentrons/api-client'
7
7
import {
8
8
useCreateLabwareOffsetMutation ,
9
9
useCreateMaintenanceCommandMutation ,
10
+ useCurrentMaintenanceRun ,
10
11
} from '@opentrons/react-api-client'
11
12
import {
12
13
CompletedProtocolAnalysis ,
@@ -37,6 +38,7 @@ import type { Axis, Sign, StepSize } from '../../molecules/JogControls/types'
37
38
import type { RegisterPositionAction , WorkingOffset } from './types'
38
39
import { getGoldenCheckSteps } from './utils/getGoldenCheckSteps'
39
40
41
+ const RUN_REFETCH_INTERVAL = 5000
40
42
const JOG_COMMAND_TIMEOUT = 10000 // 10 seconds
41
43
interface LabwarePositionCheckModalProps {
42
44
onCloseClick : ( ) => unknown
@@ -45,6 +47,7 @@ interface LabwarePositionCheckModalProps {
45
47
mostRecentAnalysis : CompletedProtocolAnalysis | null
46
48
existingOffsets : LabwareOffset [ ]
47
49
caughtError ?: Error
50
+ setMaintenanceRunId : ( id : string | null ) => void
48
51
}
49
52
50
53
export const LabwarePositionCheckComponent = (
@@ -56,10 +59,46 @@ export const LabwarePositionCheckComponent = (
56
59
existingOffsets,
57
60
runId,
58
61
maintenanceRunId,
62
+ setMaintenanceRunId,
59
63
} = props
60
64
const { t } = useTranslation ( [ 'labware_position_check' , 'shared' ] )
61
65
const isOnDevice = useSelector ( getIsOnDevice )
62
66
const protocolData = mostRecentAnalysis
67
+
68
+ // we should start checking for run deletion only after the maintenance run is created
69
+ // and the useCurrentRun poll has returned that created id
70
+ const [
71
+ monitorMaintenanceRunForDeletion ,
72
+ setMonitorMaintenanceRunForDeletion ,
73
+ ] = React . useState < boolean > ( false )
74
+
75
+ const { data : maintenanceRunData } = useCurrentMaintenanceRun ( {
76
+ refetchInterval : RUN_REFETCH_INTERVAL ,
77
+ enabled : maintenanceRunId != null ,
78
+ } )
79
+
80
+ // this will close the modal in case the run was deleted by the terminate
81
+ // activity modal on the ODD
82
+ React . useEffect ( ( ) => {
83
+ if (
84
+ maintenanceRunId !== null &&
85
+ maintenanceRunData ?. data . id === maintenanceRunId
86
+ ) {
87
+ setMonitorMaintenanceRunForDeletion ( true )
88
+ }
89
+ if (
90
+ maintenanceRunData ?. data . id !== maintenanceRunId &&
91
+ monitorMaintenanceRunForDeletion
92
+ ) {
93
+ setMaintenanceRunId ( null )
94
+ }
95
+ } , [
96
+ maintenanceRunData ?. data . id ,
97
+ maintenanceRunId ,
98
+ monitorMaintenanceRunForDeletion ,
99
+ setMaintenanceRunId ,
100
+ ] )
101
+
63
102
const [ fatalError , setFatalError ] = React . useState < string | null > ( null )
64
103
const [
65
104
{ workingOffsets, tipPickUpOffset } ,
0 commit comments