Skip to content

Commit 369a096

Browse files
committed
fix bug with swapping labware on an adapter
1 parent 9ec832f commit 369a096

File tree

4 files changed

+71
-21
lines changed

4 files changed

+71
-21
lines changed

protocol-designer/cypress/support/SetupSteps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export enum SetupLocators {
153153
TempdeckTempInput = 'input[name="targetTemperature"]',
154154
}
155155

156-
export const chooseDeckSlot = (
156+
const chooseDeckSlot = (
157157
slot: string
158158
): Cypress.Chainable<JQuery<HTMLElement>> => {
159159
const deckSlots: Record<

protocol-designer/src/pages/Designer/DeckSetup/AdapterControls.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ interface AdapterControlsProps extends SharedControlsType {
2727
// the adapter's labwareId
2828
labwareId: string
2929
onDeck: boolean
30+
swapBlocked: boolean
3031
handleDragHover?: () => void
3132
}
3233

@@ -45,6 +46,7 @@ export const AdapterControls = (
4546
itemId,
4647
isSelected,
4748
tab,
49+
swapBlocked,
4850
} = props
4951
const { t } = useTranslation(['deck', 'starting_deck_state'])
5052
const customLabwareDefs = useSelector(
@@ -80,9 +82,9 @@ export const AdapterControls = (
8082
const adapterLabwareIsMatch =
8183
draggedDef.stackingOffsetWithLabware?.[adapterLoadName] != null
8284

83-
return adapterLabwareIsMatch || isCustomLabware
85+
return (adapterLabwareIsMatch || isCustomLabware) && !swapBlocked
8486
}
85-
return true
87+
return !swapBlocked
8688
},
8789
drop: (item: DroppedItem) => {
8890
const droppedLabware = item
@@ -120,10 +122,11 @@ export const AdapterControls = (
120122
: false
121123

122124
const isSlotBlocked =
123-
isOver &&
124-
draggedDef != null &&
125-
draggedDef.stackingOffsetWithLabware?.[adapterLoadName] == null &&
126-
!isCustomLabware
125+
swapBlocked ||
126+
(isOver &&
127+
draggedDef != null &&
128+
draggedDef.stackingOffsetWithLabware?.[adapterLoadName] == null &&
129+
!isCustomLabware)
127130

128131
drop(ref)
129132

protocol-designer/src/pages/Designer/DeckSetup/DeckSetupDetails.tsx

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ import { HighlightLabware } from '../HighlightLabware'
3030
import { SlotOverflowMenu } from './SlotOverflowMenu'
3131
import { HoveredItems } from './HoveredItems'
3232
import { SelectedHoveredItems } from './SelectedHoveredItems'
33-
import { getAdjacentLabware, getSwapBlocked } from './utils'
33+
import {
34+
getAdjacentLabware,
35+
getSwapBlockedAdapter,
36+
getSwapBlockedModule,
37+
} from './utils'
3438
import { SlotWarning } from './SlotWarning'
3539
import { HighlightItems } from './HighlightItems'
3640
import { SlotControls } from './SlotControls'
@@ -113,11 +117,16 @@ export function DeckSetupDetails(props: DeckSetupDetailsProps): JSX.Element {
113117
LabwareOnDeckType | null | undefined
114118
>(null)
115119
const customLabwareDefs = useSelector(getCustomLabwareDefsByURI)
116-
const swapBlocked = getSwapBlocked({
117-
hoveredLabware,
118-
draggedLabware,
120+
const swapBlockedModule = getSwapBlockedModule({
119121
modulesById: activeDeckSetup.modules,
120122
customLabwareDefs,
123+
hoveredLabware,
124+
draggedLabware,
125+
})
126+
const swapBlockedAdapter = getSwapBlockedAdapter({
127+
labwareById: activeDeckSetup.labware,
128+
hoveredLabware,
129+
draggedLabware,
121130
})
122131

123132
const handleHoverEmptySlot = useCallback(() => {
@@ -279,6 +288,7 @@ export function DeckSetupDetails(props: DeckSetupDetailsProps): JSX.Element {
279288
{isAdapter ? (
280289
<AdapterControls
281290
itemId={slotId}
291+
swapBlocked={swapBlockedAdapter}
282292
hover={hover}
283293
onDeck={false}
284294
setHover={setHover}
@@ -302,7 +312,7 @@ export function DeckSetupDetails(props: DeckSetupDetailsProps): JSX.Element {
302312
setHoveredLabware={setHoveredLabware}
303313
setDraggedLabware={setDraggedLabware}
304314
swapBlocked={
305-
swapBlocked &&
315+
(swapBlockedModule || swapBlockedAdapter) &&
306316
(labwareLoadedOnModule.id === hoveredLabware?.id ||
307317
labwareLoadedOnModule.id === draggedLabware?.id)
308318
}
@@ -422,6 +432,7 @@ export function DeckSetupDetails(props: DeckSetupDetailsProps): JSX.Element {
422432
{labwareIsAdapter ? (
423433
<AdapterControls
424434
tab={tab}
435+
swapBlocked={swapBlockedAdapter}
425436
itemId={labware.slot}
426437
hover={hover}
427438
onDeck={true}
@@ -445,7 +456,7 @@ export function DeckSetupDetails(props: DeckSetupDetailsProps): JSX.Element {
445456
setHover={setHover}
446457
setShowMenuListForId={setShowMenuListForId}
447458
swapBlocked={
448-
swapBlocked &&
459+
(swapBlockedModule || swapBlockedAdapter) &&
449460
(labware.id === hoveredLabware?.id ||
450461
labware.id === draggedLabware?.id)
451462
}
@@ -511,7 +522,7 @@ export function DeckSetupDetails(props: DeckSetupDetailsProps): JSX.Element {
511522
setHover={setHover}
512523
setShowMenuListForId={setShowMenuListForId}
513524
swapBlocked={
514-
swapBlocked &&
525+
(swapBlockedModule || swapBlockedAdapter) &&
515526
(labware.id === hoveredLabware?.id ||
516527
labware.id === draggedLabware?.id)
517528
}

protocol-designer/src/pages/Designer/DeckSetup/utils.ts

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ import {
1515
} from '@opentrons/shared-data'
1616

1717
import { getStagingAreaAddressableAreas } from '../../../utils'
18+
import {
19+
getLabwareIsCompatible,
20+
getLabwareIsCustom,
21+
} from '../../../utils/labwareModuleCompatibility'
1822
import {
1923
FLEX_MODULE_MODELS,
2024
OT2_MODULE_MODELS,
@@ -40,10 +44,6 @@ import type {
4044
LabwareOnDeck,
4145
} from '../../../step-forms'
4246
import type { Fixture } from './constants'
43-
import {
44-
getLabwareIsCompatible,
45-
getLabwareIsCustom,
46-
} from '../../../utils/labwareModuleCompatibility'
4747

4848
const OT2_TC_SLOTS = ['7', '8', '10', '11']
4949
const FLEX_TC_SLOTS = ['A1', 'B1']
@@ -342,14 +342,14 @@ export function useDeckSetupWindowBreakPoint(): BreakPoint {
342342
return size
343343
}
344344

345-
export interface SwapBlockedArgs {
345+
export interface SwapBlockedModuleArgs {
346346
modulesById: InitialDeckSetup['modules']
347347
customLabwareDefs: LabwareDefByDefURI
348348
hoveredLabware?: LabwareOnDeck | null
349349
draggedLabware?: LabwareOnDeck | null
350350
}
351351

352-
export const getSwapBlocked = (args: SwapBlockedArgs): boolean => {
352+
export const getSwapBlockedModule = (args: SwapBlockedModuleArgs): boolean => {
353353
const {
354354
hoveredLabware,
355355
draggedLabware,
@@ -375,7 +375,7 @@ export const getSwapBlocked = (args: SwapBlockedArgs): boolean => {
375375
hoveredLabware
376376
)
377377

378-
// dragging custom labware to module gives not compat error
378+
// dragging custom labware to module gives no compat error
379379
const labwareSourceToDestBlocked = sourceModuleType
380380
? !getLabwareIsCompatible(hoveredLabware.def, sourceModuleType) &&
381381
!hoveredLabwareIsCustom
@@ -387,3 +387,39 @@ export const getSwapBlocked = (args: SwapBlockedArgs): boolean => {
387387

388388
return labwareSourceToDestBlocked || labwareDestToSourceBlocked
389389
}
390+
391+
export interface SwapBlockedAdapterArgs {
392+
labwareById: InitialDeckSetup['labware']
393+
hoveredLabware?: LabwareOnDeck | null
394+
draggedLabware?: LabwareOnDeck | null
395+
}
396+
397+
export const getSwapBlockedAdapter = (
398+
args: SwapBlockedAdapterArgs
399+
): boolean => {
400+
const { hoveredLabware, draggedLabware, labwareById } = args
401+
402+
if (!hoveredLabware || !draggedLabware) {
403+
return false
404+
}
405+
406+
const adapterSourceToDestLoadname: string | null =
407+
labwareById[draggedLabware.slot]?.def.parameters.loadName ?? null
408+
const adapterDestToSourceLoadname: string | null =
409+
labwareById[hoveredLabware.slot]?.def.parameters.loadName ?? null
410+
411+
const labwareSourceToDestBlocked =
412+
adapterSourceToDestLoadname != null
413+
? hoveredLabware.def.stackingOffsetWithLabware?.[
414+
adapterSourceToDestLoadname
415+
] == null
416+
: false
417+
const labwareDestToSourceBlocked =
418+
adapterDestToSourceLoadname != null
419+
? draggedLabware.def.stackingOffsetWithLabware?.[
420+
adapterDestToSourceLoadname
421+
] == null
422+
: false
423+
424+
return labwareSourceToDestBlocked || labwareDestToSourceBlocked
425+
}

0 commit comments

Comments
 (0)