Skip to content

Commit

Permalink
fix(protocol-designer): get labware dropdown from current deck state (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jerader authored Aug 22, 2023
1 parent aa7666e commit 8071826
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@
margin-top: 0.5rem;
font-size: var(--fs-body-1);
overflow: hidden;
white-space: nowrap;
white-space: pre-wrap;
text-overflow: ellipsis;
}

Expand Down
10 changes: 5 additions & 5 deletions protocol-designer/src/localization/en/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@
"touchTip": { "label": "touch tip" },
"moduleActionLabware": { "label": "module" },
"moduleLabwarePrefix": {
"magneticModuleType": "MAG",
"temperatureModuleType": "TEMP",
"thermocyclerModuleType": "THERMO",
"heaterShakerModuleType": "HS",
"magneticBlockType": "MAG"
"magneticModuleType": "Magnetic Module",
"temperatureModuleType": "Temperature Module",
"thermocyclerModuleType": "Thermocycler",
"heaterShakerModuleType": "Heater-Shaker",
"magneticBlockType": "Magnetic Block"
},
"magnetAction": {
"label": "Magnet action",
Expand Down
89 changes: 83 additions & 6 deletions protocol-designer/src/ui/labware/__tests__/selectors.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {
HEATERSHAKER_MODULE_TYPE,
HEATERSHAKER_MODULE_V1,
MAGNETIC_MODULE_TYPE,
MAGNETIC_MODULE_V1,
TEMPERATURE_MODULE_TYPE,
Expand Down Expand Up @@ -144,7 +146,13 @@ describe('labware selectors', () => {
}
expect(
// @ts-expect-error(sa, 2021-6-15): resultFunc
getLabwareOptions.resultFunc(labwareEntities, names, initialDeckSetup)
getLabwareOptions.resultFunc(
labwareEntities,
names,
initialDeckSetup,
{},
{}
)
).toEqual([
{ name: 'Source Plate', value: 'wellPlateId' },
{ name: 'Trash', value: 'fixedTrash' },
Expand Down Expand Up @@ -172,7 +180,8 @@ describe('labware selectors', () => {
labwareEntities,
names,
initialDeckSetup,
presavedStepForm
presavedStepForm,
{}
)
).toEqual([
{ name: 'Opentrons Tip Rack 10 µL', value: 'tiprack10Id' },
Expand All @@ -197,6 +206,11 @@ describe('labware selectors', () => {
id: 'tcPlateId',
slot: 'thermocyclerId', // On thermocycler
},
hsPlateId: {
...otherLabware.wellPlateId,
id: 'hsPlateId',
slot: 'heaterShakerId', // On heater-shaker
},
}
const labwareEntities = { ...trash, ...labware }
const initialDeckSetup = {
Expand Down Expand Up @@ -224,6 +238,12 @@ describe('labware selectors', () => {
model: THERMOCYCLER_MODULE_V1,
slot: SPAN7_8_10_11_SLOT,
},
heaterShakerId: {
id: 'heaterShakerId',
type: HEATERSHAKER_MODULE_TYPE,
model: HEATERSHAKER_MODULE_V1,
slot: '6',
},
},
}

Expand All @@ -232,19 +252,76 @@ describe('labware selectors', () => {
wellPlateId: 'Well Plate',
tempPlateId: 'Temp Plate',
tcPlateId: 'TC Plate',
hsPlateId: 'HS Plate',
}

expect(
// @ts-expect-error(sa, 2021-6-15): resultFunc
getLabwareOptions.resultFunc(
labwareEntities,
nicknames,
initialDeckSetup,
{},
{}
)
).toEqual([
{ name: 'HS Plate in Heater-Shaker', value: 'hsPlateId' },
{ name: 'TC Plate in Thermocycler', value: 'tcPlateId' },
{ name: 'Temp Plate in Temperature Module', value: 'tempPlateId' },
{ name: 'Well Plate in Magnetic Module', value: 'wellPlateId' },
{ name: 'Trash', value: 'fixedTrash' },
])
})

it('should return labware options with a labware moved off of the initial module slot', () => {
const labware = {
wellPlateId: {
...otherLabware.wellPlateId,
slot: 'magModuleId', // On magnetic module
},
}
const labwareEntities = { ...trash, ...labware }
const initialDeckSetup = {
pipettes: {},
labware: {
...trash,
...labware,
},
modules: {
magModuleId: {
id: 'magModuleId',
type: MAGNETIC_MODULE_TYPE,
model: MAGNETIC_MODULE_V1,
slot: '1',
},
},
}

const nicknames: Record<string, string> = {
...names,
wellPlateId: 'Well Plate',
}
const mockId = 'mockId'

const savedStep = {
[mockId]: {
stepType: 'moveLabware',
id: mockId,
labware: 'wellPlateId',
newLocation: '2',
},
}

expect(
// @ts-expect-error(sa, 2021-6-15): resultFunc
getLabwareOptions.resultFunc(
labwareEntities,
nicknames,
initialDeckSetup
initialDeckSetup,
savedStep
)
).toEqual([
{ name: 'MAG Well Plate', value: 'wellPlateId' },
{ name: 'TEMP Temp Plate', value: 'tempPlateId' },
{ name: 'THERMO TC Plate', value: 'tcPlateId' },
{ name: 'Well Plate in Magnetic Module', value: 'wellPlateId' },
{ name: 'Trash', value: 'fixedTrash' },
])
})
Expand Down
33 changes: 23 additions & 10 deletions protocol-designer/src/ui/labware/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,14 @@ export const getLabwareOptions: Selector<Options> = createSelector(
getLabwareNicknamesById,
stepFormSelectors.getInitialDeckSetup,
stepFormSelectors.getPresavedStepForm,
(labwareEntities, nicknamesById, initialDeckSetup, presavedStepForm) => {
stepFormSelectors.getSavedStepForms,
(
labwareEntities,
nicknamesById,
initialDeckSetup,
presavedStepForm,
savedStepForms
) => {
const moveLabwarePresavedStep = presavedStepForm?.stepType === 'moveLabware'
const options = reduce(
labwareEntities,
Expand All @@ -56,15 +63,21 @@ export const getLabwareOptions: Selector<Options> = createSelector(
const isAdapterOrAluminumBlock =
isAdapter ||
labwareEntity.def.metadata.displayCategory === 'aluminumBlock'
const moduleOnDeck = getModuleUnderLabware(initialDeckSetup, labwareId)
const prefix = moduleOnDeck
? i18n.t(
`form.step_edit_form.field.moduleLabwarePrefix.${moduleOnDeck.type}`
)
: null
const nickName = prefix
? `${prefix} ${nicknamesById[labwareId]}`
: nicknamesById[labwareId]
const moduleOnDeck = getModuleUnderLabware(
initialDeckSetup,
savedStepForms ?? {},
labwareId
)
const module =
moduleOnDeck != null
? i18n.t(
`form.step_edit_form.field.moduleLabwarePrefix.${moduleOnDeck.type}`
)
: null
const nickName =
module != null
? `${nicknamesById[labwareId]} in ${module}`
: nicknamesById[labwareId]

if (!moveLabwarePresavedStep) {
return getIsTiprack(labwareEntity.def) || isAdapter
Expand Down
26 changes: 21 additions & 5 deletions protocol-designer/src/ui/modules/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import {
ModuleType,
} from '@opentrons/shared-data'
import { Options } from '@opentrons/components'
import {
import type {
ModuleOnDeck,
LabwareOnDeck,
InitialDeckSetup,
} from '../../step-forms/types'
import type { SavedStepFormState } from '../../step-forms'

export function getModuleOnDeckByType(
initialDeckSetup: InitialDeckSetup,
type: ModuleType
Expand All @@ -29,11 +31,25 @@ export function getLabwareOnModule(
}
export function getModuleUnderLabware(
initialDeckSetup: InitialDeckSetup,
savedStepFormState: SavedStepFormState,
labwareId: string
): ModuleOnDeck | null | undefined {
// latest moveLabware step related to labwareId
const moveLabwareStep = Object.values(savedStepFormState)
.filter(
state =>
state.stepType === 'moveLabware' &&
labwareId != null &&
state.labware === labwareId
)
.reverse()[0]
const newLocation = moveLabwareStep?.newLocation

return values(initialDeckSetup.modules).find(
(moduleOnDeck: ModuleOnDeck) =>
initialDeckSetup.labware[labwareId]?.slot === moduleOnDeck.id
(newLocation != null
? newLocation
: initialDeckSetup.labware[labwareId]?.slot) === moduleOnDeck.id
)
}
export function getModuleLabwareOptions(
Expand All @@ -44,21 +60,21 @@ export function getModuleLabwareOptions(
const moduleOnDeck = getModuleOnDeckByType(initialDeckSetup, type)
const labware =
moduleOnDeck && getLabwareOnModule(initialDeckSetup, moduleOnDeck.id)
const prefix = i18n.t(`form.step_edit_form.field.moduleLabwarePrefix.${type}`)
const module = i18n.t(`form.step_edit_form.field.moduleLabwarePrefix.${type}`)
let options: Options = []

if (moduleOnDeck) {
if (labware) {
options = [
{
name: `${prefix} ${nicknamesById[labware.id]}`,
name: `${nicknamesById[labware.id]} in ${module}`,
value: moduleOnDeck.id,
},
]
} else {
options = [
{
name: `${prefix} No labware on module`,
name: `${module} No labware on module`,
value: moduleOnDeck.id,
},
]
Expand Down

0 comments on commit 8071826

Please sign in to comment.