feat: refactor error components and add database issue code (#10473)

* feat: refactor error components and add database issue code

* Apply suggestions from code review

Co-authored-by: John Bodley <4567245+john-bodley@users.noreply.github.com>

Co-authored-by: John Bodley <4567245+john-bodley@users.noreply.github.com>
This commit is contained in:
Erik Ritter
2020-08-06 13:22:24 -07:00
committed by GitHub
parent 62b873e3da
commit 2055ecc1ba
35 changed files with 384 additions and 185 deletions

View File

@@ -16,13 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
import React, { useState } from 'react';
// @ts-ignore
import { Alert, Collapse } from 'react-bootstrap';
import React from 'react';
import { t } from '@superset-ui/translation';
import getErrorMessageComponentRegistry from './getErrorMessageComponentRegistry';
import { SupersetError, ErrorSource } from './types';
import ErrorAlert from './ErrorAlert';
type Props = {
error?: SupersetError;
@@ -39,8 +38,6 @@ export default function ErrorMessageWithStackTrace({
stackTrace,
source,
}: Props) {
const [showStackTrace, setShowStackTrace] = useState(false);
// Check if a custom error message component was registered for this message
if (error) {
const ErrorMessageComponent = getErrorMessageComponentRegistry().get(
@@ -51,25 +48,26 @@ export default function ErrorMessageWithStackTrace({
}
}
// Fallback to the default error message renderer
return (
<div className={`stack-trace-container${stackTrace ? ' has-trace' : ''}`}>
<Alert
bsStyle="warning"
onClick={() => setShowStackTrace(!showStackTrace)}
>
{message || t('An error occurred.')}
{link && (
<a href={link} target="_blank" rel="noopener noreferrer">
(Request Access)
</a>
)}
</Alert>
{stackTrace && (
<Collapse in={showStackTrace}>
<pre>{stackTrace}</pre>
</Collapse>
)}
</div>
<ErrorAlert
level="warning"
title={t('Unexpected Error')}
subtitle={message}
copyText={message}
source={source}
body={
link || stackTrace ? (
<>
{link && (
<a href={link} target="_blank" rel="noopener noreferrer">
(Request Access)
</a>
)}
<br />
{stackTrace && <pre>{stackTrace}</pre>}
</>
) : undefined
}
/>
);
}