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

refactor(protocol-designer): ot-2 slot map is now a normal size #14518

Merged
merged 4 commits into from
Feb 21, 2024
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as React from 'react'
import cx from 'classnames'
import { FLEX_ROBOT_TYPE, RobotType } from '@opentrons/shared-data'
import { Icon } from '../icons'
import styles from './styles.css'

Expand All @@ -14,7 +13,6 @@ export interface SlotMapProps {
collisionSlots?: string[]
/** Optional error styling */
isError?: boolean
robotType?: RobotType
}

const OT2_SLOT_MAP_SLOTS = [
Expand All @@ -24,24 +22,15 @@ const OT2_SLOT_MAP_SLOTS = [
['1', '2', '3'],
]

const FLEX_SLOT_MAP_SLOTS = [
['A1', 'A2', 'A3'],
['B1', 'B2', 'B3'],
['C1', 'C2', 'C3'],
['D1', 'D2', 'D3'],
]

const slotWidth = 33
const slotHeight = 23
const iconSize = 20
const numRows = 4
const numCols = 3

export function SlotMap(props: SlotMapProps): JSX.Element {
const { collisionSlots, occupiedSlots, isError, robotType } = props
const slots =
robotType === FLEX_ROBOT_TYPE ? FLEX_SLOT_MAP_SLOTS : OT2_SLOT_MAP_SLOTS

export function OT2SlotMap(props: SlotMapProps): JSX.Element {
const { collisionSlots, occupiedSlots, isError } = props
const slots = OT2_SLOT_MAP_SLOTS
return (
<svg
viewBox={`-1,-1,${slotWidth * numCols + 2}, ${slotHeight * numRows + 2}`}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
describe('SlotMap', () => {
describe('OT2SlotMap', () => {
it.todo('replace deprecated enzyme test')
})
2 changes: 1 addition & 1 deletion components/src/slotmap/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './SlotMap'
export * from './OT2SlotMap'
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ export const WellSelectionField = (props: Props): JSX.Element => {
const stepId = useSelector(getSelectedStepId)
const pipetteEntities = useSelector(stepFormSelectors.getPipetteEntities)
const wellSelectionLabwareKey = useSelector(getWellSelectionLabwareKey)
const primaryWellCount = Array.isArray(selectedWells)
? selectedWells.length.toString()
: undefined
const primaryWellCount =
Array.isArray(selectedWells) && selectedWells.length > 0
? selectedWells.length.toString()
: undefined
Comment on lines +43 to +46
Copy link
Collaborator Author

@jerader jerader Feb 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated to the bug but this fixed another small bug i found that was introduced by my PR that refactored class components into functional components 😬

const pipette = pipetteId != null ? pipetteEntities[pipetteId] : null
const is8Channel = pipette != null ? pipette.spec.channels === 8 : false

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,3 @@
.button_margin {
margin-left: 1rem;
}

.slot_map_container {
flex: 0 1 13rem;
padding: 0 3rem 0;
}

.slot_map_container_modal {
display: flex;
height: 16rem;
margin-bottom: 1rem;
margin-top: 1rem;
justify-content: center;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,22 @@ import { FLEX_ROBOT_TYPE, OT2_ROBOT_TYPE } from '@opentrons/shared-data'
import {
DeckLocationSelect,
renderWithProviders,
SlotMap,
OT2SlotMap,
} from '@opentrons/components'
import { i18n } from '../../../../localization'
import { getRobotType } from '../../../../file-data/selectors'
import { getInitialDeckSetup } from '../../../../step-forms/selectors'
import { getLabwareIsCompatible } from '../../../../utils/labwareModuleCompatibility'
import { getDisableModuleRestrictions } from '../../../../feature-flags/selectors'
import { ConnectedSlotMap } from '../ConnectedSlotMap'
import { EditModulesModal } from '../index'
import type { ModuleOnDeck } from '../../../../step-forms'

jest.mock('../ConnectedSlotMap')
jest.mock('../../../../file-data/selectors')
jest.mock('../../../../step-forms/selectors')
jest.mock('../../../../utils/labwareModuleCompatibility')
jest.mock('../../../../feature-flags/selectors')
jest.mock('@opentrons/components/src/hooks/useSelectDeckLocation/index')
jest.mock('@opentrons/components/src/slotmap/SlotMap')
jest.mock('@opentrons/components/src/slotmap/OT2SlotMap')

const mockGetRobotType = getRobotType as jest.MockedFunction<
typeof getRobotType
Expand All @@ -39,10 +37,7 @@ const mockGetLabwareIsCompatible = getLabwareIsCompatible as jest.MockedFunction
const mockGetDisableModuleRestrictions = getDisableModuleRestrictions as jest.MockedFunction<
typeof getDisableModuleRestrictions
>
const mockConnectedSlotMap = ConnectedSlotMap as jest.MockedFunction<
typeof ConnectedSlotMap
>
const mockSlotMap = SlotMap as jest.MockedFunction<typeof SlotMap>
const mockOT2SlotMap = OT2SlotMap as jest.MockedFunction<typeof OT2SlotMap>
const render = (props: React.ComponentProps<typeof EditModulesModal>) => {
return renderWithProviders(<EditModulesModal {...props} />, {
i18nInstance: i18n,
Expand Down Expand Up @@ -97,8 +92,7 @@ describe('Edit Modules Modal', () => {
mockGetLabwareIsCompatible.mockReturnValue(true)
mockGetDisableModuleRestrictions.mockReturnValue(false)
mockDeckLocationSelect.mockReturnValue(<div>mock DeckLocationSelect</div>)
mockConnectedSlotMap.mockReturnValue(<div>mock ConnectedSlotMap</div>)
mockSlotMap.mockReturnValue(<div>mock SlotMap</div>)
mockOT2SlotMap.mockReturnValue(<div>mock SlotMap</div>)
})
it('renders the edit modules modal for a temp on a flex', () => {
render(props)
Expand All @@ -112,7 +106,7 @@ describe('Edit Modules Modal', () => {
mockGetRobotType.mockReturnValue(OT2_ROBOT_TYPE)
render(props)
screen.getByText('Temperature module')
screen.getByText('mock ConnectedSlotMap')
screen.getByText('mock SlotMap')
fireEvent.click(screen.getByRole('button', { name: 'cancel' }))
expect(props.onCloseClick).toHaveBeenCalled()
screen.getByRole('button', { name: 'save' })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
ALIGN_CENTER,
JUSTIFY_SPACE_BETWEEN,
JUSTIFY_FLEX_END,
SlotMap,
OT2SlotMap,
usePrevious,
} from '@opentrons/components'
import {
Expand Down Expand Up @@ -68,7 +68,6 @@ import { PDAlert } from '../../alerts/PDAlert'
import { isModuleWithCollisionIssue } from '../../modules'
import { ModelDropdown } from './ModelDropdown'
import { SlotDropdown } from './SlotDropdown'
import { ConnectedSlotMap } from './ConnectedSlotMap'
import styles from './EditModules.css'

import type { ModuleOnDeck } from '../../../step-forms/types'
Expand Down Expand Up @@ -407,24 +406,23 @@ const EditModulesModalComponent = (
<Controller
name="selectedSlot"
control={control}
render={({ field, fieldState }) =>
moduleType === THERMOCYCLER_MODULE_TYPE ? (
<Flex
height="16rem"
justifyContent={JUSTIFY_CENTER}
paddingY={SPACING.spacing16}
>
<SlotMap occupiedSlots={['7', '8', '10', '11']} />
</Flex>
) : (
<ConnectedSlotMap
robotType={OT2_ROBOT_TYPE}
field={field}
hasFieldError={!fieldState.error}
/>
)
}
></Controller>
render={({ field, fieldState }) => (
<Flex
height="16rem"
justifyContent={JUSTIFY_CENTER}
paddingY={SPACING.spacing16}
>
{moduleType === THERMOCYCLER_MODULE_TYPE ? (
<OT2SlotMap occupiedSlots={['7', '8', '10', '11']} />
) : (
<OT2SlotMap
occupiedSlots={[`${field.value}`]}
isError={!fieldState.error}
/>
)}
</Flex>
)}
/>
) : (
<Flex height="20rem" justifyContent={JUSTIFY_CENTER}>
<DeckLocationSelect
Expand Down
7 changes: 3 additions & 4 deletions protocol-designer/src/components/modules/ModuleRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import upperFirst from 'lodash/upperFirst'
import {
LabeledValue,
OutlineButton,
SlotMap,
OT2SlotMap,
Tooltip,
useHoverTooltip,
ModuleIcon,
Expand Down Expand Up @@ -51,7 +51,7 @@ export function ModuleRow(props: Props): JSX.Element {
const slot = moduleOnDeck?.slot
/*
TODO (ka 2020-2-3): This logic is very specific to this individual implementation
of SlotMap. Kept it here (for now?) because it spells out the different cases.
of OT2SlotMap. Kept it here (for now?) because it spells out the different cases.
*/
let slotDisplayName = null
let occupiedSlotsForMap: string[] = []
Expand Down Expand Up @@ -160,10 +160,9 @@ export function ModuleRow(props: Props): JSX.Element {
/>
) : (
<div {...targetProps}>
<SlotMap
<OT2SlotMap
occupiedSlots={occupiedSlotsForMap}
collisionSlots={collisionSlots}
robotType={robotType}
/>
</div>
))}
Expand Down
Loading