Skip to content

Commit

Permalink
fix(app,components): include moved labware in deck config conflict check
Browse files Browse the repository at this point in the history
adds a helper to check for moveLabware commands that use a new slot. use the helper in determining
compatibility with the existing deck config. this fixes a bug where the app wasn't surfacing a
conflict with a moveLabware command moving to a slot occupied by a trash.

closes RAUT-967
  • Loading branch information
brenthagen committed Feb 16, 2024
1 parent d94d485 commit 8790bc8
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/src/resources/deck_configuration/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getTopMostLabwareInSlots } from '@opentrons/components'
import { getInitialAndMovedLabwareInSlots } from '@opentrons/components'
import { useDeckConfigurationQuery } from '@opentrons/react-api-client'
import {
FLEX_ROBOT_TYPE,
Expand Down Expand Up @@ -43,7 +43,9 @@ export function useDeckConfigurationCompatibility(
? getAddressableAreasInProtocol(protocolAnalysis, deckDef)
: []
const labwareInSlots =
protocolAnalysis != null ? getTopMostLabwareInSlots(protocolAnalysis) : []
protocolAnalysis != null
? getInitialAndMovedLabwareInSlots(protocolAnalysis)
: []

const protocolModulesInfo =
protocolAnalysis != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { getInitialLoadedLabwareByAdapter } from './getInitiallyLoadedLabwareByA
import type {
CompletedProtocolAnalysis,
LoadLabwareRunTimeCommand,
MoveLabwareRunTimeCommand,
ProtocolAnalysisOutput,
LabwareDefinition2,
} from '@opentrons/shared-data'
Expand All @@ -13,6 +14,82 @@ interface LabwareInSlot {
location: { slotName: string }
}

export const getInitialAndMovedLabwareInSlots = (
protocolAnalysis: CompletedProtocolAnalysis | ProtocolAnalysisOutput
): LabwareInSlot[] => {
const { commands } = protocolAnalysis
const initialLoadedLabwareByAdapter = getInitialLoadedLabwareByAdapter(

Check warning on line 21 in components/src/hardware-sim/ProtocolDeck/utils/getLabwareInSlots.ts

View check run for this annotation

Codecov / codecov/patch

components/src/hardware-sim/ProtocolDeck/utils/getLabwareInSlots.ts#L20-L21

Added lines #L20 - L21 were not covered by tests
commands
)
const topMostLabwareInSlots = getTopMostLabwareInSlots(protocolAnalysis)

Check warning on line 24 in components/src/hardware-sim/ProtocolDeck/utils/getLabwareInSlots.ts

View check run for this annotation

Codecov / codecov/patch

components/src/hardware-sim/ProtocolDeck/utils/getLabwareInSlots.ts#L24

Added line #L24 was not covered by tests

return commands

Check warning on line 26 in components/src/hardware-sim/ProtocolDeck/utils/getLabwareInSlots.ts

View check run for this annotation

Codecov / codecov/patch

components/src/hardware-sim/ProtocolDeck/utils/getLabwareInSlots.ts#L26

Added line #L26 was not covered by tests
.filter(
(command): command is MoveLabwareRunTimeCommand =>
command.commandType === 'moveLabware'

Check warning on line 29 in components/src/hardware-sim/ProtocolDeck/utils/getLabwareInSlots.ts

View check run for this annotation

Codecov / codecov/patch

components/src/hardware-sim/ProtocolDeck/utils/getLabwareInSlots.ts#L29

Added line #L29 was not covered by tests
)
.reduce<LabwareInSlot[]>((acc, command) => {
const labwareId = command.params.labwareId
const location = command.params.newLocation

Check warning on line 33 in components/src/hardware-sim/ProtocolDeck/utils/getLabwareInSlots.ts

View check run for this annotation

Codecov / codecov/patch

components/src/hardware-sim/ProtocolDeck/utils/getLabwareInSlots.ts#L32-L33

Added lines #L32 - L33 were not covered by tests

const originalLabware = topMostLabwareInSlots.find(
labware => labware.labwareId === labwareId

Check warning on line 36 in components/src/hardware-sim/ProtocolDeck/utils/getLabwareInSlots.ts

View check run for this annotation

Codecov / codecov/patch

components/src/hardware-sim/ProtocolDeck/utils/getLabwareInSlots.ts#L35-L36

Added lines #L35 - L36 were not covered by tests
)
const labwareDef = originalLabware?.labwareDef

Check warning on line 38 in components/src/hardware-sim/ProtocolDeck/utils/getLabwareInSlots.ts

View check run for this annotation

Codecov / codecov/patch

components/src/hardware-sim/ProtocolDeck/utils/getLabwareInSlots.ts#L38

Added line #L38 was not covered by tests

if (
location === 'offDeck' ||
'moduleId' in location ||
'labwareId' in location
)
return acc

Check warning on line 45 in components/src/hardware-sim/ProtocolDeck/utils/getLabwareInSlots.ts

View check run for this annotation

Codecov / codecov/patch

components/src/hardware-sim/ProtocolDeck/utils/getLabwareInSlots.ts#L45

Added line #L45 was not covered by tests
if (labwareId == null) {
console.warn('expected to find labware id but could not')
return acc

Check warning on line 48 in components/src/hardware-sim/ProtocolDeck/utils/getLabwareInSlots.ts

View check run for this annotation

Codecov / codecov/patch

components/src/hardware-sim/ProtocolDeck/utils/getLabwareInSlots.ts#L47-L48

Added lines #L47 - L48 were not covered by tests
}
if (labwareDef == null) {
console.warn(

Check warning on line 51 in components/src/hardware-sim/ProtocolDeck/utils/getLabwareInSlots.ts

View check run for this annotation

Codecov / codecov/patch

components/src/hardware-sim/ProtocolDeck/utils/getLabwareInSlots.ts#L51

Added line #L51 was not covered by tests
`expected to find labware def for labware id ${String(
labwareId
)} but could not`
)
return acc

Check warning on line 56 in components/src/hardware-sim/ProtocolDeck/utils/getLabwareInSlots.ts

View check run for this annotation

Codecov / codecov/patch

components/src/hardware-sim/ProtocolDeck/utils/getLabwareInSlots.ts#L56

Added line #L56 was not covered by tests
}

const slotName =
'addressableAreaName' in location
? location.addressableAreaName
: location.slotName

// if list of labware already includes slotName, return acc
if (acc.find(labware => labware.location.slotName === slotName) != null) {
return acc

Check warning on line 66 in components/src/hardware-sim/ProtocolDeck/utils/getLabwareInSlots.ts

View check run for this annotation

Codecov / codecov/patch

components/src/hardware-sim/ProtocolDeck/utils/getLabwareInSlots.ts#L66

Added line #L66 was not covered by tests
}

const labwareInAdapter = initialLoadedLabwareByAdapter[labwareId]

Check warning on line 69 in components/src/hardware-sim/ProtocolDeck/utils/getLabwareInSlots.ts

View check run for this annotation

Codecov / codecov/patch

components/src/hardware-sim/ProtocolDeck/utils/getLabwareInSlots.ts#L69

Added line #L69 was not covered by tests

// NOTE: only grabbing the labware on top most layer so
// either the adapter or the labware but not both
const topLabwareDefinition =
labwareInAdapter?.result?.definition ?? labwareDef
const topLabwareId = labwareInAdapter?.result?.labwareId ?? labwareId
const topLabwareNickName =
labwareInAdapter?.params?.displayName ??
originalLabware?.labwareNickName ??
null

return [

Check warning on line 81 in components/src/hardware-sim/ProtocolDeck/utils/getLabwareInSlots.ts

View check run for this annotation

Codecov / codecov/patch

components/src/hardware-sim/ProtocolDeck/utils/getLabwareInSlots.ts#L81

Added line #L81 was not covered by tests
...acc,
{
labwareId: topLabwareId,
labwareDef: topLabwareDefinition,
labwareNickName: topLabwareNickName,
location: { slotName },
},
]
}, topMostLabwareInSlots)
}

export const getTopMostLabwareInSlots = (
protocolAnalysis: CompletedProtocolAnalysis | ProtocolAnalysisOutput
): LabwareInSlot[] => {
Expand Down

0 comments on commit 8790bc8

Please sign in to comment.