Skip to content

Commit aeb16ee

Browse files
committed
refactor(app): do pipette homing via onclick
1 parent 5d0bb60 commit aeb16ee

File tree

4 files changed

+30
-114
lines changed

4 files changed

+30
-114
lines changed

app/src/organisms/ErrorRecoveryFlows/ErrorRecoveryWizard.tsx

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState, useEffect, useLayoutEffect } from 'react'
1+
import { useState, useEffect } from 'react'
22
import { useTranslation } from 'react-i18next'
33
import { css } from 'styled-components'
44

@@ -75,21 +75,12 @@ export type ErrorRecoveryWizardProps = ErrorRecoveryFlowsProps &
7575
export function ErrorRecoveryWizard(
7676
props: ErrorRecoveryWizardProps
7777
): JSX.Element {
78-
const {
79-
hasLaunchedRecovery,
80-
failedCommand,
81-
recoveryCommands,
82-
routeUpdateActions,
83-
} = props
84-
const errorKind = getErrorKind(failedCommand)
85-
86-
useInitialPipetteHome({
87-
hasLaunchedRecovery,
88-
recoveryCommands,
89-
routeUpdateActions,
90-
})
91-
92-
return <ErrorRecoveryComponent errorKind={errorKind} {...props} />
78+
return (
79+
<ErrorRecoveryComponent
80+
errorKind={getErrorKind(props.failedCommand)}
81+
{...props}
82+
/>
83+
)
9384
}
9485

9586
export function ErrorRecoveryComponent(
@@ -280,26 +271,3 @@ export function ErrorRecoveryContent(props: RecoveryContentProps): JSX.Element {
280271
return buildSelectRecoveryOption()
281272
}
282273
}
283-
interface UseInitialPipetteHomeParams {
284-
hasLaunchedRecovery: ErrorRecoveryWizardProps['hasLaunchedRecovery']
285-
recoveryCommands: ErrorRecoveryWizardProps['recoveryCommands']
286-
routeUpdateActions: ErrorRecoveryWizardProps['routeUpdateActions']
287-
}
288-
// Home the Z-axis of all attached pipettes on Error Recovery launch.
289-
export function useInitialPipetteHome({
290-
hasLaunchedRecovery,
291-
recoveryCommands,
292-
routeUpdateActions,
293-
}: UseInitialPipetteHomeParams): void {
294-
const { homePipetteZAxes } = recoveryCommands
295-
const { handleMotionRouting } = routeUpdateActions
296-
297-
// Synchronously set the recovery route to "robot in motion" before initial render to prevent screen flicker on ER launch.
298-
useLayoutEffect(() => {
299-
if (hasLaunchedRecovery) {
300-
void handleMotionRouting(true)
301-
.then(() => homePipetteZAxes())
302-
.finally(() => handleMotionRouting(false))
303-
}
304-
}, [hasLaunchedRecovery])
305-
}

app/src/organisms/ErrorRecoveryFlows/RecoverySplash.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,14 @@ export function RecoverySplash(props: RecoverySplashProps): JSX.Element | null {
8383
runStatus,
8484
recoveryActionMutationUtils,
8585
resumePausedRecovery,
86+
recoveryCommands,
8687
} = props
8788
const { t } = useTranslation('error_recovery')
8889
const errorKind = getErrorKind(failedCommand)
8990
const title = useErrorName(errorKind)
9091
const { makeToast } = useToaster()
9192

92-
const { proceedToRouteAndStep } = routeUpdateActions
93+
const { proceedToRouteAndStep, handleMotionRouting } = routeUpdateActions
9394
const { reportErrorEvent } = analytics
9495

9596
const buildTitleHeadingDesktop = (): JSX.Element => {
@@ -138,9 +139,16 @@ export function RecoverySplash(props: RecoverySplashProps): JSX.Element | null {
138139

139140
const onLaunchERClick = (): void => {
140141
const onClick = (): void => {
141-
void toggleERWizAsActiveUser(true, true).then(() => {
142-
reportErrorEvent(failedCommand?.byRunRecord ?? null, 'launch-recovery')
143-
})
142+
void toggleERWizAsActiveUser(true, true)
143+
.then(() => {
144+
reportErrorEvent(
145+
failedCommand?.byRunRecord ?? null,
146+
'launch-recovery'
147+
)
148+
})
149+
.then(() => handleMotionRouting(true))
150+
.then(() => recoveryCommands.homePipetteZAxes())
151+
.finally(() => handleMotionRouting(false))
144152
}
145153
handleConditionalClick(onClick)
146154
}

app/src/organisms/ErrorRecoveryFlows/__tests__/ErrorRecoveryWizard.test.tsx

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { i18n } from '/app/i18n'
77
import { mockRecoveryContentProps } from '../__fixtures__'
88
import {
99
ErrorRecoveryContent,
10-
useInitialPipetteHome,
1110
useERWizard,
1211
ErrorRecoveryComponent,
1312
} from '../ErrorRecoveryWizard'
@@ -509,73 +508,3 @@ describe('ErrorRecoveryContent', () => {
509508
screen.getByText('MOCK_DOOR_OPEN_SPECIAL')
510509
})
511510
})
512-
513-
describe('useInitialPipetteHome', () => {
514-
let mockZHomePipetteZAxes: Mock
515-
let mockhandleMotionRouting: Mock
516-
let mockRecoveryCommands: any
517-
let mockRouteUpdateActions: any
518-
519-
beforeEach(() => {
520-
mockZHomePipetteZAxes = vi.fn()
521-
mockhandleMotionRouting = vi.fn()
522-
523-
mockhandleMotionRouting.mockResolvedValue(() => mockZHomePipetteZAxes())
524-
mockZHomePipetteZAxes.mockResolvedValue(() => mockhandleMotionRouting())
525-
526-
mockRecoveryCommands = {
527-
homePipetteZAxes: mockZHomePipetteZAxes,
528-
} as any
529-
mockRouteUpdateActions = {
530-
handleMotionRouting: mockhandleMotionRouting,
531-
} as any
532-
})
533-
534-
it('does not z-home the pipettes if error recovery was not launched', () => {
535-
renderHook(() =>
536-
useInitialPipetteHome({
537-
hasLaunchedRecovery: false,
538-
recoveryCommands: mockRecoveryCommands,
539-
routeUpdateActions: mockRouteUpdateActions,
540-
})
541-
)
542-
543-
expect(mockhandleMotionRouting).not.toHaveBeenCalled()
544-
})
545-
546-
it('sets the motion screen properly and z-homes all pipettes only on the initial render of Error Recovery', async () => {
547-
const { rerender } = renderHook(() =>
548-
useInitialPipetteHome({
549-
hasLaunchedRecovery: true,
550-
recoveryCommands: mockRecoveryCommands,
551-
routeUpdateActions: mockRouteUpdateActions,
552-
})
553-
)
554-
555-
await waitFor(() => {
556-
expect(mockhandleMotionRouting).toHaveBeenCalledWith(true)
557-
})
558-
await waitFor(() => {
559-
expect(mockZHomePipetteZAxes).toHaveBeenCalledTimes(1)
560-
})
561-
await waitFor(() => {
562-
expect(mockhandleMotionRouting).toHaveBeenCalledWith(false)
563-
})
564-
565-
expect(mockhandleMotionRouting.mock.invocationCallOrder[0]).toBeLessThan(
566-
mockZHomePipetteZAxes.mock.invocationCallOrder[0]
567-
)
568-
expect(mockZHomePipetteZAxes.mock.invocationCallOrder[0]).toBeLessThan(
569-
mockhandleMotionRouting.mock.invocationCallOrder[1]
570-
)
571-
572-
rerender()
573-
574-
await waitFor(() => {
575-
expect(mockhandleMotionRouting).toHaveBeenCalledTimes(2)
576-
})
577-
await waitFor(() => {
578-
expect(mockZHomePipetteZAxes).toHaveBeenCalledTimes(1)
579-
})
580-
})
581-
})

app/src/organisms/ErrorRecoveryFlows/__tests__/RecoverySplash.test.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,14 @@ describe('RecoverySplash', () => {
8080
let props: React.ComponentProps<typeof RecoverySplash>
8181
const mockToggleERWiz = vi.fn(() => Promise.resolve())
8282
const mockProceedToRouteAndStep = vi.fn()
83+
const mockHandleMotionRouting = vi.fn(() => Promise.resolve())
8384
const mockRouteUpdateActions = {
8485
proceedToRouteAndStep: mockProceedToRouteAndStep,
86+
handleMotionRouting: mockHandleMotionRouting,
8587
} as any
8688
const mockMakeToast = vi.fn()
8789
const mockResumeRecovery = vi.fn()
90+
const mockHomePipetteZAxes = vi.fn(() => Promise.resolve())
8891

8992
beforeEach(() => {
9093
props = {
@@ -96,6 +99,7 @@ describe('RecoverySplash', () => {
9699
resumeRecovery: mockResumeRecovery,
97100
} as any,
98101
resumePausedRecovery: true,
102+
recoveryCommands: { homePipetteZAxes: mockHomePipetteZAxes } as any,
99103
}
100104

101105
vi.mocked(StepInfo).mockReturnValue(<div>MOCK STEP INFO</div>)
@@ -162,6 +166,13 @@ describe('RecoverySplash', () => {
162166
await waitFor(() => {
163167
expect(mockToggleERWiz).toHaveBeenCalledWith(true, true)
164168
})
169+
170+
expect(mockHandleMotionRouting).toHaveBeenNthCalledWith(1, true)
171+
expect(mockHandleMotionRouting).toHaveBeenNthCalledWith(2, false)
172+
173+
await waitFor(() => {
174+
expect(props.recoveryCommands.homePipetteZAxes).toHaveBeenCalled()
175+
})
165176
})
166177

167178
it('should render a door open toast if the door is open', () => {

0 commit comments

Comments
 (0)