Skip to content

Commit e63686b

Browse files
authored
fix(app): Fix tip selection during Error Recovery (#16659)
Closes RQA-3472
1 parent 1a7b61d commit e63686b

File tree

2 files changed

+20
-51
lines changed

2 files changed

+20
-51
lines changed

app/src/organisms/ErrorRecoveryFlows/hooks/__tests__/useFailedLabwareUtils.test.tsx

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
getRelevantWellName,
88
getRelevantFailedLabwareCmdFrom,
99
useRelevantFailedLwLocations,
10-
useInitialSelectedLocationsFrom,
1110
} from '../useFailedLabwareUtils'
1211
import { DEFINED_ERROR_TYPES } from '../../constants'
1312

@@ -242,22 +241,3 @@ describe('useRelevantFailedLwLocations', () => {
242241
expect(result.current.newLoc).toStrictEqual({ slotName: 'C2' })
243242
})
244243
})
245-
246-
describe('useInitialSelectedLocationsFrom', () => {
247-
it('updates result if the relevant command changes', () => {
248-
const cmd = { commandType: 'pickUpTip', params: { wellName: 'A1' } } as any
249-
const cmd2 = { commandType: 'pickUpTip', params: { wellName: 'A2' } } as any
250-
251-
const { result, rerender } = renderHook((cmd: any) =>
252-
useInitialSelectedLocationsFrom(cmd)
253-
)
254-
255-
rerender(cmd)
256-
257-
expect(result.current).toStrictEqual({ A1: null })
258-
259-
rerender(cmd2)
260-
261-
expect(result.current).toStrictEqual({ A2: null })
262-
})
263-
})

app/src/organisms/ErrorRecoveryFlows/hooks/useFailedLabwareUtils.ts

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useMemo, useState } from 'react'
1+
import { useEffect, useMemo, useState } from 'react'
22
import without from 'lodash/without'
33
import { useTranslation } from 'react-i18next'
44

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

214-
const initialLocs = useInitialSelectedLocationsFrom(
215-
recentRelevantFailedLabwareCmd
216-
)
217-
218-
// Set the initial locs when they first become available or update.
219-
if (selectedLocs !== initialLocs) {
220-
setSelectedLocs(initialLocs)
221-
}
214+
// Note that while other commands may have a wellName associated with them,
215+
// we are only interested in wells for the purposes of tip picking up.
216+
// Support state updates if the underlying well data changes, since this data is lazily retrieved and may change shortly
217+
// after Error Recovery launches.
218+
const initialWellName =
219+
recentRelevantFailedLabwareCmd != null &&
220+
recentRelevantFailedLabwareCmd.commandType === 'pickUpTip'
221+
? recentRelevantFailedLabwareCmd.params.wellName
222+
: null
223+
useEffect(() => {
224+
if (
225+
recentRelevantFailedLabwareCmd != null &&
226+
recentRelevantFailedLabwareCmd.commandType === 'pickUpTip'
227+
) {
228+
setSelectedLocs({
229+
[recentRelevantFailedLabwareCmd.params.wellName]: null,
230+
})
231+
}
232+
}, [initialWellName])
222233

223234
const deselectTips = (locations: string[]): void => {
224235
setSelectedLocs(prevLocs =>
@@ -253,28 +264,6 @@ function useTipSelectionUtils(
253264
}
254265
}
255266

256-
// Set the initial well selection to be the last pickup tip location for the pipette used in the failed command.
257-
export function useInitialSelectedLocationsFrom(
258-
recentRelevantFailedLabwareCmd: FailedCommandRelevantLabware
259-
): WellGroup | null {
260-
const [initialWells, setInitialWells] = useState<WellGroup | null>(null)
261-
262-
// Note that while other commands may have a wellName associated with them,
263-
// we are only interested in wells for the purposes of tip picking up.
264-
// Support state updates if the underlying data changes, since this data is lazily loaded and may change shortly
265-
// after Error Recovery launches.
266-
if (
267-
recentRelevantFailedLabwareCmd != null &&
268-
recentRelevantFailedLabwareCmd.commandType === 'pickUpTip' &&
269-
(initialWells == null ||
270-
!(recentRelevantFailedLabwareCmd.params.wellName in initialWells))
271-
) {
272-
setInitialWells({ [recentRelevantFailedLabwareCmd.params.wellName]: null })
273-
}
274-
275-
return initialWells
276-
}
277-
278267
// Get the name of the relevant labware relevant to the failed command, if any.
279268
export function getFailedCmdRelevantLabware(
280269
protocolAnalysis: ErrorRecoveryFlowsProps['protocolAnalysis'],

0 commit comments

Comments
 (0)