Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(app): Wire up Error Recovery flows on desktop #15560

Merged
merged 13 commits into from
Jul 2, 2024
Prev Previous commit
Next Next commit
WIP LegacyStyledText and merge issues
  • Loading branch information
TamarZanzouri committed Jul 2, 2024
commit 602c8fcf23bbfea5ea8a805225ed83d4d7ad48c7
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
})

it('returns true if on the ODD', () => {
const { result } = renderHook(() => useRunPausedSplash(), { wrapper })
const { result } = renderHook(() => useRunPausedSplash(isOnDevice=true, showERWizard=true), { wrapper })

Check failure on line 38 in app/src/organisms/ErrorRecoveryFlows/__tests__/RunPausedSplash.test.tsx

View workflow job for this annotation

GitHub Actions / js checks

Cannot find name 'isOnDevice'. Did you mean 'getIsOnDevice'?

Check failure on line 38 in app/src/organisms/ErrorRecoveryFlows/__tests__/RunPausedSplash.test.tsx

View workflow job for this annotation

GitHub Actions / js checks

Cannot find name 'showERWizard'.

Check failure on line 38 in app/src/organisms/ErrorRecoveryFlows/__tests__/RunPausedSplash.test.tsx

View workflow job for this annotation

GitHub Actions / js checks

Arrow function should not return assignment

Check failure on line 38 in app/src/organisms/ErrorRecoveryFlows/__tests__/RunPausedSplash.test.tsx

View workflow job for this annotation

GitHub Actions / js checks

Arrow function should not return assignment

Check failure on line 38 in app/src/organisms/ErrorRecoveryFlows/__tests__/RunPausedSplash.test.tsx

View workflow job for this annotation

GitHub Actions / js checks

Cannot find name 'isOnDevice'. Did you mean 'getIsOnDevice'?

Check failure on line 38 in app/src/organisms/ErrorRecoveryFlows/__tests__/RunPausedSplash.test.tsx

View workflow job for this annotation

GitHub Actions / js checks

Cannot find name 'showERWizard'.

Check failure on line 38 in app/src/organisms/ErrorRecoveryFlows/__tests__/RunPausedSplash.test.tsx

View workflow job for this annotation

GitHub Actions / js checks

Arrow function should not return assignment

Check failure on line 38 in app/src/organisms/ErrorRecoveryFlows/__tests__/RunPausedSplash.test.tsx

View workflow job for this annotation

GitHub Actions / js checks

Arrow function should not return assignment
expect(result.current).toEqual(true)
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ describe('useRecoveryCommands', () => {
failedCommand: mockFailedCommand,
failedLabwareUtils: mockFailedLabwareUtils,
routeUpdateActions: mockRouteUpdateActions,
recoveryToastUtils: {} as any,
})
)

Expand All @@ -85,7 +84,7 @@ describe('useRecoveryCommands', () => {
failedCommand: mockFailedCommand,
failedLabwareUtils: mockFailedLabwareUtils,
routeUpdateActions: mockRouteUpdateActions,
recoveryToastUtils: {} as any,

})
)

Expand All @@ -112,7 +111,6 @@ describe('useRecoveryCommands', () => {
failedCommand: mockFailedCommand,
failedLabwareUtils: mockFailedLabwareUtils,
routeUpdateActions: mockRouteUpdateActions,
recoveryToastUtils: {} as any,
})
)

Expand All @@ -133,7 +131,6 @@ describe('useRecoveryCommands', () => {
failedCommand: mockFailedCommand,
failedLabwareUtils: mockFailedLabwareUtils,
routeUpdateActions: mockRouteUpdateActions,
recoveryToastUtils: { makeSuccessToast: mockMakeSuccessToast } as any,
})
)

Expand All @@ -152,7 +149,6 @@ describe('useRecoveryCommands', () => {
failedCommand: mockFailedCommand,
failedLabwareUtils: mockFailedLabwareUtils,
routeUpdateActions: mockRouteUpdateActions,
recoveryToastUtils: {} as any,
})
)

Expand All @@ -168,7 +164,6 @@ describe('useRecoveryCommands', () => {
failedCommand: mockFailedCommand,
failedLabwareUtils: mockFailedLabwareUtils,
routeUpdateActions: mockRouteUpdateActions,
recoveryToastUtils: {} as any,
})
)

Expand Down Expand Up @@ -207,7 +202,6 @@ describe('useRecoveryCommands', () => {
failedLabware: mockFailedLabware,
},
routeUpdateActions: mockRouteUpdateActions,
recoveryToastUtils: {} as any,
})
)

Expand All @@ -228,7 +222,6 @@ describe('useRecoveryCommands', () => {
failedCommand: mockFailedCommand,
failedLabwareUtils: mockFailedLabwareUtils,
routeUpdateActions: mockRouteUpdateActions,
recoveryToastUtils: {} as any,
})
)

Expand All @@ -249,7 +242,6 @@ describe('useRecoveryCommands', () => {
failedCommand: mockFailedCommand,
failedLabwareUtils: mockFailedLabwareUtils,
routeUpdateActions: mockRouteUpdateActions,
recoveryToastUtils: {} as any,
})
)

Expand Down
20 changes: 5 additions & 15 deletions app/src/organisms/ErrorRecoveryFlows/hooks/useERUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
} from '../../../resources/runs'
import { useRecoveryOptionCopy } from './useRecoveryOptionCopy'
import { useRunningStepCounts } from '../../../resources/protocols/hooks'
import { useRecoveryToasts } from './useRecoveryToasts'

import type { PipetteData } from '@opentrons/api-client'
import type { IRecoveryMap } from '../types'
Expand All @@ -29,7 +28,6 @@ import type { StepCounts } from '../../../resources/protocols/hooks'
type ERUtilsProps = ErrorRecoveryFlowsProps & {
toggleERWizard: (launchER: boolean) => Promise<void>
hasLaunchedRecovery: boolean
isOnDevice: boolean
}

export interface ERUtilsResults {
Expand All @@ -56,7 +54,6 @@ export function useERUtils({
toggleERWizard,
hasLaunchedRecovery,
protocolAnalysis,
isOnDevice,
}: ERUtilsProps): ERUtilsResults {
const { data: attachedInstruments } = useInstrumentsQuery()
const { data: runRecord } = useNotifyRunQuery(runId)
Expand All @@ -70,22 +67,13 @@ export function useERUtils({
pageLength: 999,
})

const stepCounts = useRunningStepCounts(runId, runCommands)
const commandAfterFailedCommand = getNextStep(failedCommand, protocolAnalysis)

const {
recoveryMap,
setRM,
trackExternalMap,
currentRecoveryOptionUtils,
} = useRecoveryRouting()

const recoveryToastUtils = useRecoveryToasts({
currentStepCount: stepCounts.currentStepNumber,
selectedRecoveryOption: currentRecoveryOptionUtils.selectedRecoveryOption,
isOnDevice,
})

const tipStatusUtils = useRecoveryTipStatus({
runId,
isFlex,
Expand Down Expand Up @@ -119,7 +107,6 @@ export function useERUtils({
failedCommand,
failedLabwareUtils,
routeUpdateActions,
recoveryToastUtils,
})

const recoveryMapUtils = useRecoveryMapUtils({
Expand All @@ -129,6 +116,9 @@ export function useERUtils({
failedLabwareUtils,
})

const stepCounts = useRunningStepCounts(runId, runCommands)
const commandAfterFailedCommand = getNextStep(failedCommand, protocolAnalysis)

// TODO(jh, 06-14-24): Ensure other string build utilities that are internal to ErrorRecoveryFlows are exported under
// one utility object in useERUtils.
const getRecoveryOptionCopy = useRecoveryOptionCopy()
Expand All @@ -146,6 +136,6 @@ export function useERUtils({
recoveryMapUtils,
getRecoveryOptionCopy,
stepCounts,
commandAfterFailedCommand,
commandAfterFailedCommand
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,17 @@ import type { WellGroup } from '@opentrons/components'
import type { FailedCommand } from '../types'
import type { UseFailedLabwareUtilsResult } from './useFailedLabwareUtils'
import type { UseRouteUpdateActionsResult } from './useRouteUpdateActions'
import type { RecoveryToasts } from './useRecoveryToasts'

interface UseRecoveryCommandsParams {
runId: string
failedCommand: FailedCommand | null
failedLabwareUtils: UseFailedLabwareUtilsResult
routeUpdateActions: UseRouteUpdateActionsResult
recoveryToastUtils: RecoveryToasts
}
export interface UseRecoveryCommandsResult {
/* A terminal recovery command that causes ER to exit as the run status becomes "running" */
resumeRun: () => void
/* A terminal recovery command that causes ER to exit when the run status becomes "cancelled". ER still renders while
* in a "stop-requested" state */
/* A terminal recovery command that causes ER to exit as the run status becomes "stop-requested" */
cancelRun: () => void
/* A non-terminal recovery command, but should generally be chained with a resumeRun. */
skipFailedCommand: () => Promise<void>
Expand All @@ -47,15 +44,11 @@ export function useRecoveryCommands({
failedCommand,
failedLabwareUtils,
routeUpdateActions,
recoveryToastUtils,
}: UseRecoveryCommandsParams): UseRecoveryCommandsResult {
const { proceedToRouteAndStep } = routeUpdateActions
const { chainRunCommands } = useChainRunCommands(runId, failedCommand?.id)
const {
mutateAsync: resumeRunFromRecovery,
} = useResumeRunFromRecoveryMutation()
const { resumeRunFromRecovery } = useResumeRunFromRecoveryMutation()
const { stopRun } = useStopRunMutation()
const { makeSuccessToast } = recoveryToastUtils

const chainRunRecoveryCommands = React.useCallback(
(
Expand Down Expand Up @@ -103,10 +96,8 @@ export function useRecoveryCommands({
}, [chainRunRecoveryCommands, failedCommand, failedLabwareUtils])

const resumeRun = React.useCallback((): void => {
void resumeRunFromRecovery(runId).then(() => {
makeSuccessToast()
})
}, [runId, resumeRunFromRecovery, makeSuccessToast])
resumeRunFromRecovery(runId)
}, [runId, resumeRunFromRecovery])

const cancelRun = React.useCallback((): void => {
stopRun(runId)
Expand Down Expand Up @@ -169,4 +160,4 @@ export const buildPickUpTips = (
},
}
}
}
}
10 changes: 4 additions & 6 deletions app/src/organisms/ErrorRecoveryFlows/shared/StepInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@ import * as React from 'react'

import { useTranslation } from 'react-i18next'

import { Flex, DISPLAY_INLINE, StyledText } from '@opentrons/components'
import { Flex, DISPLAY_INLINE, LegacyStyledText } from '@opentrons/components'

import { CommandText } from '../../../molecules/Command'

import type { StyleProps } from '@opentrons/components'
import type { RecoveryContentProps } from '../types'

interface StepInfoProps extends StyleProps {
textStyle: React.ComponentProps<typeof StyledText>[
| 'desktopStyle'
| 'oddStyle']
textStyle: React.ComponentProps<typeof LegacyStyledText>['as']
stepCounts: RecoveryContentProps['stepCounts']
failedCommand: RecoveryContentProps['failedCommand']
robotType: RecoveryContentProps['robotType']
Expand All @@ -39,9 +37,9 @@ export function StepInfo({

return (
<Flex display={DISPLAY_INLINE} {...styleProps}>
<StyledText as={textStyle} display={DISPLAY_INLINE}>
<LegacyStyledText as={textStyle} display={DISPLAY_INLINE}>
{`${t('at_step')} ${currentCopy}/${totalCopy}: `}
</StyledText>
</LegacyStyledText>
{analysisCommand != null && protocolAnalysis != null ? (
<CommandText
command={analysisCommand}
Expand Down
Loading