Skip to content

Commit 9de3dca

Browse files
authored
fix(app): fix devices landing page text wrapping (#11110)
This will address design feedback on the Devices landing page. fix #10886
1 parent f74853b commit 9de3dca

File tree

3 files changed

+67
-38
lines changed

3 files changed

+67
-38
lines changed

app/src/organisms/Devices/RobotCard.tsx

Lines changed: 60 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
} from './hooks'
3636
import { ReachableBanner } from './ReachableBanner'
3737
import { RobotOverflowMenu } from './RobotOverflowMenu'
38+
import { useGetElementDOMRectProperty } from '../../organisms/ProtocolsLanding/useGetElementDOMRectProperty'
3839

3940
import type { DiscoveredRobot } from '../../redux/discovery/types'
4041

@@ -45,6 +46,8 @@ const ROBOT_CARD_STYLE = css`
4546
}
4647
`
4748

49+
const ROBOT_CARD_WRAP_SIZE = 650
50+
4851
interface RobotCardProps {
4952
robot: DiscoveredRobot
5053
}
@@ -54,6 +57,25 @@ export function RobotCard(props: RobotCardProps): JSX.Element | null {
5457
const { name: robotName = null, local } = robot
5558
const history = useHistory()
5659

60+
const robotCardRef = React.useRef(null)
61+
const { getElementProperty } = useGetElementDOMRectProperty<HTMLDivElement>(
62+
robotCardRef
63+
)
64+
const [robotCardWidth, setRobotCardWidth] = React.useState<number | null>(
65+
getElementProperty('width')
66+
)
67+
68+
const handleResize = React.useCallback((): void => {
69+
setRobotCardWidth(getElementProperty('width'))
70+
}, [getElementProperty])
71+
72+
React.useEffect(() => {
73+
window.addEventListener('resize', handleResize)
74+
return () => {
75+
window.removeEventListener('resize', handleResize)
76+
}
77+
}, [handleResize])
78+
5779
return robotName != null ? (
5880
<Flex
5981
alignItems={ALIGN_CENTER}
@@ -66,6 +88,7 @@ export function RobotCard(props: RobotCardProps): JSX.Element | null {
6688
width="100%"
6789
onClick={() => history.push(`/devices/${robotName}`)}
6890
cursor="pointer"
91+
ref={robotCardRef}
6992
>
7093
<img
7194
src={OT2_PNG}
@@ -112,14 +135,20 @@ export function RobotCard(props: RobotCardProps): JSX.Element | null {
112135
) : null}
113136
</Flex>
114137
{robot.status === CONNECTABLE ? (
115-
<Flex flexDirection={DIRECTION_ROW}>
116-
<Flex flex="4">
117-
<AttachedPipettes robotName={robotName} />
118-
</Flex>
119-
<Flex flex="1">
120-
<AttachedModules robotName={robotName} />
121-
</Flex>
122-
</Flex>
138+
<Box
139+
display="grid"
140+
css={
141+
robotCardWidth == null || robotCardWidth >= ROBOT_CARD_WRAP_SIZE
142+
? { 'grid-template-columns': '4fr 1fr' }
143+
: { 'grid-template-rows': '2fr 1fr' }
144+
}
145+
>
146+
<AttachedPipettes
147+
robotName={robotName}
148+
robotCardWidth={robotCardWidth}
149+
/>
150+
<AttachedModules robotName={robotName} />
151+
</Box>
123152
) : null}
124153
</Box>
125154
<RobotOverflowMenu robot={robot} alignSelf={ALIGN_START} />
@@ -132,10 +161,10 @@ function AttachedModules(props: { robotName: string }): JSX.Element | null {
132161
const { t } = useTranslation('devices_landing')
133162
const attachedModules = useAttachedModules()
134163
return attachedModules.length > 0 ? (
135-
<Flex
136-
flexDirection={DIRECTION_COLUMN}
164+
<Box
165+
display="grid"
166+
gridTemplateRows="1fr 1fr"
137167
paddingRight={SPACING.spacing4}
138-
width="100%"
139168
>
140169
<StyledText
141170
as="h6"
@@ -156,23 +185,29 @@ function AttachedModules(props: { robotName: string }): JSX.Element | null {
156185
/>
157186
))}
158187
</Flex>
159-
</Flex>
188+
</Box>
160189
) : (
161190
<Flex width="100%"></Flex>
162191
)
163192
}
164-
function AttachedPipettes(props: { robotName: string }): JSX.Element {
165-
const { robotName } = props
193+
function AttachedPipettes(props: {
194+
robotName: string
195+
robotCardWidth: number | null
196+
}): JSX.Element {
197+
const { robotName, robotCardWidth } = props
166198
const { t } = useTranslation('devices_landing')
167199
const attachedPipettes = useAttachedPipettes()
200+
168201
return (
169-
<Flex flexDirection={DIRECTION_ROW} width="100%">
170-
<Flex
171-
flex="1"
172-
flexDirection={DIRECTION_COLUMN}
173-
paddingRight={SPACING.spacing4}
174-
width="100%"
175-
>
202+
<Box
203+
display="grid"
204+
css={
205+
robotCardWidth == null || robotCardWidth >= ROBOT_CARD_WRAP_SIZE
206+
? { 'grid-template-columns': '1fr 1fr' }
207+
: { 'grid-template-rows': '1fr' }
208+
}
209+
>
210+
<Box gridTemplateRows="1fr 1fr" paddingRight={SPACING.spacing4}>
176211
<StyledText
177212
as="h6"
178213
textTransform={TEXT_TRANSFORM_UPPERCASE}
@@ -184,13 +219,8 @@ function AttachedPipettes(props: { robotName: string }): JSX.Element {
184219
<StyledText as="p" id={`RobotCard_${robotName}_leftMountPipette`}>
185220
{attachedPipettes?.left?.modelSpecs.displayName ?? t('empty')}
186221
</StyledText>
187-
</Flex>
188-
<Flex
189-
flex="1"
190-
flexDirection={DIRECTION_COLUMN}
191-
paddingRight={SPACING.spacing4}
192-
width="100%"
193-
>
222+
</Box>
223+
<Box gridTemplateRows="1fr 1fr" paddingRight={SPACING.spacing4}>
194224
<StyledText
195225
as="h6"
196226
textTransform={TEXT_TRANSFORM_UPPERCASE}
@@ -202,8 +232,8 @@ function AttachedPipettes(props: { robotName: string }): JSX.Element {
202232
<StyledText as="p" id={`RobotCard_${robotName}_rightMountPipette`}>
203233
{attachedPipettes?.right?.modelSpecs.displayName ?? t('empty')}
204234
</StyledText>
205-
</Flex>
206-
</Flex>
235+
</Box>
236+
</Box>
207237
)
208238
}
209239

app/src/organisms/ProtocolsLanding/ProtocolCard.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ function AnalysisInfo(props: AnalysisInfoProps): JSX.Element {
135135
const { getElementProperty } = useGetElementDOMRectProperty<HTMLDivElement>(
136136
targetRef
137137
)
138+
const width = getElementProperty('width')
138139

139140
// TODO kj 07/06/2022: Currently, using hardcoded number to align elements
140141
// This should be removed in the future
@@ -146,9 +147,7 @@ function AnalysisInfo(props: AnalysisInfoProps): JSX.Element {
146147
size="6rem"
147148
height="auto"
148149
justifyContent={JUSTIFY_CENTER}
149-
alignItems={
150-
getElementProperty('height') <= 880 ? ALIGN_START : ALIGN_CENTER
151-
}
150+
alignItems={width == null || width <= 800 ? ALIGN_START : ALIGN_CENTER}
152151
data-testid={`ProtocolCard_deckLayout_${protocolDisplayName}`}
153152
>
154153
{
@@ -280,7 +279,7 @@ function AnalysisInfo(props: AnalysisInfoProps): JSX.Element {
280279
data-testid={`ProtocolCard_date_${protocolDisplayName}`}
281280
marginTop={SPACING.spacing3}
282281
justifyContent={
283-
getElementProperty('height') <= 880 ? JUSTIFY_FLEX_END : FLEX_NONE
282+
width == null || width <= 880 ? JUSTIFY_FLEX_END : FLEX_NONE
284283
}
285284
>
286285
<StyledText

app/src/organisms/ProtocolsLanding/useGetElementDOMRectProperty.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react'
22

33
type DOMRectProperty = keyof Omit<DOMRect, 'toJSON'>
44
interface props {
5-
getElementProperty: (property: DOMRectProperty) => number
5+
getElementProperty: (property: DOMRectProperty) => number | null
66
}
77

88
/**
@@ -26,13 +26,13 @@ export const useGetElementDOMRectProperty = <T extends HTMLElement>(
2626
elementRef: React.RefObject<T>
2727
): props => {
2828
const getElementProperty = React.useCallback(
29-
(targetProperty: DOMRectProperty): number => {
29+
(targetProperty: DOMRectProperty): number | null => {
3030
const clientRect = elementRef.current?.getBoundingClientRect()
3131
if (clientRect != null) {
3232
return clientRect[targetProperty]
3333
}
34-
// if clientRect is undefined, return 0
35-
return 0
34+
// if clientRect is undefined, return null
35+
return null
3636
},
3737
[elementRef]
3838
)

0 commit comments

Comments
 (0)