Skip to content

Commit

Permalink
fix(protocol-designer): fix layout and menu items of SlotOverflowMenu (
Browse files Browse the repository at this point in the history
…#16840)

This PR fixes the layout and content of SlotOverflowMenu component. It
aligns text to the left of the menu button. Also, it always renders 'Add
liquid' option, but disables if no labware is present in the slot. Last,
it adds a Divider above 'Clear slot' option.

Closes RQA-3335
  • Loading branch information
ncdiehl11 authored Nov 18, 2024
1 parent 9fceef6 commit d77329a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 58 deletions.
2 changes: 2 additions & 0 deletions components/src/atoms/MenuList/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export const MenuItem = styled.button<ButtonProps>`
padding: ${SPACING.spacing8} ${SPACING.spacing12} ${SPACING.spacing8}
${SPACING.spacing12};
border: ${props => (props.border != null ? props.border : 'inherit')};
border-radius: ${props =>
props.borderRadius != null ? props.borderRadius : 'inherit'};
&:hover {
background-color: ${COLORS.blue10};
Expand Down
94 changes: 38 additions & 56 deletions protocol-designer/src/pages/Designer/DeckSetup/SlotOverflowMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import { useTranslation } from 'react-i18next'
import { useState } from 'react'
import styled from 'styled-components'
import { useDispatch, useSelector } from 'react-redux'
import { useNavigate } from 'react-router-dom'
import {
BORDERS,
COLORS,
CURSOR_AUTO,
CURSOR_POINTER,
DIRECTION_COLUMN,
Divider,
Flex,
MenuItem,
NO_WRAP,
POSITION_ABSOLUTE,
RobotCoordsForeignDiv,
SPACING,
StyledText,
useOnClickOutside,
} from '@opentrons/components'
Expand Down Expand Up @@ -168,7 +166,7 @@ export function SlotOverflowMenu(
nestedLabwareOnSlot == null) ||
nestedLabwareOnSlot != null

const showEditAndLiquidsBtns =
const canRenameLabwareAndEditLiquids =
(labwareOnSlot != null &&
!isLabwareAnAdapter &&
!isLabwareTiprack &&
Expand All @@ -180,7 +178,7 @@ export function SlotOverflowMenu(
: TOP_SLOT_Y_POSITION

if (showDuplicateBtn && !ROBOT_BOTTOM_HALF_SLOTS.includes(location)) {
position += showEditAndLiquidsBtns
position += canRenameLabwareAndEditLiquids
? TOP_SLOT_Y_POSITION_ALL_BUTTONS
: TOP_SLOT_Y_POSITION_2_BUTTONS
}
Expand Down Expand Up @@ -233,7 +231,7 @@ export function SlotOverflowMenu(
e.stopPropagation()
}}
>
<MenuButton
<MenuItem
onClick={() => {
addEquipment(location)
setShowMenuList(false)
Expand All @@ -244,38 +242,37 @@ export function SlotOverflowMenu(
? t(isOffDeckLocation ? 'add_labware' : 'add_hw_lw')
: t(isOffDeckLocation ? 'edit_labware' : 'edit_hw_lw')}
</StyledText>
</MenuButton>
{showEditAndLiquidsBtns ? (
<>
<MenuButton
onClick={(e: MouseEvent) => {
setShowNickNameModal(true)
e.preventDefault()
e.stopPropagation()
}}
>
<StyledText desktopStyle="bodyDefaultRegular">
{t('rename_lab')}
</StyledText>
</MenuButton>
<MenuButton
onClick={() => {
if (nestedLabwareOnSlot != null) {
dispatch(openIngredientSelector(nestedLabwareOnSlot.id))
} else if (labwareOnSlot != null) {
dispatch(openIngredientSelector(labwareOnSlot.id))
}
navigate('/liquids')
}}
>
<StyledText desktopStyle="bodyDefaultRegular">
{selectionHasLiquids ? t('edit_liquid') : t('add_liquid')}
</StyledText>
</MenuButton>
</>
</MenuItem>
{canRenameLabwareAndEditLiquids ? (
<MenuItem
onClick={(e: MouseEvent) => {
setShowNickNameModal(true)
e.preventDefault()
e.stopPropagation()
}}
>
<StyledText desktopStyle="bodyDefaultRegular">
{t('rename_lab')}
</StyledText>
</MenuItem>
) : null}
<MenuItem
onClick={() => {
if (nestedLabwareOnSlot != null) {
dispatch(openIngredientSelector(nestedLabwareOnSlot.id))
} else if (labwareOnSlot != null) {
dispatch(openIngredientSelector(labwareOnSlot.id))
}
navigate('/liquids')
}}
disabled={!canRenameLabwareAndEditLiquids}
>
<StyledText desktopStyle="bodyDefaultRegular">
{selectionHasLiquids ? t('edit_liquid') : t('add_liquid')}
</StyledText>
</MenuItem>
{showDuplicateBtn ? (
<MenuButton
<MenuItem
onClick={() => {
if (
labwareOnSlot != null &&
Expand All @@ -292,9 +289,10 @@ export function SlotOverflowMenu(
<StyledText desktopStyle="bodyDefaultRegular">
{t('duplicate')}
</StyledText>
</MenuButton>
</MenuItem>
) : null}
<MenuButton
<Divider marginY="0" />
<MenuItem
disabled={hasNoItems}
onClick={(e: MouseEvent) => {
if (matchingLabware != null) {
Expand All @@ -310,7 +308,7 @@ export function SlotOverflowMenu(
<StyledText desktopStyle="bodyDefaultRegular">
{t(isOffDeckLocation ? 'clear_labware' : 'clear_slot')}
</StyledText>
</MenuButton>
</MenuItem>
</Flex>
</>
)
Expand All @@ -337,19 +335,3 @@ export function SlotOverflowMenu(
slotOverflowBody
)
}

const MenuButton = styled.button`
background-color: ${COLORS.transparent};
border-radius: inherit;
cursor: ${CURSOR_POINTER};
padding: ${SPACING.spacing8} ${SPACING.spacing12};
border: none;
border-radius: inherit;
&:hover {
background-color: ${COLORS.blue10};
}
&:disabled {
color: ${COLORS.grey40};
cursor: ${CURSOR_AUTO};
}
`
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,18 @@ describe('SlotOverflowMenu', () => {
expect(vi.mocked(deleteDeckFixture)).toHaveBeenCalled()
expect(props.setShowMenuList).toHaveBeenCalled()
})
it('renders 2 buttons when there is nothing on the slot', () => {
it('renders 3 buttons when there is nothing on the slot', () => {
props.location = 'A1'
render(props)
fireEvent.click(
screen.getByRole('button', { name: 'Add hardware/labware' })
)
expect(props.addEquipment).toHaveBeenCalled()
expect(props.setShowMenuList).toHaveBeenCalled()
expect(screen.getAllByRole('button')).toHaveLength(2)
expect(screen.getAllByRole('button')).toHaveLength(3)
expect(screen.getByRole('button', { name: 'Add liquid' })).toBeDisabled()
expect(screen.getByRole('button', { name: 'Clear slot' })).toBeDisabled()
screen.getByTestId('divider')
})
it('renders Edit liquid button when there is liquid on the labware', () => {
vi.mocked(labwareIngredSelectors.getLiquidsByLabwareId).mockReturnValue({
Expand Down

0 comments on commit d77329a

Please sign in to comment.