Skip to content

Commit 508d21f

Browse files
authored
fix(app): add modal close logic for remote run deletion for LPC (#13633)
fix RQA-1703
1 parent 73e3966 commit 508d21f

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

app/src/organisms/LabwarePositionCheck/LabwarePositionCheckComponent.tsx

+39
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { LabwareOffsetCreateData } from '@opentrons/api-client'
77
import {
88
useCreateLabwareOffsetMutation,
99
useCreateMaintenanceCommandMutation,
10+
useCurrentMaintenanceRun,
1011
} from '@opentrons/react-api-client'
1112
import {
1213
CompletedProtocolAnalysis,
@@ -37,6 +38,7 @@ import type { Axis, Sign, StepSize } from '../../molecules/JogControls/types'
3738
import type { RegisterPositionAction, WorkingOffset } from './types'
3839
import { getGoldenCheckSteps } from './utils/getGoldenCheckSteps'
3940

41+
const RUN_REFETCH_INTERVAL = 5000
4042
const JOG_COMMAND_TIMEOUT = 10000 // 10 seconds
4143
interface LabwarePositionCheckModalProps {
4244
onCloseClick: () => unknown
@@ -45,6 +47,7 @@ interface LabwarePositionCheckModalProps {
4547
mostRecentAnalysis: CompletedProtocolAnalysis | null
4648
existingOffsets: LabwareOffset[]
4749
caughtError?: Error
50+
setMaintenanceRunId: (id: string | null) => void
4851
}
4952

5053
export const LabwarePositionCheckComponent = (
@@ -56,10 +59,46 @@ export const LabwarePositionCheckComponent = (
5659
existingOffsets,
5760
runId,
5861
maintenanceRunId,
62+
setMaintenanceRunId,
5963
} = props
6064
const { t } = useTranslation(['labware_position_check', 'shared'])
6165
const isOnDevice = useSelector(getIsOnDevice)
6266
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+
63102
const [fatalError, setFatalError] = React.useState<string | null>(null)
64103
const [
65104
{ workingOffsets, tipPickUpOffset },

app/src/organisms/LabwarePositionCheck/__tests__/useLaunchLPC.test.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ describe('useLaunchLPC hook', () => {
8080
Promise.resolve({ data: { definitionUri: 'fakeDefUri' } })
8181
)
8282
mockDeleteMaintenanceRun = jest.fn((_data, opts) => {
83-
opts?.onSuccess()
83+
opts?.onSettled()
8484
})
8585
const store = mockStore({ isOnDevice: false })
8686
wrapper = ({ children }) => (
@@ -184,7 +184,7 @@ describe('useLaunchLPC hook', () => {
184184
expect(mockDeleteMaintenanceRun).toHaveBeenCalledWith(
185185
MOCK_MAINTENANCE_RUN_ID,
186186
{
187-
onSuccess: expect.any(Function),
187+
onSettled: expect.any(Function),
188188
}
189189
)
190190
expect(result.current.LPCWizard).toBeNull()

app/src/organisms/LabwarePositionCheck/index.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ interface LabwarePositionCheckModalProps {
1313
existingOffsets: LabwareOffset[]
1414
mostRecentAnalysis: CompletedProtocolAnalysis | null
1515
caughtError?: Error
16+
setMaintenanceRunId: (id: string | null) => void
1617
}
1718

1819
// We explicitly wrap LabwarePositionCheckComponent in an ErrorBoundary because an error might occur while pulling in

app/src/organisms/LabwarePositionCheck/useLaunchLPC.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function useLaunchLPC(
2929
const handleCloseLPC = (): void => {
3030
if (maintenanceRunId != null) {
3131
deleteMaintenanceRun(maintenanceRunId, {
32-
onSuccess: () => {
32+
onSettled: () => {
3333
setMaintenanceRunId(null)
3434
},
3535
})
@@ -70,6 +70,7 @@ export function useLaunchLPC(
7070
mostRecentAnalysis={mostRecentAnalysis}
7171
existingOffsets={runRecord?.data?.labwareOffsets ?? []}
7272
maintenanceRunId={maintenanceRunId}
73+
setMaintenanceRunId={setMaintenanceRunId}
7374
/>
7475
) : null,
7576
}

0 commit comments

Comments
 (0)