Skip to content

Commit

Permalink
fix(app): fix stale well location in Error Recovery (#16628)
Browse files Browse the repository at this point in the history
Closes RQA-3438

The logic for determining the default well used during tip selection is calculated as soon as Error Recovery renders. After the initial well is determined, this state is set and then never updated for the remainder of Error Recovery. The current logic works well if there never has been a recentRelevantFailedLabwareCmd, however, if this is the 2nd+ instance of error recovery in the run, the recentRelevantFailedLabwareCmd is stale until the fetch for the newrecentRelevantFailedLabwareCmd completes.

Instead of gating the state setting behavior by whether or not there is a recentRelevantFailedLabwareCmd, we should gate it by whether the relevant data within recentRelevantFailedLabwareCmd has changed.
  • Loading branch information
mjhuff authored Oct 29, 2024
1 parent b27a22c commit 20ed43d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
getRelevantWellName,
getRelevantFailedLabwareCmdFrom,
useRelevantFailedLwLocations,
useInitialSelectedLocationsFrom,
} from '../useFailedLabwareUtils'
import { DEFINED_ERROR_TYPES } from '../../constants'

Expand Down Expand Up @@ -241,3 +242,22 @@ 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 })
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,9 @@ function useTipSelectionUtils(
const initialLocs = useInitialSelectedLocationsFrom(
recentRelevantFailedLabwareCmd
)
// Set the initial locs when they first become available.
if (selectedLocs == null && initialLocs != null) {

// Set the initial locs when they first become available or update.
if (selectedLocs !== initialLocs) {
setSelectedLocs(initialLocs)
}

Expand Down Expand Up @@ -253,17 +254,20 @@ function useTipSelectionUtils(
}

// Set the initial well selection to be the last pickup tip location for the pipette used in the failed command.
function useInitialSelectedLocationsFrom(
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
(initialWells == null ||
!(recentRelevantFailedLabwareCmd.params.wellName in initialWells))
) {
setInitialWells({ [recentRelevantFailedLabwareCmd.params.wellName]: null })
}
Expand Down

0 comments on commit 20ed43d

Please sign in to comment.