Skip to content

Commit

Permalink
fix(app): Fix tip selection during Error Recovery (#16659)
Browse files Browse the repository at this point in the history
Closes RQA-3472
  • Loading branch information
mjhuff authored Nov 1, 2024
1 parent 1a7b61d commit e63686b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
getRelevantWellName,
getRelevantFailedLabwareCmdFrom,
useRelevantFailedLwLocations,
useInitialSelectedLocationsFrom,
} from '../useFailedLabwareUtils'
import { DEFINED_ERROR_TYPES } from '../../constants'

Expand Down Expand Up @@ -242,22 +241,3 @@ describe('useRelevantFailedLwLocations', () => {
expect(result.current.newLoc).toStrictEqual({ slotName: 'C2' })
})
})

describe('useInitialSelectedLocationsFrom', () => {
it('updates result if the relevant command changes', () => {
const cmd = { commandType: 'pickUpTip', params: { wellName: 'A1' } } as any
const cmd2 = { commandType: 'pickUpTip', params: { wellName: 'A2' } } as any

const { result, rerender } = renderHook((cmd: any) =>
useInitialSelectedLocationsFrom(cmd)
)

rerender(cmd)

expect(result.current).toStrictEqual({ A1: null })

rerender(cmd2)

expect(result.current).toStrictEqual({ A2: null })
})
})
51 changes: 20 additions & 31 deletions app/src/organisms/ErrorRecoveryFlows/hooks/useFailedLabwareUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMemo, useState } from 'react'
import { useEffect, useMemo, useState } from 'react'
import without from 'lodash/without'
import { useTranslation } from 'react-i18next'

Expand Down Expand Up @@ -211,14 +211,25 @@ function useTipSelectionUtils(
): UseTipSelectionUtilsResult {
const [selectedLocs, setSelectedLocs] = useState<WellGroup | null>(null)

const initialLocs = useInitialSelectedLocationsFrom(
recentRelevantFailedLabwareCmd
)

// Set the initial locs when they first become available or update.
if (selectedLocs !== initialLocs) {
setSelectedLocs(initialLocs)
}
// Note that while other commands may have a wellName associated with them,
// we are only interested in wells for the purposes of tip picking up.
// Support state updates if the underlying well data changes, since this data is lazily retrieved and may change shortly
// after Error Recovery launches.
const initialWellName =
recentRelevantFailedLabwareCmd != null &&
recentRelevantFailedLabwareCmd.commandType === 'pickUpTip'
? recentRelevantFailedLabwareCmd.params.wellName
: null
useEffect(() => {
if (
recentRelevantFailedLabwareCmd != null &&
recentRelevantFailedLabwareCmd.commandType === 'pickUpTip'
) {
setSelectedLocs({
[recentRelevantFailedLabwareCmd.params.wellName]: null,
})
}
}, [initialWellName])

const deselectTips = (locations: string[]): void => {
setSelectedLocs(prevLocs =>
Expand Down Expand Up @@ -253,28 +264,6 @@ function useTipSelectionUtils(
}
}

// Set the initial well selection to be the last pickup tip location for the pipette used in the failed command.
export function useInitialSelectedLocationsFrom(
recentRelevantFailedLabwareCmd: FailedCommandRelevantLabware
): WellGroup | null {
const [initialWells, setInitialWells] = useState<WellGroup | null>(null)

// Note that while other commands may have a wellName associated with them,
// we are only interested in wells for the purposes of tip picking up.
// Support state updates if the underlying data changes, since this data is lazily loaded and may change shortly
// after Error Recovery launches.
if (
recentRelevantFailedLabwareCmd != null &&
recentRelevantFailedLabwareCmd.commandType === 'pickUpTip' &&
(initialWells == null ||
!(recentRelevantFailedLabwareCmd.params.wellName in initialWells))
) {
setInitialWells({ [recentRelevantFailedLabwareCmd.params.wellName]: null })
}

return initialWells
}

// Get the name of the relevant labware relevant to the failed command, if any.
export function getFailedCmdRelevantLabware(
protocolAnalysis: ErrorRecoveryFlowsProps['protocolAnalysis'],
Expand Down

0 comments on commit e63686b

Please sign in to comment.