Skip to content

Commit

Permalink
fix(app): Fix double drop tip prompting after Error Recovery cancel a…
Browse files Browse the repository at this point in the history
…ction (#17316)

This commit brings the `lastRunCommandPromptedErrorRecovery` util back and adds the new and improved behavior to also check if Error Recovery is enabled (in settings). If it's not enabled, we need to run tip detection even if the last run command was recoverable.
  • Loading branch information
mjhuff authored Jan 21, 2025
1 parent 9c70751 commit 0da7b99
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 5 deletions.
1 change: 1 addition & 0 deletions app/src/local-resources/commands/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './getCommandTextData'
export * from './lastRunCommandPromptedErrorRecovery'
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { RunCommandSummary } from '@opentrons/api-client'
// Whether the last run protocol command prompted Error Recovery, if Error Recovery is enabled.
export function lastRunCommandPromptedErrorRecovery(
summary: RunCommandSummary[] | null,
isEREnabled: boolean
): boolean {
const lastProtocolCommand = summary?.findLast(
command => command.intent !== 'fixit' && command.error != null
)
// All recoverable protocol commands have defined errors.
return isEREnabled ? lastProtocolCommand?.error?.isDefined ?? false : false
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@ import { useEffect } from 'react'

import { RUN_STATUS_IDLE, RUN_STATUS_STOPPED } from '@opentrons/api-client'
import { FLEX_ROBOT_TYPE, OT2_ROBOT_TYPE } from '@opentrons/shared-data'
import { useErrorRecoverySettings } from '@opentrons/react-api-client'

import { useDropTipWizardFlows } from '/app/organisms/DropTipWizardFlows'
import { useProtocolDropTipModal } from '../modals'
import { useCloseCurrentRun, useIsRunCurrent } from '/app/resources/runs'
import {
useCloseCurrentRun,
useCurrentRunCommands,
useIsRunCurrent,
} from '/app/resources/runs'
import { isTerminalRunStatus } from '../../utils'
import { useTipAttachmentStatus } from '/app/resources/instruments'
import { lastRunCommandPromptedErrorRecovery } from '/app/local-resources/commands'

import type { RobotType } from '@opentrons/shared-data'
import type { Run, RunStatus } from '@opentrons/api-client'
Expand Down Expand Up @@ -99,17 +105,33 @@ export function useRunHeaderDropTip({
: { showDTWiz: false, dtWizProps: null }
}

const { data } = useErrorRecoverySettings()
const isEREnabled = data?.data.enabled ?? true
const runSummaryNoFixit = useCurrentRunCommands(
{
includeFixitCommands: false,
pageLength: 1,
},
{ enabled: isTerminalRunStatus(runStatus) }
)

// Manage tip checking
useEffect(() => {
// If a user begins a new run without navigating away from the run page, reset tip status.
if (robotType === FLEX_ROBOT_TYPE) {
if (runStatus === RUN_STATUS_IDLE) {
resetTipStatus()
} else if (isRunCurrent && isTerminalRunStatus(runStatus)) {
}
// Only run tip checking if it wasn't *just* handled during Error Recovery.
else if (
!lastRunCommandPromptedErrorRecovery(runSummaryNoFixit, isEREnabled) &&
isRunCurrent &&
isTerminalRunStatus(runStatus)
) {
void determineTipStatus()
}
}
}, [runStatus, robotType, isRunCurrent])
}, [runStatus, robotType, isRunCurrent, runSummaryNoFixit, isEREnabled])

// If the run terminates with a "stopped" status, close the run if no tips are attached after running tip check at least once.
// This marks the robot as "not busy" if drop tip CTAs are unnecessary.
Expand Down
16 changes: 14 additions & 2 deletions app/src/pages/ODD/RunSummary/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
useProtocolQuery,
useDeleteRunMutation,
useRunCommandErrors,
useErrorRecoverySettings,
} from '@opentrons/react-api-client'
import { useRunControls } from '/app/organisms/RunTimeControl/hooks'
import { onDeviceDisplayFormatTimestamp } from '/app/transformations/runs'
Expand All @@ -65,9 +66,11 @@ import {
useRunCreatedAtTimestamp,
useCloseCurrentRun,
EMPTY_TIMESTAMP,
useCurrentRunCommands,
} from '/app/resources/runs'
import { handleTipsAttachedModal } from '/app/organisms/DropTipWizardFlows'
import { useTipAttachmentStatus } from '/app/resources/instruments'
import { lastRunCommandPromptedErrorRecovery } from '/app/local-resources/commands'

import type { IconName } from '@opentrons/components'
import type { OnDeviceRouteParams } from '/app/App/types'
Expand Down Expand Up @@ -233,10 +236,19 @@ export function RunSummary(): JSX.Element {
runId,
runRecord: runRecord ?? null,
})
const { data } = useErrorRecoverySettings()
const isEREnabled = data?.data.enabled ?? true
const runSummaryNoFixit = useCurrentRunCommands({
includeFixitCommands: false,
pageLength: 1,
})

useEffect(() => {
void determineTipStatus()
}, [])
// Only run tip checking if it wasn't *just* handled during Error Recovery.
if (!lastRunCommandPromptedErrorRecovery(runSummaryNoFixit, isEREnabled)) {
void determineTipStatus()
}
}, [isRunCurrent, runSummaryNoFixit, isEREnabled])

const returnToQuickTransfer = (): void => {
closeCurrentRunIfValid(() => {
Expand Down

0 comments on commit 0da7b99

Please sign in to comment.