From 56858390cab58401d313cc62a73f681fd79f0e76 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Thu, 7 Apr 2022 11:24:07 -0500 Subject: [PATCH] notifications: allow viewing stack trace of unexpected error Previously, it was only possible to view the stack trace by clicking the copy button and pasting it somewhere. --- .../UnexpectedErrorNotification.scss | 10 +++++++++ .../UnexpectedErrorNotification.tsx | 21 +++++++++++++++++-- src/notifications/i18n.ts | 1 + src/notifications/translations/en.json | 1 + src/utils/react.ts | 17 ++++++++++++++- 5 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 src/notifications/UnexpectedErrorNotification.scss diff --git a/src/notifications/UnexpectedErrorNotification.scss b/src/notifications/UnexpectedErrorNotification.scss new file mode 100644 index 00000000..c0ac8343 --- /dev/null +++ b/src/notifications/UnexpectedErrorNotification.scss @@ -0,0 +1,10 @@ +// SPDX-License-Identifier: MIT +// Copyright (c) 2022 The Pybricks Authors + +@import '../variables.scss'; + +pre.pb-notification-stack-trace { + max-width: $pt-grid-size * 50; + max-height: $pt-grid-size * 50; + overflow: auto; +} diff --git a/src/notifications/UnexpectedErrorNotification.tsx b/src/notifications/UnexpectedErrorNotification.tsx index 62b90207..66705e38 100644 --- a/src/notifications/UnexpectedErrorNotification.tsx +++ b/src/notifications/UnexpectedErrorNotification.tsx @@ -3,9 +3,11 @@ // Provides special notification contents for unexpected errors. -import { AnchorButton, Button, ButtonGroup, Intent } from '@blueprintjs/core'; +import './UnexpectedErrorNotification.scss'; +import { AnchorButton, Button, ButtonGroup, Collapse, Intent } from '@blueprintjs/core'; import { useI18n } from '@shopify/react-i18n'; -import React from 'react'; +import React, { useState } from 'react'; +import { useUniqueId } from '../utils/react'; import { I18nId } from './i18n'; type UnexpectedErrorNotificationProps = { @@ -18,10 +20,25 @@ const UnexpectedErrorNotification: React.VoidFunctionComponent< > = ({ messageId, err }) => { // istanbul ignore next: babel-loader rewrites this line const [i18n] = useI18n(); + const [isExpanded, setIsExpanded] = useState(false); + const labelId = useUniqueId('pb-notification'); return ( <>

{i18n.translate(messageId, { errorMessage: err.message })}

+ +