Skip to content

Commit

Permalink
refactor(app): use the new hook in error recovery
Browse files Browse the repository at this point in the history
  • Loading branch information
mjhuff committed Nov 22, 2024
1 parent be544dc commit a8bc146
Showing 1 changed file with 13 additions and 21 deletions.
34 changes: 13 additions & 21 deletions app/src/organisms/ErrorRecoveryFlows/hooks/useRecoveryCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import head from 'lodash/head'
import {
useResumeRunFromRecoveryMutation,
useStopRunMutation,
useUpdateErrorRecoveryPolicy,
useResumeRunFromRecoveryAssumingFalsePositiveMutation,
} from '@opentrons/react-api-client'

import { useChainRunCommands } from '/app/resources/runs'
import {
useChainRunCommands,
useUpdateRecoveryPolicyWithStrategy,
} from '/app/resources/runs'
import { DEFINED_ERROR_TYPES, ERROR_KINDS, RECOVERY_MAP } from '../constants'
import { getErrorKind } from '/app/organisms/ErrorRecoveryFlows/utils'

Expand All @@ -23,12 +25,7 @@ import type {
PrepareToAspirateRunTimeCommand,
MoveLabwareParams,
} from '@opentrons/shared-data'
import type {
CommandData,
IfMatchType,
RecoveryPolicyRulesParams,
RunAction,
} from '@opentrons/api-client'
import type { CommandData, IfMatchType, RunAction } from '@opentrons/api-client'
import type { WellGroup } from '@opentrons/components'
import type { FailedCommand, RecoveryRoute, RouteStep } from '../types'
import type { UseFailedLabwareUtilsResult } from './useFailedLabwareUtils'
Expand All @@ -38,6 +35,7 @@ import type { UseRecoveryAnalyticsResult } from '/app/redux-resources/analytics'
import type { CurrentRecoveryOptionUtils } from './useRecoveryRouting'
import type { ErrorRecoveryFlowsProps } from '..'
import type { FailedCommandBySource } from './useRetainedFailedCommandBySource'
import type { UpdateErrorRecoveryPolicyWithStrategy } from '/app/resources/runs'

interface UseRecoveryCommandsParams {
runId: string
Expand Down Expand Up @@ -100,9 +98,7 @@ export function useRecoveryCommands({
mutateAsync: resumeRunFromRecoveryAssumingFalsePositive,
} = useResumeRunFromRecoveryAssumingFalsePositiveMutation()
const { stopRun } = useStopRunMutation()
const {
mutateAsync: updateErrorRecoveryPolicy,
} = useUpdateErrorRecoveryPolicy(runId)
const updateErrorRecoveryPolicy = useUpdateRecoveryPolicyWithStrategy(runId)
const { makeSuccessToast } = recoveryToastUtils

// TODO(jh, 11-21-24): Some commands return a 200 with an error body. We should catch these and propagate the error.
Expand Down Expand Up @@ -231,7 +227,7 @@ export function useRecoveryCommands({
ifMatch
)

return updateErrorRecoveryPolicy(ignorePolicyRules)
return updateErrorRecoveryPolicy(ignorePolicyRules, 'append')
.then(() => Promise.resolve())
.catch(() =>
Promise.reject(new Error('Failed to update recovery policy.'))
Expand Down Expand Up @@ -421,12 +417,8 @@ export const buildIgnorePolicyRules = (
commandType: FailedCommand['commandType'],
errorType: string,
ifMatch: IfMatchType
): RecoveryPolicyRulesParams => {
return [
{
commandType,
errorType,
ifMatch,
},
]
}
): UpdateErrorRecoveryPolicyWithStrategy['newPolicy'] => ({
commandType,
errorType,
ifMatch,
})

0 comments on commit a8bc146

Please sign in to comment.