Skip to content

Commit

Permalink
fix(protocol-designer): fix deck view size issue in new pd
Browse files Browse the repository at this point in the history
fix deck view size issue in new pd

close RQA- RQA-
  • Loading branch information
koji committed Oct 28, 2024
1 parent 1c1a3c0 commit f02c187
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 16 deletions.
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, ...restProps } = props
const wrapperRef = React.useRef<SVGSVGElement>(null)

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

wholeDeckViewBox = `${viewBoxOriginX} ${-deckYDimension} ${deckXDimension} ${deckYDimension}`

// wholeDeckViewBox = `${viewBoxOriginX} ${viewBoxOriginY} ${deckXDimension} ${deckYDimension}`
// Add padding to prevent clipping and better center the content
const padding = 20
wholeDeckViewBox = `${viewBoxOriginX - padding} ${
viewBoxOriginY - padding
} ${deckXDimension + padding * 2} ${deckYDimension + padding * 2}`
// Invert Y-axis by setting min-y to negative of deckYDimension
}
console.log('wholeDeckViewBox', wholeDeckViewBox)
console.log('viewBox', viewBox)
console.log(viewBox || wholeDeckViewBox)
return (
<Svg
viewBox={viewBox || wholeDeckViewBox}
ref={wrapperRef}
transform="scale(1, -1)"
{...restProps}
<Flex
width="100%"
height="100%"
alignItems="center"
justifyContent="center"
css={css`
outline: purple solid 1px;
`}
>
{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
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

Check failure on line 113 in protocol-designer/src/pages/ProtocolOverview/DeckThumbnail.tsx

View workflow job for this annotation

GitHub Actions / js checks

Property 'zoomed' is missing in type '{ children: () => Element; height: string; width: string; deckDef: DeckDefinition; viewBox: string; }' but required in type 'RobotCoordinateSpaceWithRefProps'.
height="80%"
height="100%"
width="100%"
deckDef={deckDef}
viewBox={`${deckDef.cornerOffsetFromOrigin[0]} ${
Expand Down

0 comments on commit f02c187

Please sign in to comment.