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

fix(protocol-designer): Fix deck view size issues in pd #16616

Merged
merged 14 commits into from
Oct 31, 2024
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react'
import { Svg } from '../../primitives'
import { css } from 'styled-components'
import { Flex, Svg } from '../../primitives'
import type { DeckDefinition, DeckSlot } from '@opentrons/shared-data'

export interface RobotCoordinateSpaceWithRefRenderProps {
Expand All @@ -10,13 +11,14 @@ interface RobotCoordinateSpaceWithRefProps
extends React.ComponentProps<typeof Svg> {
viewBox?: string | null
deckDef?: DeckDefinition
zoomed?: boolean
children?: (props: RobotCoordinateSpaceWithRefRenderProps) => React.ReactNode
}

export function RobotCoordinateSpaceWithRef(
props: RobotCoordinateSpaceWithRefProps
): JSX.Element | null {
const { children, deckDef, viewBox, ...restProps } = props
const { children, deckDef, viewBox, zoomed = false, ...restProps } = props
const wrapperRef = React.useRef<SVGSVGElement>(null)

if (deckDef == null && viewBox == null) return null
Expand All @@ -31,16 +33,36 @@ export function RobotCoordinateSpaceWithRef(
(acc, deckSlot) => ({ ...acc, [deckSlot.id]: deckSlot }),
{}
)
wholeDeckViewBox = `${viewBoxOriginX} ${viewBoxOriginY} ${deckXDimension} ${deckYDimension}`

// Add padding to prevent clipping and better center the content
const PADDING = deckDef.otId === 'ot2_standard' ? 5 : 20
wholeDeckViewBox = `${viewBoxOriginX - PADDING} ${
viewBoxOriginY - PADDING
} ${deckXDimension + PADDING * 2} ${deckYDimension + PADDING * 2}`
}
return (
<Svg
viewBox={viewBox || wholeDeckViewBox}
ref={wrapperRef}
transform="scale(1, -1)"
{...restProps}
<Flex
width="100%"
height="100%"
alignItems="center"
koji marked this conversation as resolved.
Show resolved Hide resolved
justifyContent="center"
koji marked this conversation as resolved.
Show resolved Hide resolved
css={css`
outline: purple solid 1px;
koji marked this conversation as resolved.
Show resolved Hide resolved
`}
>
{children?.({ deckSlotsById })}
</Svg>
<Svg
viewBox={zoomed ? viewBox : wholeDeckViewBox}
ref={wrapperRef}
transform="scale(1, -1)"
width="100%"
height="100%"
css={css`
outline: red solid 1px;
`}
{...restProps}
>
{children?.({ deckSlotsById })}
</Svg>
</Flex>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export function SlotDetailsContainer(
return location.pathname === '/designer' && slot !== 'offDeck' ? (
<RobotCoordsForeignObject
width="15.8125rem"
height="26.75rem"
height="32.3125rem"
x="-400"
y={getYPosition({ robotType, slot })}
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useMemo, useState, Fragment } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { css } from 'styled-components'
import {
ALIGN_CENTER,
BORDERS,
Expand Down Expand Up @@ -176,9 +177,12 @@ export function DeckSetupContainer(props: DeckSetupTabType): JSX.Element {
backgroundColor={COLORS.white}
borderRadius={BORDERS.borderRadius12}
width="100%"
height={zoomIn.slot != null ? '75vh' : '65vh'}
height={zoomIn.slot != null ? '75vh' : '70vh'}
flexDirection={DIRECTION_COLUMN}
padding={SPACING.spacing40}
css={css`
outline: green solid 1px;
`}
>
<Flex
width="100%"
Expand All @@ -187,11 +191,12 @@ export function DeckSetupContainer(props: DeckSetupTabType): JSX.Element {
justifyContent={JUSTIFY_CENTER}
>
<RobotCoordinateSpaceWithRef
height={zoomIn.slot != null ? '100%' : '80%'}
height={zoomIn.slot != null ? '100%' : '95%'}
width="100%"
deckDef={deckDef}
viewBox={viewBox}
outline="auto"
zoomed={zoomIn.slot != null}
>
{() => (
<>
Expand Down
17 changes: 13 additions & 4 deletions protocol-designer/src/pages/Designer/LiquidsOverflowMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import {
Flex,
Icon,
LiquidIcon,
NO_WRAP,
POSITION_ABSOLUTE,
SPACING,
StyledText,
TYPOGRAPHY,
} from '@opentrons/components'
import { LINE_CLAMP_TEXT_STYLE } from '../../atoms'
import { selectors as labwareIngredSelectors } from '../../labware-ingred/selectors'
import * as labwareIngredActions from '../../labware-ingred/actions'
import type { ThunkDispatch } from '../../types'
Expand Down Expand Up @@ -46,7 +47,6 @@ export function LiquidsOverflowMenu(
zIndex={5}
right={location.pathname === '/liquids' ? SPACING.spacing12 : '3.125rem'}
top={`calc(${NAV_HEIGHT} - 6px)`}
whiteSpace={NO_WRAP}
ref={overflowWrapperRef}
borderRadius={BORDERS.borderRadius8}
boxShadow="0px 1px 3px rgba(0, 0, 0, 0.2)"
Expand All @@ -56,6 +56,7 @@ export function LiquidsOverflowMenu(
e.preventDefault()
e.stopPropagation()
}}
width="9.375rem"
>
{liquids.map(({ name, displayColor, ingredientId }) => {
return (
Expand All @@ -70,7 +71,15 @@ export function LiquidsOverflowMenu(
>
<Flex alignItems={ALIGN_CENTER} gridGap={SPACING.spacing8}>
<LiquidIcon color={displayColor ?? ''} />
<StyledText desktopStyle="bodyDefaultRegular">{name}</StyledText>
<StyledText
desktopStyle="bodyDefaultRegular"
css={`
${LINE_CLAMP_TEXT_STYLE(3)}
text-align: ${TYPOGRAPHY.textAlignLeft}
`}
>
{name}
</StyledText>
</Flex>
</MenuButton>
)
Expand All @@ -87,7 +96,7 @@ export function LiquidsOverflowMenu(
}}
key="defineLiquid"
>
<Flex alignItems={ALIGN_CENTER} gridGap={SPACING.spacing4}>
<Flex alignItems={ALIGN_CENTER} gridGap={SPACING.spacing8}>
<Icon name="plus" size="1rem" />
<StyledText desktopStyle="bodyDefaultRegular">
{t('define_liquid')}
Expand Down
2 changes: 1 addition & 1 deletion protocol-designer/src/pages/Designer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export function Designer(): JSX.Element {
padding={zoomIn.slot != null ? '0' : SPACING.spacing80}
height="calc(100vh - 64px)"
>
<Flex flexDirection={DIRECTION_COLUMN} gridGap={SPACING.spacing24}>
<Flex flexDirection={DIRECTION_COLUMN}>
{zoomIn.slot == null ? (
<Flex alignSelf={ALIGN_END}>
<ToggleGroup
Expand Down
12 changes: 10 additions & 2 deletions protocol-designer/src/pages/ProtocolOverview/DeckThumbnail.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react'
import { useSelector } from 'react-redux'
import { css } from 'styled-components'
import {
ALIGN_CENTER,
BORDERS,
Expand All @@ -11,6 +12,7 @@ import {
RobotCoordinateSpaceWithRef,
SingleSlotFixture,
SlotLabels,
SPACING,
StagingAreaFixture,
WasteChuteFixture,
WasteChuteStagingAreaFixture,
Expand Down Expand Up @@ -99,11 +101,17 @@ export function DeckThumbnail(props: DeckThumbnailProps): JSX.Element {
width="100%"
alignItems={ALIGN_CENTER}
justifyContent={JUSTIFY_CENTER}
backgroundColor={COLORS.grey10}
backgroundColor={
robotType === OT2_ROBOT_TYPE ? COLORS.white : COLORS.grey10
}
borderRadius={BORDERS.borderRadius8}
paddingY={SPACING.spacing24}
css={css`
outline: green solid 1px;
`}
>
<RobotCoordinateSpaceWithRef
height="80%"
height="100%"
width="100%"
deckDef={deckDef}
viewBox={`${deckDef.cornerOffsetFromOrigin[0]} ${
Expand Down
Loading