-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app): add restart robot confirmation modal (#12850)
add restart robot confirmation modal and move Navigation components under organisms
- Loading branch information
Showing
16 changed files
with
279 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import * as React from 'react' | ||
import { useDispatch } from 'react-redux' | ||
import { useTranslation } from 'react-i18next' | ||
import { | ||
ALIGN_CENTER, | ||
COLORS, | ||
Flex, | ||
Icon, | ||
SPACING, | ||
TYPOGRAPHY, | ||
} from '@opentrons/components' | ||
|
||
import { StyledText } from '../../atoms/text' | ||
import { MenuList } from '../../atoms/MenuList' | ||
import { MenuItem } from '../../atoms/MenuList/MenuItem' | ||
import { home, ROBOT } from '../../redux/robot-controls' | ||
import { useLights } from '../Devices/hooks' | ||
import { RestartRobotConfirmationModal } from './RestartRobotConfirmationModal' | ||
|
||
import type { Dispatch } from '../../redux/types' | ||
|
||
interface NavigationMenuProps { | ||
onClick: React.MouseEventHandler | ||
robotName: string | ||
} | ||
|
||
export function NavigationMenu(props: NavigationMenuProps): JSX.Element { | ||
const { onClick, robotName } = props | ||
const { t, i18n } = useTranslation(['devices_landing', 'robot_controls']) | ||
const { lightsOn, toggleLights } = useLights() | ||
const dispatch = useDispatch<Dispatch>() | ||
const [ | ||
showRestartRobotConfirmationModal, | ||
setShowRestartRobotConfirmationModal, | ||
] = React.useState<boolean>(false) | ||
|
||
const handleRestart = (): void => { | ||
setShowRestartRobotConfirmationModal(true) | ||
} | ||
|
||
return ( | ||
<> | ||
{showRestartRobotConfirmationModal ? ( | ||
<RestartRobotConfirmationModal | ||
robotName={robotName} | ||
setShowRestartRobotConfirmationModal={ | ||
setShowRestartRobotConfirmationModal | ||
} | ||
/> | ||
) : null} | ||
<MenuList onClick={onClick} isOnDevice={true}> | ||
<MenuItem | ||
key="home-robot-arm" | ||
onClick={() => dispatch(home(robotName, ROBOT))} | ||
> | ||
<Flex alignItems={ALIGN_CENTER}> | ||
<Icon | ||
name="home-robot-arm" | ||
aria-label="home-robot-arm_icon" | ||
size="2.5rem" | ||
/> | ||
<StyledText | ||
as="h4" | ||
fontWeight={TYPOGRAPHY.fontWeightSemiBold} | ||
marginLeft={SPACING.spacing12} | ||
> | ||
{t('home_robot_arm')} | ||
</StyledText> | ||
</Flex> | ||
</MenuItem> | ||
<MenuItem key="restart" onClick={handleRestart}> | ||
<Flex alignItems={ALIGN_CENTER}> | ||
<Icon | ||
name="restart" | ||
size="2.5rem" | ||
color={COLORS.black} | ||
aria-label="restart_icon" | ||
/> | ||
<StyledText | ||
as="h4" | ||
fontWeight={TYPOGRAPHY.fontWeightSemiBold} | ||
marginLeft={SPACING.spacing12} | ||
> | ||
{t('robot_controls:restart_label')} | ||
</StyledText> | ||
</Flex> | ||
</MenuItem> | ||
<MenuItem key="light" onClick={toggleLights}> | ||
<Flex alignItems={ALIGN_CENTER}> | ||
<Icon | ||
name="light" | ||
size="2.5rem" | ||
color={COLORS.black} | ||
aria-label="light_icon" | ||
/> | ||
<StyledText | ||
as="h4" | ||
fontWeight={TYPOGRAPHY.fontWeightSemiBold} | ||
marginLeft={SPACING.spacing12} | ||
> | ||
{i18n.format( | ||
t(lightsOn ? 'lights_off' : 'lights_on'), | ||
'capitalize' | ||
)} | ||
</StyledText> | ||
</Flex> | ||
</MenuItem> | ||
</MenuList> | ||
</> | ||
) | ||
} |
77 changes: 77 additions & 0 deletions
77
app/src/organisms/Navigation/RestartRobotConfirmationModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import * as React from 'react' | ||
import { Trans, useTranslation } from 'react-i18next' | ||
import { useDispatch } from 'react-redux' | ||
|
||
import { | ||
COLORS, | ||
DIRECTION_COLUMN, | ||
DIRECTION_ROW, | ||
Flex, | ||
SPACING, | ||
} from '@opentrons/components' | ||
|
||
import { StyledText } from '../../atoms/text' | ||
import { SmallButton } from '../../atoms/buttons' | ||
import { Modal } from '../../molecules/Modal/OnDeviceDisplay' | ||
import { restartRobot } from '../../redux/robot-admin' | ||
|
||
import { Dispatch } from '../../redux/types' | ||
import { ModalHeaderBaseProps } from '../../molecules/Modal/OnDeviceDisplay/types' | ||
|
||
interface RestartRobotConfirmationModalProps { | ||
robotName: string | ||
setShowRestartRobotConfirmationModal: ( | ||
showRestartRobotConfirmationModal: boolean | ||
) => void | ||
} | ||
export function RestartRobotConfirmationModal({ | ||
robotName, | ||
setShowRestartRobotConfirmationModal, | ||
}: RestartRobotConfirmationModalProps): JSX.Element { | ||
const { i18n, t } = useTranslation(['device_settings', 'shared']) | ||
const modalHeader: ModalHeaderBaseProps = { | ||
title: t('restart_now'), | ||
iconName: 'ot-alert', | ||
iconColor: COLORS.yellow2, | ||
} | ||
const dispatch = useDispatch<Dispatch>() | ||
|
||
return ( | ||
<Modal header={modalHeader}> | ||
<Flex | ||
flexDirection={DIRECTION_COLUMN} | ||
gridGap={SPACING.spacing40} | ||
width="100%" | ||
> | ||
<Trans | ||
t={t} | ||
i18nKey="restart_robot_confirmation_description" | ||
values={{ robotName: robotName }} | ||
components={{ | ||
bold: <strong />, | ||
span: ( | ||
<StyledText | ||
as="p" | ||
data-testid="restart_robot_confirmation_description" | ||
/> | ||
), | ||
}} | ||
/> | ||
<Flex flexDirection={DIRECTION_ROW} gridGap={SPACING.spacing8}> | ||
<SmallButton | ||
flex="1" | ||
buttonType="primary" | ||
buttonText={t('shared:go_back')} | ||
onClick={() => setShowRestartRobotConfirmationModal(false)} | ||
/> | ||
<SmallButton | ||
flex="1" | ||
buttonType="alert" | ||
buttonText={i18n.format(t('shared:restart'), 'capitalize')} | ||
onClick={() => dispatch(restartRobot(robotName))} | ||
/> | ||
</Flex> | ||
</Flex> | ||
</Modal> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
app/src/organisms/Navigation/__tests__/RestartRobotConfirmationModal.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import * as React from 'react' | ||
|
||
import { renderWithProviders } from '@opentrons/components' | ||
|
||
import { i18n } from '../../../i18n' | ||
import { restartRobot } from '../../../redux/robot-admin' | ||
import { RestartRobotConfirmationModal } from '../RestartRobotConfirmationModal' | ||
|
||
jest.mock('../../../redux/robot-admin') | ||
|
||
const mockFunc = jest.fn() | ||
const mockRestartRobot = restartRobot as jest.MockedFunction< | ||
typeof restartRobot | ||
> | ||
const render = ( | ||
props: React.ComponentProps<typeof RestartRobotConfirmationModal> | ||
) => { | ||
return renderWithProviders(<RestartRobotConfirmationModal {...props} />, { | ||
i18nInstance: i18n, | ||
}) | ||
} | ||
|
||
describe('RestartRobotConfirmationModal', () => { | ||
let props: React.ComponentProps<typeof RestartRobotConfirmationModal> | ||
|
||
beforeEach(() => { | ||
props = { | ||
robotName: 'mockRobotName', | ||
setShowRestartRobotConfirmationModal: mockFunc, | ||
} | ||
}) | ||
|
||
it('should render text and buttons', () => { | ||
const [{ getByText, getByTestId }] = render(props) | ||
getByText('Restart now?') | ||
getByTestId('restart_robot_confirmation_description') | ||
getByText('Go back') | ||
getByText('Restart') | ||
}) | ||
|
||
it('should call a mock function when tapping go back button', () => { | ||
const [{ getByText }] = render(props) | ||
getByText('Go back').click() | ||
expect(mockFunc).toHaveBeenCalled() | ||
}) | ||
|
||
it('should call mock restart function when tapping restart', () => { | ||
const [{ getByText }] = render(props) | ||
getByText('Restart').click() | ||
expect(mockRestartRobot).toHaveBeenCalled() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.