diff --git a/app/src/organisms/ErrorRecoveryFlows/hooks/__tests__/useFailedLabwareUtils.test.tsx b/app/src/organisms/ErrorRecoveryFlows/hooks/__tests__/useFailedLabwareUtils.test.tsx index a24afb09b29..b0716af5c8a 100644 --- a/app/src/organisms/ErrorRecoveryFlows/hooks/__tests__/useFailedLabwareUtils.test.tsx +++ b/app/src/organisms/ErrorRecoveryFlows/hooks/__tests__/useFailedLabwareUtils.test.tsx @@ -7,7 +7,6 @@ import { getRelevantWellName, getRelevantFailedLabwareCmdFrom, useRelevantFailedLwLocations, - useInitialSelectedLocationsFrom, } from '../useFailedLabwareUtils' import { DEFINED_ERROR_TYPES } from '../../constants' @@ -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 }) - }) -}) diff --git a/app/src/organisms/ErrorRecoveryFlows/hooks/useFailedLabwareUtils.ts b/app/src/organisms/ErrorRecoveryFlows/hooks/useFailedLabwareUtils.ts index 14372409c44..72969d884d4 100644 --- a/app/src/organisms/ErrorRecoveryFlows/hooks/useFailedLabwareUtils.ts +++ b/app/src/organisms/ErrorRecoveryFlows/hooks/useFailedLabwareUtils.ts @@ -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' @@ -211,14 +211,25 @@ function useTipSelectionUtils( ): UseTipSelectionUtilsResult { const [selectedLocs, setSelectedLocs] = useState(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 => @@ -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(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'],