-
Notifications
You must be signed in to change notification settings - Fork 180
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(app): add InterventionModal to Error Recovery #15277
Changes from 7 commits
192f12f
e431fdd
00d4809
354fdb8
826d059
ddd9c1e
8d2489a
e900cbd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
import * as React from 'react' | ||
import { useSelector } from 'react-redux' | ||
|
||
import { | ||
ALIGN_CENTER, | ||
BORDERS, | ||
|
@@ -7,6 +9,7 @@ import { | |
Flex, | ||
Icon, | ||
JUSTIFY_CENTER, | ||
JUSTIFY_SPACE_BETWEEN, | ||
OVERFLOW_AUTO, | ||
POSITION_ABSOLUTE, | ||
POSITION_RELATIVE, | ||
|
@@ -15,6 +18,8 @@ import { | |
} from '@opentrons/components' | ||
import type { IconName } from '@opentrons/components' | ||
|
||
import { getIsOnDevice } from '../../redux/config' | ||
|
||
export type ModalType = 'intervention-required' | 'error' | ||
|
||
const BASE_STYLE = { | ||
|
@@ -32,20 +37,29 @@ const BASE_STYLE = { | |
|
||
const BORDER_STYLE_BASE = `6px ${BORDERS.styleSolid}` | ||
|
||
const MODAL_STYLE = { | ||
const MODAL_BASE_STYLE = { | ||
backgroundColor: COLORS.white, | ||
position: POSITION_RELATIVE, | ||
overflowY: OVERFLOW_AUTO, | ||
maxHeight: '100%', | ||
width: '47rem', | ||
borderRadius: BORDERS.borderRadius8, | ||
boxShadow: BORDERS.smallDropShadow, | ||
'data-testid': '__otInterventionModal', | ||
} as const | ||
|
||
const MODAL_DESKTOP_STYLE = { | ||
...MODAL_BASE_STYLE, | ||
maxHeight: '100%', | ||
width: '47rem', | ||
} as const | ||
|
||
const MODAL_ODD_STYLE = { | ||
...MODAL_BASE_STYLE, | ||
width: '62rem', | ||
height: '35.5rem', | ||
} as const | ||
|
||
const HEADER_STYLE = { | ||
alignItems: ALIGN_CENTER, | ||
gridGap: SPACING.spacing12, | ||
padding: `${SPACING.spacing20} ${SPACING.spacing32}`, | ||
color: COLORS.white, | ||
position: POSITION_STICKY, | ||
|
@@ -69,38 +83,56 @@ const INTERVENTION_REQUIRED_COLOR = COLORS.blue50 | |
const ERROR_COLOR = COLORS.red50 | ||
|
||
export interface InterventionModalProps { | ||
/** optional modal heading **/ | ||
heading?: React.ReactNode | ||
/** Optional modal title heading. Aligned to the left. */ | ||
titleHeading?: React.ReactNode | ||
/** Optional modal heading right of the icon. Aligned right if titleHeading is supplied, otherwise aligned left. **/ | ||
iconHeading?: React.ReactNode | ||
/** Optional onClick for the icon heading and icon. */ | ||
iconHeadingOnClick?: () => void | ||
/** overall style hint */ | ||
type?: ModalType | ||
/** optional icon name */ | ||
iconName?: IconName | null | undefined | ||
/** modal contents */ | ||
children: React.ReactNode | ||
} | ||
|
||
// TOME: Do ODD test styling and mocking! | ||
mjhuff marked this conversation as resolved.
Show resolved
Hide resolved
|
||
export function InterventionModal(props: InterventionModalProps): JSX.Element { | ||
const modalType = props.type ?? 'intervention-required' | ||
const headerColor = | ||
modalType === 'error' ? ERROR_COLOR : INTERVENTION_REQUIRED_COLOR | ||
const border = `${BORDER_STYLE_BASE} ${ | ||
modalType === 'error' ? ERROR_COLOR : INTERVENTION_REQUIRED_COLOR | ||
}` | ||
const headerJustifyContent = | ||
props.titleHeading != null ? JUSTIFY_SPACE_BETWEEN : undefined | ||
|
||
const isOnDevice = useSelector(getIsOnDevice) | ||
const modalStyle = isOnDevice ? MODAL_ODD_STYLE : MODAL_DESKTOP_STYLE | ||
|
||
return ( | ||
<Flex {...WRAPPER_STYLE}> | ||
<Flex {...BASE_STYLE} zIndex={10}> | ||
<Box | ||
{...MODAL_STYLE} | ||
{...modalStyle} | ||
border={border} | ||
onClick={(e: React.MouseEvent) => { | ||
e.stopPropagation() | ||
}} | ||
> | ||
<Flex {...HEADER_STYLE} backgroundColor={headerColor}> | ||
{props.iconName != null ? ( | ||
<Icon name={props.iconName} size={SPACING.spacing32} /> | ||
) : null} | ||
{props.heading != null ? props.heading : null} | ||
<Flex | ||
{...HEADER_STYLE} | ||
backgroundColor={headerColor} | ||
justifyContent={headerJustifyContent} | ||
onClick={props.iconHeadingOnClick} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we destruct There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, can add in my next PR. Sorry I didn't see these in time 👍 |
||
> | ||
{props.titleHeading} | ||
<Flex alignItems={ALIGN_CENTER} gridGap={SPACING.spacing12}> | ||
{props.iconName != null ? ( | ||
<Icon name={props.iconName} size={SPACING.spacing32} /> | ||
) : null} | ||
{props.iconHeading != null ? props.iconHeading : null} | ||
</Flex> | ||
</Flex> | ||
{props.children} | ||
</Box> | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you move this import before import type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh woops, I'll refactor this in my next PR 👍