-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app,app-shell): create desktop app error boundary (#14323)
this error boundary will capture a runtime error anywhere in the desktop app and show a general error modal with error message instead of an app whitescreen. on clicking the "Reload app" button, the app navigates to the root page and initiates an electron browser window reload via a new RELOAD_UI action that is registered in the app-shell ui module.
- Loading branch information
1 parent
15ece39
commit cb819ee
Showing
8 changed files
with
148 additions
and
36 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
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,64 @@ | ||
import * as React from 'react' | ||
import { useDispatch } from 'react-redux' | ||
import { useHistory } from 'react-router-dom' | ||
import { useTranslation } from 'react-i18next' | ||
|
||
import { useTrackEvent, ANALYTICS_DESKTOP_APP_ERROR } from '../redux/analytics' | ||
|
||
import type { FallbackProps } from 'react-error-boundary' | ||
|
||
import { | ||
AlertPrimaryButton, | ||
ALIGN_FLEX_END, | ||
DIRECTION_COLUMN, | ||
Flex, | ||
SPACING, | ||
TYPOGRAPHY, | ||
} from '@opentrons/components' | ||
|
||
import { StyledText } from '../atoms/text' | ||
import { LegacyModal } from '../molecules/LegacyModal' | ||
import { reloadUi } from '../redux/shell' | ||
|
||
import type { Dispatch } from '../redux/types' | ||
|
||
export function DesktopAppFallback({ error }: FallbackProps): JSX.Element { | ||
const { t } = useTranslation('app_settings') | ||
const trackEvent = useTrackEvent() | ||
const dispatch = useDispatch<Dispatch>() | ||
const history = useHistory() | ||
const handleReloadClick = (): void => { | ||
trackEvent({ | ||
name: ANALYTICS_DESKTOP_APP_ERROR, | ||
properties: { errorMessage: error.message }, | ||
}) | ||
// route to the root page and initiate an electron browser window reload via app-shell | ||
history.push('/') | ||
dispatch(reloadUi(error.message)) | ||
} | ||
|
||
return ( | ||
<LegacyModal | ||
type="warning" | ||
title={t('error_boundary_title')} | ||
marginLeft="0" | ||
> | ||
<Flex flexDirection={DIRECTION_COLUMN} gridGap={SPACING.spacing32}> | ||
<Flex flexDirection={DIRECTION_COLUMN} gridGap={SPACING.spacing8}> | ||
<StyledText as="p"> | ||
{t('error_boundary_desktop_app_description')} | ||
</StyledText> | ||
<StyledText as="p" fontWeight={TYPOGRAPHY.fontWeightSemiBold}> | ||
{error.message} | ||
</StyledText> | ||
</Flex> | ||
<AlertPrimaryButton | ||
alignSelf={ALIGN_FLEX_END} | ||
onClick={handleReloadClick} | ||
> | ||
{t('reload_app')} | ||
</AlertPrimaryButton> | ||
</Flex> | ||
</LegacyModal> | ||
) | ||
} |
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 |
---|---|---|
|
@@ -34,6 +34,7 @@ | |
"enable_dev_tools": "Developer Tools", | ||
"enable_dev_tools_description": "Enabling this setting opens Developer Tools on app launch, enables additional logging and gives access to feature flags.", | ||
"error_boundary_description": "You need to restart the touchscreen. Then download the robot logs from the Opentrons App and send them to [email protected] for assistance.", | ||
"error_boundary_desktop_app_description": "You need to reload the app. Contact support with the following error message:", | ||
"error_boundary_title": "An unknown error has occurred", | ||
"feature_flags": "Feature Flags", | ||
"general": "General", | ||
|
@@ -71,6 +72,7 @@ | |
"prompt": "Always show the prompt to choose calibration block or trash bin", | ||
"receive_alert": "Receive an alert when an Opentrons software update is available.", | ||
"release_notes": "Release notes", | ||
"reload_app": "Reload app", | ||
"remind_later": "Remind me later", | ||
"reset_to_default": "Reset to default", | ||
"restart_touchscreen": "Restart touchscreen", | ||
|
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