Skip to content

Commit

Permalink
fix(app): add modal close logic for remote run deletion for LPC (#13633)
Browse files Browse the repository at this point in the history
  • Loading branch information
smb2268 authored Sep 22, 2023
1 parent 73e3966 commit 508d21f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { LabwareOffsetCreateData } from '@opentrons/api-client'
import {
useCreateLabwareOffsetMutation,
useCreateMaintenanceCommandMutation,
useCurrentMaintenanceRun,
} from '@opentrons/react-api-client'
import {
CompletedProtocolAnalysis,
Expand Down Expand Up @@ -37,6 +38,7 @@ import type { Axis, Sign, StepSize } from '../../molecules/JogControls/types'
import type { RegisterPositionAction, WorkingOffset } from './types'
import { getGoldenCheckSteps } from './utils/getGoldenCheckSteps'

const RUN_REFETCH_INTERVAL = 5000
const JOG_COMMAND_TIMEOUT = 10000 // 10 seconds
interface LabwarePositionCheckModalProps {
onCloseClick: () => unknown
Expand All @@ -45,6 +47,7 @@ interface LabwarePositionCheckModalProps {
mostRecentAnalysis: CompletedProtocolAnalysis | null
existingOffsets: LabwareOffset[]
caughtError?: Error
setMaintenanceRunId: (id: string | null) => void
}

export const LabwarePositionCheckComponent = (
Expand All @@ -56,10 +59,46 @@ export const LabwarePositionCheckComponent = (
existingOffsets,
runId,
maintenanceRunId,
setMaintenanceRunId,
} = props
const { t } = useTranslation(['labware_position_check', 'shared'])
const isOnDevice = useSelector(getIsOnDevice)
const protocolData = mostRecentAnalysis

// we should start checking for run deletion only after the maintenance run is created
// and the useCurrentRun poll has returned that created id
const [
monitorMaintenanceRunForDeletion,
setMonitorMaintenanceRunForDeletion,
] = React.useState<boolean>(false)

const { data: maintenanceRunData } = useCurrentMaintenanceRun({
refetchInterval: RUN_REFETCH_INTERVAL,
enabled: maintenanceRunId != null,
})

// this will close the modal in case the run was deleted by the terminate
// activity modal on the ODD
React.useEffect(() => {
if (
maintenanceRunId !== null &&
maintenanceRunData?.data.id === maintenanceRunId
) {
setMonitorMaintenanceRunForDeletion(true)
}
if (
maintenanceRunData?.data.id !== maintenanceRunId &&
monitorMaintenanceRunForDeletion
) {
setMaintenanceRunId(null)
}
}, [
maintenanceRunData?.data.id,
maintenanceRunId,
monitorMaintenanceRunForDeletion,
setMaintenanceRunId,
])

const [fatalError, setFatalError] = React.useState<string | null>(null)
const [
{ workingOffsets, tipPickUpOffset },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('useLaunchLPC hook', () => {
Promise.resolve({ data: { definitionUri: 'fakeDefUri' } })
)
mockDeleteMaintenanceRun = jest.fn((_data, opts) => {
opts?.onSuccess()
opts?.onSettled()
})
const store = mockStore({ isOnDevice: false })
wrapper = ({ children }) => (
Expand Down Expand Up @@ -184,7 +184,7 @@ describe('useLaunchLPC hook', () => {
expect(mockDeleteMaintenanceRun).toHaveBeenCalledWith(
MOCK_MAINTENANCE_RUN_ID,
{
onSuccess: expect.any(Function),
onSettled: expect.any(Function),
}
)
expect(result.current.LPCWizard).toBeNull()
Expand Down
1 change: 1 addition & 0 deletions app/src/organisms/LabwarePositionCheck/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface LabwarePositionCheckModalProps {
existingOffsets: LabwareOffset[]
mostRecentAnalysis: CompletedProtocolAnalysis | null
caughtError?: Error
setMaintenanceRunId: (id: string | null) => void
}

// We explicitly wrap LabwarePositionCheckComponent in an ErrorBoundary because an error might occur while pulling in
Expand Down
3 changes: 2 additions & 1 deletion app/src/organisms/LabwarePositionCheck/useLaunchLPC.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function useLaunchLPC(
const handleCloseLPC = (): void => {
if (maintenanceRunId != null) {
deleteMaintenanceRun(maintenanceRunId, {
onSuccess: () => {
onSettled: () => {
setMaintenanceRunId(null)
},
})
Expand Down Expand Up @@ -70,6 +70,7 @@ export function useLaunchLPC(
mostRecentAnalysis={mostRecentAnalysis}
existingOffsets={runRecord?.data?.labwareOffsets ?? []}
maintenanceRunId={maintenanceRunId}
setMaintenanceRunId={setMaintenanceRunId}
/>
) : null,
}
Expand Down

0 comments on commit 508d21f

Please sign in to comment.