Skip to content

Commit

Permalink
refactor(app): return the LabwareLocation for the failed labware
Browse files Browse the repository at this point in the history
  • Loading branch information
mjhuff committed Oct 22, 2024
1 parent 4d1e3e5 commit e551948
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ const TestWrapper = (props: GetRelevantLwLocationsParams) => {
const displayLocation = useRelevantFailedLwLocations(props)
return (
<>
<div>{`Current Loc: ${displayLocation.currentLoc}`}</div>
<div>{`New Loc: ${displayLocation.newLoc}`}</div>
<div>{`Current Loc: ${displayLocation.displayNameCurrentLoc}`}</div>
<div>{`New Loc: ${displayLocation.displayNameNewLoc}`}</div>
</>
)
}
Expand Down
36 changes: 25 additions & 11 deletions app/src/organisms/ErrorRecoveryFlows/hooks/useFailedLabwareUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import type {
DispenseRunTimeCommand,
LiquidProbeRunTimeCommand,
MoveLabwareRunTimeCommand,
LabwareLocation,
} from '@opentrons/shared-data'
import type { LabwareDisplayLocationSlotOnly } from '/app/local-resources/labware'
import type { ErrorRecoveryFlowsProps } from '..'
Expand All @@ -40,8 +41,10 @@ interface UseFailedLabwareUtilsProps {
}

interface RelevantFailedLabwareLocations {
currentLoc: string
newLoc: string | null
displayNameCurrentLoc: string
displayNameNewLoc: string | null
currentLoc: LabwareLocation | null
newLoc: LabwareLocation | null
}

export type UseFailedLabwareUtilsResult = UseTipSelectionUtilsResult & {
Expand All @@ -53,6 +56,7 @@ export type UseFailedLabwareUtilsResult = UseTipSelectionUtilsResult & {
relevantWellName: string | null
/* The user-content nickname of the failed labware, if any */
failedLabwareNickname: string | null
/* Details relating to the labware location. */
failedLabwareLocations: RelevantFailedLabwareLocations
}

Expand Down Expand Up @@ -360,25 +364,35 @@ export function useRelevantFailedLwLocations({
isOnDevice: false, // Always return the "slot XYZ" copy, which is the desktop copy.
}

const currentLocation = getLabwareDisplayLocation({
const displayNameCurrentLoc = getLabwareDisplayLocation({
...BASE_DISPLAY_PARAMS,
location: failedLabware?.location ?? null,
})

const getNewLocation = (): string | null => {
const getNewLocation = (): Pick<
RelevantFailedLabwareLocations,
'displayNameNewLoc' | 'newLoc'
> => {
switch (failedCommandByRunRecord?.commandType) {
case 'moveLabware':
return getLabwareDisplayLocation({
...BASE_DISPLAY_PARAMS,
location: failedCommandByRunRecord.params.newLocation,
})
return {
displayNameNewLoc: getLabwareDisplayLocation({
...BASE_DISPLAY_PARAMS,
location: failedCommandByRunRecord.params.newLocation,
}),
newLoc: failedCommandByRunRecord.params.newLocation,
}
default:
return null
return {
displayNameNewLoc: null,
newLoc: null,
}
}
}

return {
currentLoc: currentLocation,
newLoc: getNewLocation(),
displayNameCurrentLoc,
currentLoc: failedLabware?.location ?? null,
...getNewLocation(),
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ export function LeftColumnLabwareInfo({
failedLabwareNickname,
failedLabwareLocations,
} = failedLabwareUtils
const { newLoc, currentLoc } = failedLabwareLocations
const { displayNameNewLoc, displayNameCurrentLoc } = failedLabwareLocations

const buildNewLocation = (): React.ComponentProps<
typeof InterventionContent
>['infoProps']['newLocationProps'] =>
newLoc != null ? { deckLabel: newLoc.toUpperCase() } : undefined
displayNameNewLoc != null
? { deckLabel: displayNameNewLoc.toUpperCase() }
: undefined

return (
<InterventionContent
Expand All @@ -36,7 +38,9 @@ export function LeftColumnLabwareInfo({
type,
labwareName: failedLabwareName ?? '',
labwareNickname: failedLabwareNickname ?? '',
currentLocationProps: { deckLabel: currentLoc.toUpperCase() },
currentLocationProps: {
deckLabel: displayNameCurrentLoc.toUpperCase(),
},
newLocationProps: buildNewLocation(),
}}
notificationProps={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('LeftColumnLabwareInfo', () => {
})

it('does not include newLocationProps when newLoc is not provided', () => {
props.failedLabwareUtils.failedLabwareLocations.newLoc = null
props.failedLabwareUtils.failedLabwareLocations.displayNameNewLoc = null
render(props)

expect(vi.mocked(InterventionContent)).toHaveBeenCalledWith(
Expand All @@ -91,8 +91,8 @@ describe('LeftColumnLabwareInfo', () => {

it('converts location labels to uppercase', () => {
props.failedLabwareUtils.failedLabwareLocations = {
currentLoc: 'slot A1',
newLoc: 'slot B2',
displayNameCurrentLoc: 'slot A1',
displayNameNewLoc: 'slot B2',
}
render(props)

Expand Down

0 comments on commit e551948

Please sign in to comment.