Skip to content

Commit

Permalink
fix(protocol-designer): get labware location from current step index (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jerader authored Jan 17, 2025
1 parent a133e62 commit 95089e1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 22 deletions.
42 changes: 29 additions & 13 deletions protocol-designer/src/ui/labware/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '@opentrons/shared-data'
import * as stepFormSelectors from '../../step-forms/selectors'
import { selectors as labwareIngredSelectors } from '../../labware-ingred/selectors'
import { getLabwareLatestSlot } from './utils'
import { getLabwareLatestSlotFromCurrentStepIndex } from './utils'

import type {
LabwareEntity,
Expand Down Expand Up @@ -55,13 +55,15 @@ const getNickname = (
initialDeckSetup: AllTemporalPropertiesForTimelineFrame,
labwareId: string,
savedStepForms: SavedStepFormState,
robotType: RobotType
robotType: RobotType,
filteredSavedStepFormIds: string[]
): string => {
const latestSlot = getLabwareLatestSlot(
const latestSlot = getLabwareLatestSlotFromCurrentStepIndex(
initialDeckSetup,
savedStepForms ?? {},
labwareId,
robotType
robotType,
filteredSavedStepFormIds
)

let nickName: string = nicknamesById[labwareId]
Expand Down Expand Up @@ -131,7 +133,8 @@ export const getMoveLabwareOptions: Selector<DropdownOption[]> = createSelector(
initialDeckSetup,
labwareId,
savedStepForms,
robotType
robotType,
filteredSavedStepFormIds
)

// filter out moving trash, adapters, and labware in
Expand Down Expand Up @@ -161,13 +164,24 @@ export const getLabwareOptions: Selector<DropdownOption[]> = createSelector(
stepFormSelectors.getInitialDeckSetup,
stepFormSelectors.getSavedStepForms,
stepFormSelectors.getAdditionalEquipmentEntities,
stepFormSelectors.getUnsavedForm,
(
labwareEntities,
nicknamesById,
initialDeckSetup,
savedStepForms,
additionalEquipmentEntities
additionalEquipmentEntities,
unsavedForm
) => {
const savedFormKeys = Object.keys(savedStepForms)
const previouslySavedFormDataIndex = unsavedForm
? savedFormKeys.indexOf(unsavedForm.id)
: -1
const filteredSavedStepFormIds =
previouslySavedFormDataIndex !== -1
? savedFormKeys.slice(0, previouslySavedFormDataIndex)
: savedFormKeys

const wasteChuteLocation = Object.values(additionalEquipmentEntities).find(
aE => aE.name === 'wasteChute'
)?.location
Expand All @@ -184,12 +198,13 @@ export const getLabwareOptions: Selector<DropdownOption[]> = createSelector(
labwareEntity: LabwareEntity,
labwareId: string
): DropdownOption[] => {
const isLabwareInWasteChute = Object.values(savedStepForms).find(
form =>
form.stepType === 'moveLabware' &&
form.labware === labwareId &&
form.newLocation === wasteChuteLocation
)
const isLabwareInWasteChute =
filteredSavedStepFormIds.find(
id =>
savedStepForms[id].stepType === 'moveLabware' &&
savedStepForms[id].labware === labwareId &&
savedStepForms[id].newLocation === wasteChuteLocation
) != null

const isAdapter =
labwareEntity.def.allowedRoles?.includes('adapter') ?? false
Expand All @@ -198,7 +213,8 @@ export const getLabwareOptions: Selector<DropdownOption[]> = createSelector(
initialDeckSetup,
labwareId,
savedStepForms,
robotType
robotType,
filteredSavedStepFormIds
)

return getIsTiprack(labwareEntity.def) ||
Expand Down
20 changes: 11 additions & 9 deletions protocol-designer/src/ui/labware/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,27 @@ function resolveSlotLocation(
}
}

export function getLabwareLatestSlot(
export function getLabwareLatestSlotFromCurrentStepIndex(
initialDeckSetup: InitialDeckSetup,
savedStepForms: SavedStepFormState,
labwareId: string,
robotType: RobotType
robotType: RobotType,
filteredSavedStepFormIds: string[]
): string | null {
const { modules, labware, additionalEquipmentOnDeck } = initialDeckSetup
const initialSlot = labware[labwareId]?.slot
const hasWasteChute = getHasWasteChute(additionalEquipmentOnDeck)

// latest moveLabware step related to labwareId
const moveLabwareStep = Object.values(savedStepForms)
// latest moveLabware step related to labwareId at given index
const moveLabwareStepId = filteredSavedStepFormIds
.filter(
state =>
state.stepType === 'moveLabware' &&
labwareId != null &&
labwareId === state.labware
id =>
savedStepForms[id].stepType === 'moveLabware' &&
savedStepForms[id].labware === labwareId
)
.reverse()[0]
.pop()
const moveLabwareStep =
moveLabwareStepId != null ? savedStepForms[moveLabwareStepId] : null

if (
hasWasteChute &&
Expand Down

0 comments on commit 95089e1

Please sign in to comment.