Skip to content

Commit

Permalink
fix editLabware drag and drop
Browse files Browse the repository at this point in the history
  • Loading branch information
jerader committed Feb 14, 2024
1 parent c737b0f commit 7e4ca7e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import styles from './LabwareOverlays.css'

interface Props {
labwareOnDeck: LabwareOnDeck
setHoveredLabware: (val?: LabwareOnDeck | null) => unknown
setDraggedLabware: (val?: LabwareOnDeck | null) => unknown
setHoveredLabware: (val?: LabwareOnDeck | null) => void
setDraggedLabware: (val?: LabwareOnDeck | null) => void
swapBlocked: boolean
}

Expand All @@ -38,6 +38,7 @@ export const EditLabware = (props: Props): JSX.Element | null => {
const savedLabware = useSelector(labwareIngredSelectors.getSavedLabware)
const dispatch = useDispatch<ThunkDispatch<any>>()

Check warning on line 39 in protocol-designer/src/components/DeckSetup/LabwareOverlays/EditLabware.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/DeckSetup/LabwareOverlays/EditLabware.tsx#L38-L39

Added lines #L38 - L39 were not covered by tests
const { t } = useTranslation('deck')
const ref = React.useRef(null)

Check warning on line 41 in protocol-designer/src/components/DeckSetup/LabwareOverlays/EditLabware.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/DeckSetup/LabwareOverlays/EditLabware.tsx#L41

Added line #L41 was not covered by tests

const { isTiprack } = labwareOnDeck.def.parameters
const hasName = savedLabware[labwareOnDeck.id]

Check warning on line 44 in protocol-designer/src/components/DeckSetup/LabwareOverlays/EditLabware.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/DeckSetup/LabwareOverlays/EditLabware.tsx#L44

Added line #L44 was not covered by tests
Expand All @@ -62,26 +63,21 @@ export const EditLabware = (props: Props): JSX.Element | null => {

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

Check warning on line 64 in protocol-designer/src/components/DeckSetup/LabwareOverlays/EditLabware.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/DeckSetup/LabwareOverlays/EditLabware.tsx#L64

Added line #L64 was not covered by tests
accept: DND_TYPES.LABWARE,
canDrop: (item: any) => {
const draggedItem = item?.labwareOnDeck
const draggedLabware = draggedItem?.labwareOnDeck
canDrop: (item: DroppedItem) => {
const draggedLabware = item?.labwareOnDeck

Check warning on line 67 in protocol-designer/src/components/DeckSetup/LabwareOverlays/EditLabware.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/DeckSetup/LabwareOverlays/EditLabware.tsx#L67

Added line #L67 was not covered by tests
const isDifferentSlot =
draggedLabware && draggedLabware.slot !== labwareOnDeck.slot
return isDifferentSlot && !swapBlocked
},
drop: (item: any) => {
const draggedItem = item?.labwareOnDeck
if (draggedItem) {
dispatch(
moveDeckItem(draggedItem.labwareOnDeck.slot, labwareOnDeck.slot)
)
drop: (item: DroppedItem) => {
const draggedLabware = item?.labwareOnDeck

Check warning on line 73 in protocol-designer/src/components/DeckSetup/LabwareOverlays/EditLabware.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/DeckSetup/LabwareOverlays/EditLabware.tsx#L73

Added line #L73 was not covered by tests
if (draggedLabware) {
dispatch(moveDeckItem(draggedLabware.slot, labwareOnDeck.slot))

Check warning on line 75 in protocol-designer/src/components/DeckSetup/LabwareOverlays/EditLabware.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/DeckSetup/LabwareOverlays/EditLabware.tsx#L75

Added line #L75 was not covered by tests
}
},

hover: (monitor: DropTargetMonitor) => {
if (monitor.canDrop()) {
setHoveredLabware(labwareOnDeck)
}
hover: () => {
setHoveredLabware(labwareOnDeck)

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L80 was not covered by tests
},
collect: (monitor: DropTargetMonitor) => ({

Check warning on line 82 in protocol-designer/src/components/DeckSetup/LabwareOverlays/EditLabware.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/DeckSetup/LabwareOverlays/EditLabware.tsx#L82

Added line #L82 was not covered by tests
isOver: monitor.isOver(),
Expand Down Expand Up @@ -151,17 +147,18 @@ export const EditLabware = (props: Props): JSX.Element | null => {
)
}

const dragResult = drag(
<div ref={drop}>
<div
className={cx(styles.slot_overlay, {
[styles.appear_on_mouseover]: !isBeingDragged && !isYetUnnamed,
[styles.appear]: isOver,
[styles.disabled]: isBeingDragged,
})}
>
{contents}
</div>
drag(drop(ref))

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L150 was not covered by tests

const dragResult = (
<div

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L153 was not covered by tests
ref={ref}
className={cx(styles.slot_overlay, {
[styles.appear_on_mouseover]: !isBeingDragged && !isYetUnnamed,
[styles.appear]: isOver,
[styles.disabled]: isBeingDragged,
})}
>
{contents}
</div>
)

Expand Down
5 changes: 0 additions & 5 deletions protocol-designer/src/components/steplist/ContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ export const ContextMenu = (props: Props): JSX.Element => {
})

const makeHandleContextMenu = (stepId: StepIdType) => (event: MouseEvent) => {
console.log(
'handle context menu called before isMulti SelectMode',
isMultiSelectMode
)
if (isMultiSelectMode) return
event.preventDefault()

Expand All @@ -84,7 +80,6 @@ export const ContextMenu = (props: Props): JSX.Element => {
screenH - clickY > rootH
? clickY + MENU_OFFSET_PX
: clickY - rootH - MENU_OFFSET_PX
console.log('handle context menu called')
setVisible(true)
setStepId(stepId)
setPosition({ left, top })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ export const DraggableStepItems = (
React.useEffect(() => {
setStepIds(orderedStepIds)

Check warning on line 93 in protocol-designer/src/components/steplist/DraggableStepItems.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/steplist/DraggableStepItems.tsx#L88-L93

Added lines #L88 - L93 were not covered by tests
}, [orderedStepIds])
console.log('orderedStepIds', orderedStepIds)
console.log('stepIds', stepIds)

const clickDrop = (): void => {

Check warning on line 96 in protocol-designer/src/components/steplist/DraggableStepItems.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/steplist/DraggableStepItems.tsx#L96

Added line #L96 was not covered by tests
if (!isEqual(orderedStepIds, stepIds)) {
Expand All @@ -120,8 +118,7 @@ export const DraggableStepItems = (
stepIds.findIndex(id => stepId === id)

Check warning on line 118 in protocol-designer/src/components/steplist/DraggableStepItems.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/steplist/DraggableStepItems.tsx#L117-L118

Added lines #L117 - L118 were not covered by tests

const currentIds = isOver ? stepIds : orderedStepIds
console.log('isover', isOver)
console.log('currentIds', currentIds)

return (

Check warning on line 122 in protocol-designer/src/components/steplist/DraggableStepItems.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/steplist/DraggableStepItems.tsx#L122

Added line #L122 was not covered by tests
<>
<ContextMenu>
Expand Down

0 comments on commit 7e4ca7e

Please sign in to comment.