Skip to content

Commit

Permalink
some more migrating trash bin away from labwareEntities
Browse files Browse the repository at this point in the history
  • Loading branch information
jerader committed Nov 17, 2023
1 parent ffba93f commit 5258535
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 105 deletions.
11 changes: 4 additions & 7 deletions protocol-designer/src/components/DeckSetup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import {
TRASH_BIN_ADAPTER_FIXTURE,
WASTE_CHUTE_CUTOUT,
} from '@opentrons/shared-data'
import { FLEX_TRASH_DEF_URI, OT_2_TRASH_DEF_URI } from '../../constants'
import { selectors as labwareDefSelectors } from '../../labware-defs'

import { selectors as featureFlagSelectors } from '../../feature-flags'
Expand Down Expand Up @@ -502,12 +501,10 @@ export const DeckSetup = (): JSX.Element => {
const _disableCollisionWarnings = useSelector(
featureFlagSelectors.getDisableModuleRestrictions
)
const trash = Object.values(activeDeckSetup.labware).find(
lw =>
lw.labwareDefURI === OT_2_TRASH_DEF_URI ||
lw.labwareDefURI === FLEX_TRASH_DEF_URI
const trash = Object.values(activeDeckSetup.additionalEquipmentOnDeck).find(
ae => ae.name === 'trashBin'
)
const trashSlot = trash?.slot
const trashSlot = trash?.location
const robotType = useSelector(getRobotType)
const dispatch = useDispatch()

Expand All @@ -526,7 +523,7 @@ export const DeckSetup = (): JSX.Element => {
})
const trashBinFixtures = [
{
cutoutId: trash?.slot as CutoutId,
cutoutId: trash?.location as CutoutId,
cutoutFixtureId: TRASH_BIN_ADAPTER_FIXTURE,
},
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import * as React from 'react'
import { useSelector } from 'react-redux'
import { DropdownField, DropdownOption, FormGroup } from '@opentrons/components'
import { FLEX_TRASH_DEF_URI, OT_2_TRASH_DEF_URI } from '../../../../constants'
import { i18n } from '../../../../localization'
import {
getAdditionalEquipmentEntities,
getLabwareEntities,
} from '../../../../step-forms/selectors'
import { getAdditionalEquipmentEntities } from '../../../../step-forms/selectors'
import { StepFormDropdown } from '../StepFormDropdownField'
import styles from '../../StepEditForm.css'

Expand All @@ -20,28 +16,25 @@ export function DropTipField(
onFieldFocus,
updateValue,
} = props
const labware = useSelector(getLabwareEntities)
const additionalEquipment = useSelector(getAdditionalEquipmentEntities)
const wasteChute = Object.values(additionalEquipment).find(
aE => aE.name === 'wasteChute'
)
const trash = Object.values(labware).find(
lw =>
lw.labwareDefURI === FLEX_TRASH_DEF_URI ||
lw.labwareDefURI === OT_2_TRASH_DEF_URI
const trashBin = Object.values(additionalEquipment).find(
aE => aE.name === 'trashBin'
)
const wasteChuteOption: DropdownOption = {
name: 'Waste Chute',
value: wasteChute?.id ?? '',
}
const trashOption: DropdownOption = {
name: 'Trash Bin',
value: trash?.id ?? '',
value: trashBin?.id ?? '',
}

const options: DropdownOption[] = []
if (wasteChute != null) options.push(wasteChuteOption)
if (trash != null) options.push(trashOption)
if (trashBin != null) options.push(trashOption)

const [selectedValue, setSelectedValue] = React.useState(
dropdownItem || (options[0] && options[0].value)
Expand Down
15 changes: 4 additions & 11 deletions protocol-designer/src/file-data/selectors/fileCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ import {
DEFAULT_MM_FROM_BOTTOM_DISPENSE,
DEFAULT_MM_TOUCH_TIP_OFFSET_FROM_TOP,
DEFAULT_MM_BLOWOUT_OFFSET_FROM_TOP,
OT_2_TRASH_DEF_URI,
FLEX_TRASH_DEF_URI,
} from '../../constants'
import { getFileMetadata, getRobotType } from './fileFields'
import { getInitialRobotState, getRobotStateTimeline } from './commands'
Expand Down Expand Up @@ -91,15 +89,10 @@ export const getLabwareDefinitionsInUse = (
])

return labwareDefURIsInUse.reduce<LabwareDefByDefURI>(
(acc, labwareDefURI: string) => {
if (
labwareDefURI !== FLEX_TRASH_DEF_URI &&
labwareDefURI !== OT_2_TRASH_DEF_URI
) {
acc[labwareDefURI] = allLabwareDefsByURI[labwareDefURI]
}
return acc
},
(acc, labwareDefURI: string) => ({
...acc,
[labwareDefURI]: allLabwareDefsByURI[labwareDefURI],
}),
{}
)
}
Expand Down
59 changes: 26 additions & 33 deletions protocol-designer/src/load-file/migration/8_0_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,23 @@ import {
OT2_STANDARD_DECKID,
OT2_STANDARD_MODEL,
} from '@opentrons/shared-data'
import { getOnlyLatestDefs } from '../../labware-defs'
import { uuid } from '../../utils'
import {
FLEX_TRASH_DEF_URI,
INITIAL_DECK_SETUP_STEP_ID,
OT_2_TRASH_DEF_URI,
} from '../../constants'
import type { ProtocolFileV7 } from '@opentrons/shared-data'
import { INITIAL_DECK_SETUP_STEP_ID } from '../../constants'
import type {
ProtocolFileV7,
MoveToAddressableAreaCreateCommand,
} from '@opentrons/shared-data'
import type {
CommandAnnotationV1Mixin,
CommandV8Mixin,
LabwareV2Mixin,
LiquidV1Mixin,
LoadLabwareCreateCommand,
OT2RobotMixin,
OT3RobotMixin,
ProtocolBase,
ProtocolFile,
} from '@opentrons/shared-data/protocol/types/schemaV8'
import type { LoadPipetteCreateCommand } from '@opentrons/shared-data/protocol/types/schemav7'
import type { DesignerApplicationData } from './utils/getLoadLiquidCommands'

// NOTE: this migration is to schema v8 and updates fixed trash by
Expand All @@ -46,37 +44,31 @@ export const migrateFile = (
const labwareLocationUpdate: LabwareLocationUpdate =
designerApplication.data.savedStepForms[INITIAL_DECK_SETUP_STEP_ID]
.labwareLocationUpdate
const allLatestDefs = getOnlyLatestDefs()

const robotType = robot.model
const trashSlot = robotType === FLEX_ROBOT_TYPE ? 'A3' : '12'
const trashDefUri =
robotType === FLEX_ROBOT_TYPE ? FLEX_TRASH_DEF_URI : OT_2_TRASH_DEF_URI
const trashAddressableArea =
robotType === FLEX_ROBOT_TYPE ? 'moveableTrashA3' : 'fixedTrash'

const trashDefinition = allLatestDefs[trashDefUri]
const trashId = `${uuid()}:${trashDefUri}`
const pipetteId = Object.values(commands).find(
(command): command is LoadPipetteCreateCommand =>
command.commandType === 'loadPipette'
)?.params.pipetteId

const trashLoadCommand = [
const trashMoveToAddressableAreaCommand: MoveToAddressableAreaCreateCommand[] = [
{
key: uuid(),
commandType: 'loadLabware',
commandType: 'moveToAddressableArea',
params: {
location: { slotName: trashSlot },
version: 1,
namespace: 'opentrons',
loadName: trashDefinition.parameters.loadName,
displayName: trashDefinition.metadata.displayName,
labwareId: trashId,
addressableAreaName: trashAddressableArea,
pipetteId: pipetteId ?? '',
},
},
] as LoadLabwareCreateCommand[]
]

const newLabwareLocationUpdate: LabwareLocationUpdate = Object.keys(
labwareLocationUpdate
).reduce((acc: LabwareLocationUpdate, labwareId: string) => {
if (labwareId === 'fixedTrash') {
acc[trashId] = trashSlot
} else {
if (labwareId !== 'fixedTrash') {
acc[labwareId] = labwareLocationUpdate[labwareId]
}
return acc
Expand All @@ -89,29 +81,31 @@ export const migrateFile = (
const sharedParams = {
blowout_location:
stepForm.blowout_location === 'fixedTrash'
? trashId
? trashAddressableArea
: stepForm.blowout_location,
dropTip_location: trashId,
dropTip_location: trashAddressableArea,
}

if (stepForm.stepType === 'moveLiquid') {
return {
...stepForm,
aspirate_labware:
stepForm.aspirate_labware === 'fixedTrash'
? trashId
? trashAddressableArea
: stepForm.aspirate_labware,
dispense_labware:
stepForm.dispense_labware === 'fixedTrash'
? trashId
? trashAddressableArea
: stepForm.dispense_labware,
...sharedParams,
}
} else if (stepForm.stepType === 'mix') {
return {
...stepForm,
labware:
stepForm.labware === 'fixedTrash' ? trashId : stepForm.labware,
stepForm.labware === 'fixedTrash'
? trashAddressableArea
: stepForm.labware,
...sharedParams,
}
}
Expand Down Expand Up @@ -173,7 +167,6 @@ export const migrateFile = (
const labwareV2Mixin: LabwareV2Mixin = {
labwareDefinitionSchemaId: 'opentronsLabwareSchemaV2',
labwareDefinitions: {
...{ [trashDefUri]: trashDefinition },
...appData.labwareDefinitions,
},
}
Expand All @@ -185,7 +178,7 @@ export const migrateFile = (

const commandv8Mixin: CommandV8Mixin = {
commandSchemaId: 'opentronsCommandSchemaV8',
commands: [...commands, ...trashLoadCommand],
commands: [...commands, ...trashMoveToAddressableAreaCommand],
}

const commandAnnotionaV1Mixin: CommandAnnotationV1Mixin = {
Expand Down
40 changes: 10 additions & 30 deletions protocol-designer/src/step-forms/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ import {
PipetteName,
THERMOCYCLER_MODULE_TYPE,
WASTE_CHUTE_ADDRESSABLE_AREAS,
getDeckDefFromRobotTypeV4,
AddressableAreaName,
CutoutId,
MOVABLE_TRASH_ADDRESSABLE_AREAS,
} from '@opentrons/shared-data'
import type { RootState as LabwareDefsRootState } from '../../labware-defs'
import { rootReducer as labwareDefsRootReducer } from '../../labware-defs'
import { uuid } from '../../utils'
import { getCutoutIdByAddressableArea, uuid } from '../../utils'
import { INITIAL_DECK_SETUP_STEP_ID, SPAN7_8_10_11_SLOT } from '../../constants'
import { getPDMetadata } from '../../file-types'
import {
Expand All @@ -50,8 +48,6 @@ import {
COLUMN_4_SLOTS,
NormalizedAdditionalEquipmentById,
NormalizedPipetteById,
OT_2_TRASH_DEF_URI,
FLEX_TRASH_DEF_URI,
} from '@opentrons/step-generation'
import { LoadFileAction } from '../../load-file'
import { SaveStepFormAction } from '../../ui/steps/actions/thunks'
Expand Down Expand Up @@ -1335,11 +1331,6 @@ export const additionalEquipmentInvariantProperties = handleActions<NormalizedAd
): NormalizedAdditionalEquipmentById => {
const { file } = action.payload
const isFlex = file.robot.model === FLEX_ROBOT_TYPE
const deckDef = getDeckDefFromRobotTypeV4(FLEX_ROBOT_TYPE)
const cutoutFixtures = deckDef.cutoutFixtures
const providesAddressableAreasForAddressableArea = cutoutFixtures.find(
cutoutFixture => cutoutFixture.id.includes('stagingAreaRightSlot')
)?.providesAddressableAreas

const hasGripperCommands = Object.values(file.commands).some(
(command): command is MoveLabwareCreateCommand =>
Expand Down Expand Up @@ -1392,26 +1383,13 @@ export const additionalEquipmentInvariantProperties = handleActions<NormalizedAd
]),
]

const findCutoutIdByAddressableArea = (
addressableAreaName: AddressableAreaName
): CutoutId | null => {
if (providesAddressableAreasForAddressableArea != null) {
for (const cutoutId in providesAddressableAreasForAddressableArea) {
if (
providesAddressableAreasForAddressableArea[
cutoutId as keyof typeof providesAddressableAreasForAddressableArea
].includes(addressableAreaName)
) {
return cutoutId as CutoutId
}
}
}
return null
}

const stagingAreas = stagingAreaSlotNames.reduce((acc, slot) => {
const stagingAreaId = `${uuid()}:stagingArea`
const cutoutId = findCutoutIdByAddressableArea(slot)
const cutoutId = getCutoutIdByAddressableArea(
slot,
'stagingAreaRightSlot',
isFlex ? FLEX_ROBOT_TYPE : OT2_ROBOT_TYPE
)
return {
...acc,
[stagingAreaId]: {
Expand All @@ -1434,8 +1412,10 @@ export const additionalEquipmentInvariantProperties = handleActions<NormalizedAd
trashBinCommand?.params.addressableAreaName

const trashBinId = `${uuid()}:trashBin`
const trashCutoutId = findCutoutIdByAddressableArea(
trashAddressableAreaName as AddressableAreaName
const trashCutoutId = getCutoutIdByAddressableArea(
trashAddressableAreaName as AddressableAreaName,
isFlex ? 'trashBinAdapter' : 'fixedTrashSlot',
isFlex ? FLEX_ROBOT_TYPE : OT2_ROBOT_TYPE
)
const trashBin =
trashAddressableAreaName != null
Expand Down
16 changes: 4 additions & 12 deletions protocol-designer/src/ui/labware/selectors.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { createSelector } from 'reselect'
import mapValues from 'lodash/mapValues'
import reduce from 'lodash/reduce'
import {
getIsTiprack,
getLabwareDisplayName,
getLabwareHasQuirk,
} from '@opentrons/shared-data'
import { getIsTiprack, getLabwareDisplayName } from '@opentrons/shared-data'
import {
AdditionalEquipmentEntity,
COLUMN_4_SLOTS,
Expand Down Expand Up @@ -164,7 +160,7 @@ export const getLabwareOptions: Selector<Options> = createSelector(
)

const trashOption: Options =
trash != null ? [{ name: TRASH, value: trash?.id }] : []
trash != null ? [{ name: TRASH, value: trash?.id ?? '' }] : []

const options = [...trashOption, ...labwareOptions]

Expand All @@ -178,17 +174,13 @@ export const getDisposalLabwareOptions: Selector<Options> = createSelector(
additionalEquipment =>
reduce(
additionalEquipment,
(
acc: Options,
additionalEquipment: AdditionalEquipmentEntity,
aeId
): Options =>
(acc: Options, additionalEquipment: AdditionalEquipmentEntity): Options =>
additionalEquipment.name === 'trashBin'
? [
...acc,
{
name: TRASH,
value: aeId,
value: additionalEquipment.location ?? '',
},
]
: acc,
Expand Down
Loading

0 comments on commit 5258535

Please sign in to comment.