Skip to content

Commit

Permalink
fix bug with slot and adapter controls
Browse files Browse the repository at this point in the history
  • Loading branch information
jerader committed Feb 13, 2024
1 parent f7a40fb commit 5448767
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
moveDeckItem,
openAddLabwareModal,
} from '../../../labware-ingred/actions'
import { getDeckSetupForActiveItem } from '../../../top-selectors/labware-locations'
import { selectors as labwareDefSelectors } from '../../../labware-defs'
import { START_TERMINAL_ITEM_ID, TerminalItemId } from '../../../steplist'
import { BlockedSlot } from './BlockedSlot'
Expand Down Expand Up @@ -54,13 +55,17 @@ export const AdapterControls = (
const customLabwareDefs = useSelector(

Check warning on line 55 in protocol-designer/src/components/DeckSetup/LabwareOverlays/AdapterControls.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/DeckSetup/LabwareOverlays/AdapterControls.tsx#L55

Added line #L55 was not covered by tests
labwareDefSelectors.getCustomLabwareDefsByURI
)

const activeDeckSetup = useSelector(getDeckSetupForActiveItem)
const labware = activeDeckSetup.labware
const ref = React.useRef(null)
const [newSlot, setSlot] = React.useState<string | null>(null)
const dispatch = useDispatch()

Check warning on line 62 in protocol-designer/src/components/DeckSetup/LabwareOverlays/AdapterControls.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/DeckSetup/LabwareOverlays/AdapterControls.tsx#L58-L62

Added lines #L58 - L62 were not covered by tests

const adapterName =
allLabware.find(labware => labware.id === labwareId)?.def.metadata
.displayName ?? ''

const [{ itemType, draggedItem, isOver }, drop] = useDrop(() => ({
const [{ itemType, draggedItem, isOver }, drop] = useDrop({

Check warning on line 68 in protocol-designer/src/components/DeckSetup/LabwareOverlays/AdapterControls.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/DeckSetup/LabwareOverlays/AdapterControls.tsx#L68

Added line #L68 was not covered by tests
accept: DND_TYPES.LABWARE,
canDrop: (item: DroppedItem) => {
const draggedDef = item.labwareOnDeck?.def
Expand All @@ -82,8 +87,12 @@ export const AdapterControls = (
return true

Check warning on line 87 in protocol-designer/src/components/DeckSetup/LabwareOverlays/AdapterControls.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/DeckSetup/LabwareOverlays/AdapterControls.tsx#L87

Added line #L87 was not covered by tests
},
drop: (item: DroppedItem) => {
if (item.labwareOnDeck) {
dispatch(moveDeckItem(item.labwareOnDeck.slot, labwareId))
const droppedLabware = item

Check warning on line 90 in protocol-designer/src/components/DeckSetup/LabwareOverlays/AdapterControls.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/DeckSetup/LabwareOverlays/AdapterControls.tsx#L90

Added line #L90 was not covered by tests
if (newSlot != null) {
dispatch(moveDeckItem(newSlot, labwareId))

Check warning on line 92 in protocol-designer/src/components/DeckSetup/LabwareOverlays/AdapterControls.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/DeckSetup/LabwareOverlays/AdapterControls.tsx#L92

Added line #L92 was not covered by tests
} else if (droppedLabware.labwareOnDeck != null) {
const droppedSlot = droppedLabware.labwareOnDeck.slot
dispatch(moveDeckItem(droppedSlot, labwareId))

Check warning on line 95 in protocol-designer/src/components/DeckSetup/LabwareOverlays/AdapterControls.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/DeckSetup/LabwareOverlays/AdapterControls.tsx#L94-L95

Added lines #L94 - L95 were not covered by tests
}
},
hover: () => {
Expand All @@ -96,7 +105,17 @@ export const AdapterControls = (
isOver: !!monitor.isOver(),
draggedItem: monitor.getItem() as DroppedItem,
}),
}))
})

const draggedLabware = Object.values(labware).find(
l => l.id === draggedItem?.labwareOnDeck?.id

Check warning on line 111 in protocol-designer/src/components/DeckSetup/LabwareOverlays/AdapterControls.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/DeckSetup/LabwareOverlays/AdapterControls.tsx#L110-L111

Added lines #L110 - L111 were not covered by tests
)

React.useEffect(() => {

Check warning on line 114 in protocol-designer/src/components/DeckSetup/LabwareOverlays/AdapterControls.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/DeckSetup/LabwareOverlays/AdapterControls.tsx#L114

Added line #L114 was not covered by tests
if (draggedLabware != null) {
setSlot(draggedLabware.slot)

Check warning on line 116 in protocol-designer/src/components/DeckSetup/LabwareOverlays/AdapterControls.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/DeckSetup/LabwareOverlays/AdapterControls.tsx#L116

Added line #L116 was not covered by tests
}
})

if (
selectedTerminalItemId !== START_TERMINAL_ITEM_ID ||
Expand Down Expand Up @@ -124,8 +143,10 @@ export const AdapterControls = (
slotBlocked = 'Labware incompatible with this adapter'
}

drop(ref)

Check warning on line 146 in protocol-designer/src/components/DeckSetup/LabwareOverlays/AdapterControls.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/DeckSetup/LabwareOverlays/AdapterControls.tsx#L146

Added line #L146 was not covered by tests

return (

Check warning on line 148 in protocol-designer/src/components/DeckSetup/LabwareOverlays/AdapterControls.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/DeckSetup/LabwareOverlays/AdapterControls.tsx#L148

Added line #L148 was not covered by tests
<g ref={drop}>
<g ref={ref}>
{slotBlocked ? (
<BlockedSlot
x={slotPosition[0]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
moveDeckItem,
openAddLabwareModal,
} from '../../../labware-ingred/actions'
import { getDeckSetupForActiveItem } from '../../../top-selectors/labware-locations'
import { selectors as labwareDefSelectors } from '../../../labware-defs'
import { START_TERMINAL_ITEM_ID, TerminalItemId } from '../../../steplist'
import { BlockedSlot } from './BlockedSlot'
Expand All @@ -34,7 +35,7 @@ interface SlotControlsProps {
slotId: string
moduleType: ModuleType | null
selectedTerminalItemId?: TerminalItemId | null
handleDragHover?: () => unknown
handleDragHover?: () => void
}

interface DroppedItem {
Expand All @@ -53,10 +54,15 @@ export const SlotControls = (props: SlotControlsProps): JSX.Element | null => {
const customLabwareDefs = useSelector(

Check warning on line 54 in protocol-designer/src/components/DeckSetup/LabwareOverlays/SlotControls.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/DeckSetup/LabwareOverlays/SlotControls.tsx#L54

Added line #L54 was not covered by tests
labwareDefSelectors.getCustomLabwareDefsByURI
)
const activeDeckSetup = useSelector(getDeckSetupForActiveItem)
const labware = activeDeckSetup.labware
const ref = React.useRef(null)
const [newSlot, setSlot] = React.useState<string | null>(null)
const dispatch = useDispatch()

Check warning on line 61 in protocol-designer/src/components/DeckSetup/LabwareOverlays/SlotControls.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/DeckSetup/LabwareOverlays/SlotControls.tsx#L57-L61

Added lines #L57 - L61 were not covered by tests

const { t } = useTranslation('deck')

const [{ itemType, draggedItem, isOver }, drop] = useDrop(() => ({
const [{ draggedItem, itemType, isOver }, drop] = useDrop({

Check warning on line 65 in protocol-designer/src/components/DeckSetup/LabwareOverlays/SlotControls.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/DeckSetup/LabwareOverlays/SlotControls.tsx#L65

Added line #L65 was not covered by tests
accept: DND_TYPES.LABWARE,
canDrop: (item: DroppedItem) => {
const draggedDef = item?.labwareOnDeck?.def
Expand All @@ -70,13 +76,16 @@ export const SlotControls = (props: SlotControlsProps): JSX.Element | null => {
)

return getLabwareIsCompatible(draggedDef, moduleType) || isCustomLabware
} else {
return true
}
return true

Check warning on line 80 in protocol-designer/src/components/DeckSetup/LabwareOverlays/SlotControls.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/DeckSetup/LabwareOverlays/SlotControls.tsx#L80

Added line #L80 was not covered by tests
},
drop: (item: DroppedItem) => {
if (item.labwareOnDeck) {
dispatch(moveDeckItem(item.labwareOnDeck.slot, slotId))
const droppedLabware = item

Check warning on line 83 in protocol-designer/src/components/DeckSetup/LabwareOverlays/SlotControls.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/DeckSetup/LabwareOverlays/SlotControls.tsx#L83

Added line #L83 was not covered by tests
if (newSlot != null) {
dispatch(moveDeckItem(newSlot, slotId))

Check warning on line 85 in protocol-designer/src/components/DeckSetup/LabwareOverlays/SlotControls.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/DeckSetup/LabwareOverlays/SlotControls.tsx#L85

Added line #L85 was not covered by tests
} else if (droppedLabware.labwareOnDeck != null) {
const droppedSlot = droppedLabware.labwareOnDeck.slot
dispatch(moveDeckItem(droppedSlot, slotId))

Check warning on line 88 in protocol-designer/src/components/DeckSetup/LabwareOverlays/SlotControls.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/DeckSetup/LabwareOverlays/SlotControls.tsx#L87-L88

Added lines #L87 - L88 were not covered by tests
}
},
hover: () => {
Expand All @@ -89,7 +98,17 @@ export const SlotControls = (props: SlotControlsProps): JSX.Element | null => {
isOver: !!monitor.isOver(),
draggedItem: monitor.getItem() as DroppedItem,
}),
}))
})

const draggedLabware = Object.values(labware).find(
l => l.id === draggedItem?.labwareOnDeck?.id

Check warning on line 104 in protocol-designer/src/components/DeckSetup/LabwareOverlays/SlotControls.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/DeckSetup/LabwareOverlays/SlotControls.tsx#L103-L104

Added lines #L103 - L104 were not covered by tests
)

React.useEffect(() => {

Check warning on line 107 in protocol-designer/src/components/DeckSetup/LabwareOverlays/SlotControls.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/DeckSetup/LabwareOverlays/SlotControls.tsx#L107

Added line #L107 was not covered by tests
if (draggedLabware != null) {
setSlot(draggedLabware.slot)

Check warning on line 109 in protocol-designer/src/components/DeckSetup/LabwareOverlays/SlotControls.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/DeckSetup/LabwareOverlays/SlotControls.tsx#L109

Added line #L109 was not covered by tests
}
})

if (
selectedTerminalItemId !== START_TERMINAL_ITEM_ID ||
Expand Down Expand Up @@ -131,8 +150,10 @@ export const SlotControls = (props: SlotControlsProps): JSX.Element | null => {
dispatch(openAddLabwareModal({ slot: slotId }))

Check warning on line 150 in protocol-designer/src/components/DeckSetup/LabwareOverlays/SlotControls.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/DeckSetup/LabwareOverlays/SlotControls.tsx#L149-L150

Added lines #L149 - L150 were not covered by tests
}

drop(ref)

Check warning on line 153 in protocol-designer/src/components/DeckSetup/LabwareOverlays/SlotControls.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/DeckSetup/LabwareOverlays/SlotControls.tsx#L153

Added line #L153 was not covered by tests

return (

Check warning on line 155 in protocol-designer/src/components/DeckSetup/LabwareOverlays/SlotControls.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/DeckSetup/LabwareOverlays/SlotControls.tsx#L155

Added line #L155 was not covered by tests
<g ref={drop}>
<g ref={ref}>
{slotBlocked ? (
<BlockedSlot
x={slotPosition[0]}
Expand Down

0 comments on commit 5448767

Please sign in to comment.