Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(protocol-designer): get labware location from current step index #17297

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading