Skip to content

Commit a8f9b4e

Browse files
authored
fix(protocol-designer): remove command references from 8_5_0 migration (#18862)
1 parent eb6823b commit a8f9b4e

File tree

2 files changed

+48
-63
lines changed

2 files changed

+48
-63
lines changed

protocol-designer/src/load-file/migration/8_5_0.ts

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import min from 'lodash/min'
44

55
import {
66
FLEX_ROBOT_TYPE,
7+
getAllLabwareDefs,
78
getPipetteSpecsV2,
89
POSITION_REFERENCE_BOTTOM,
910
POSITION_REFERENCE_TOP,
@@ -16,12 +17,10 @@ import {
1617
PROTOCOL_DESIGNER_SOURCE,
1718
} from '../../constants'
1819
import { getDefaultBlowoutFlowRate, getDefaultPushOutVolume } from '../../utils'
19-
import { getEquipmentLoadInfoFromCommands } from './utils/getEquipmentLoadInfoFromCommands'
2020
import { getMigratedPositionFromTop } from './utils/getMigrationPositionFromTop'
2121

2222
import type {
2323
LabwareDefinition2,
24-
LoadLabwareCreateCommand,
2524
PipetteV2Specs,
2625
ProtocolFile,
2726
} from '@opentrons/shared-data'
@@ -56,21 +55,25 @@ const getMigratedBlowoutLocation = (
5655
export const migrateFile = (
5756
appData: ProtocolFile<PDMetadata>
5857
): ProtocolFile<PDMetadata> => {
59-
const { designerApplication, commands, labwareDefinitions, robot } = appData
58+
const { designerApplication, robot, labwareDefinitions } = appData
6059
if (designerApplication == null || designerApplication?.data == null) {
6160
throw Error('The designerApplication key in your file is corrupt.')
6261
}
63-
const { savedStepForms, ingredients } = designerApplication.data
62+
const {
63+
savedStepForms,
64+
ingredients,
65+
labware,
66+
pipettes,
67+
} = designerApplication.data
6468
const { model: robotType } = robot
65-
const loadLabwareCommands = commands.filter(
66-
(command): command is LoadLabwareCreateCommand =>
67-
command.commandType === 'loadLabware'
68-
)
69-
const equipmentLoadInfoFromCommands = getEquipmentLoadInfoFromCommands(
70-
commands,
71-
labwareDefinitions
72-
)
7369

70+
const allLabwareDefsByURI =
71+
// read the labware definitions key first
72+
// otherwise map to all labware defs as a fallback
73+
// for OpentronsAI
74+
Object.values(labwareDefinitions).length > 0
75+
? labwareDefinitions
76+
: getAllLabwareDefs()
7477
const migratedIngredients: Ingredients = Object.entries(
7578
ingredients
7679
).reduce<Ingredients>((acc, [id, ingredient]) => {
@@ -127,19 +130,17 @@ export const migrateFile = (
127130
blowout_z_offset,
128131
...rest
129132
} = form
130-
const aspirateLabwareUri =
131-
equipmentLoadInfoFromCommands.labware[aspirate_labware].labwareDefURI
132-
const isAspirateLabwareTouchtipDisabled = labwareDefinitions[
133+
const aspirateLabwareUri = labware[aspirate_labware].labwareDefURI
134+
const isAspirateLabwareTouchtipDisabled = allLabwareDefsByURI[
133135
aspirateLabwareUri
134136
].parameters.quirks?.includes('touchTipDisabled')
135-
const dispenseLabwareUri =
136-
equipmentLoadInfoFromCommands.labware[dispense_labware]?.labwareDefURI
137+
const dispenseLabwareUri = labware[dispense_labware]?.labwareDefURI
137138

138139
const isDispenseLabwareTouchtipDisabled =
139140
// dispense is in a waste chute/trash bin
140-
labwareDefinitions[dispenseLabwareUri] == null
141+
allLabwareDefsByURI[dispenseLabwareUri] == null
141142
? true
142-
: labwareDefinitions[dispenseLabwareUri].parameters.quirks?.includes(
143+
: allLabwareDefsByURI[dispenseLabwareUri].parameters.quirks?.includes(
143144
'touchTipDisabled'
144145
)
145146

@@ -148,21 +149,19 @@ export const migrateFile = (
148149
firstTrashBinOrWasteChuteId
149150
)
150151
const matchingAspirateLabwareWellDepth = getMigratedPositionFromTop(
151-
labwareDefinitions,
152-
loadLabwareCommands,
152+
allLabwareDefsByURI,
153153
aspirate_labware as string,
154+
labware,
154155
'aspirate'
155156
)
156157
const matchingDispenseLabwareWellDepth = getMigratedPositionFromTop(
157-
labwareDefinitions,
158-
loadLabwareCommands,
158+
allLabwareDefsByURI,
159159
dispense_labware as string,
160+
labware,
160161
'dispense'
161162
)
162-
const tipRackDef = labwareDefinitions[form.tipRack]
163-
const pipetteName =
164-
equipmentLoadInfoFromCommands.pipettes?.[form.pipette]?.pipetteName ??
165-
null
163+
const tipRackDef = allLabwareDefsByURI[form.tipRack]
164+
const pipetteName = pipettes?.[form.pipette]?.pipetteName ?? null
166165
const pipetteSpecs =
167166
pipetteName != null ? getPipetteSpecsV2(pipetteName) : null
168167
const defaultPushOutVolume =
@@ -272,20 +271,17 @@ export const migrateFile = (
272271
const {
273272
id,
274273
mix_touchTip_mmFromBottom,
275-
labware,
274+
labware: formLabware,
276275
liquidClassesSupported,
277276
mix_touchTip_checkbox,
278277
...rest
279278
} = form
280-
const tipRackDef = labwareDefinitions[form.tipRack]
281-
const mixLabwareUri =
282-
equipmentLoadInfoFromCommands.labware[labware].labwareDefURI
283-
const isLabwareTouchtipDisabled = labwareDefinitions[
279+
const tipRackDef = allLabwareDefsByURI[form.tipRack]
280+
const mixLabwareUri = labware[formLabware].labwareDefURI
281+
const isLabwareTouchtipDisabled = allLabwareDefsByURI[
284282
mixLabwareUri
285283
].parameters.quirks?.includes('touchTipDisabled')
286-
const pipetteName =
287-
equipmentLoadInfoFromCommands.pipettes?.[form.pipette]?.pipetteName ??
288-
null
284+
const pipetteName = pipettes?.[form.pipette]?.pipetteName ?? null
289285
const pipetteSpecs =
290286
pipetteName != null ? getPipetteSpecsV2(pipetteName) : null
291287
const defaultPushOutVolume =
@@ -298,9 +294,9 @@ export const migrateFile = (
298294
)
299295

300296
const matchingLabwareWellDepth = getMigratedPositionFromTop(
301-
labwareDefinitions,
302-
loadLabwareCommands,
303-
labware as string,
297+
allLabwareDefsByURI,
298+
formLabware as string,
299+
labware,
304300
'mix'
305301
)
306302

@@ -321,7 +317,7 @@ export const migrateFile = (
321317
[id]: {
322318
...rest,
323319
id,
324-
labware,
320+
labware: formLabware,
325321
mix_touchTip_checkbox: isLabwareTouchtipDisabled
326322
? false
327323
: mix_touchTip_checkbox,

protocol-designer/src/load-file/migration/utils/getMigrationPositionFromTop.ts

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,33 @@
1-
import type {
2-
LabwareDefinition2,
3-
LoadLabwareCreateCommand,
4-
} from '@opentrons/shared-data'
1+
import type { LabwareDefinition2 } from '@opentrons/shared-data'
2+
import type { Labware } from '../../../file-types'
53
import type { MoveLiquidPrefixType } from '../../../resources/types'
64

75
export const getMigratedPositionFromTop = (
8-
labwareDefinitions: {
9-
[definitionId: string]: LabwareDefinition2
10-
},
11-
loadLabwareCommands: LoadLabwareCreateCommand[],
12-
labware: string,
6+
labwareDefsByURI: Record<string, LabwareDefinition2>,
7+
formLabwareId: string,
8+
labware: Labware,
139
type: MoveLiquidPrefixType
1410
): number => {
15-
const matchingLoadLabware = loadLabwareCommands.find(
16-
command =>
17-
command.commandType === 'loadLabware' &&
18-
command.params.labwareId === labware
19-
)
20-
if (matchingLoadLabware == null) {
11+
const labwareDefUri = labware[formLabwareId].labwareDefURI
12+
13+
if (labwareDefUri == null) {
2114
console.error(
22-
`expected to find matching ${type} labware load command but could not with ${type}_labware from form data as ${labware}`
15+
`unable to find matching labware def uri from form labware id ${formLabwareId}`
2316
)
2417
}
25-
const labwareUri =
26-
matchingLoadLabware != null
27-
? `${matchingLoadLabware.params.namespace}/${matchingLoadLabware.params.loadName}/${matchingLoadLabware.params.version}`
28-
: ''
2918

3019
// early exit for dispense_labware equaling trashBin or wasteChute
31-
if (labwareDefinitions[labwareUri] == null) {
20+
if (labwareDefsByURI[labwareDefUri] == null) {
3221
return 0
3322
}
3423

35-
const matchingLabwareWellDepth = labwareUri
36-
? labwareDefinitions[labwareUri].wells.A1.depth
24+
const matchingLabwareWellDepth = labwareDefUri
25+
? labwareDefsByURI[labwareDefUri].wells.A1.depth
3726
: 0
3827

3928
if (matchingLabwareWellDepth === 0) {
4029
console.error(
41-
`error in finding the ${type} labware well depth with labware uri ${labwareUri}`
30+
`error in finding the ${type} labware well depth with labware uri ${labwareDefUri}`
4231
)
4332
}
4433
return matchingLabwareWellDepth

0 commit comments

Comments
 (0)