Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export {
ThemeProvider,
CacheProvider as EmotionCacheProvider,
withTheme,
type SerializedStyles,
} from '@emotion/react';
export { default as createEmotionCache } from '@emotion/cache';

Expand Down
5 changes: 4 additions & 1 deletion superset-frontend/src/components/ErrorBoundary/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface ErrorBoundaryProps {
children: ReactNode;
onError?: (error: Error, info: ErrorInfo) => void;
showMessage?: boolean;
className?: string;
}

interface ErrorBoundaryState {
Expand Down Expand Up @@ -51,14 +52,16 @@ export default class ErrorBoundary extends Component<

render() {
const { error, info } = this.state;
const { showMessage, className } = this.props;
if (error) {
const firstLine = error.toString().split('\n')[0];
if (this.props.showMessage) {
if (showMessage) {
return (
<ErrorAlert
errorType={t('Unexpected error')}
message={firstLine}
descriptionDetails={info?.componentStack}
className={className}
/>
);
}
Expand Down
6 changes: 4 additions & 2 deletions superset-frontend/src/components/ErrorMessage/ErrorAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface ErrorAlertProps {
children?: React.ReactNode; // Additional content to show in the modal
closable?: boolean; // Show close button, default true
showIcon?: boolean; // Show icon, default true
className?: string;
}

const ErrorAlert: React.FC<ErrorAlertProps> = ({
Expand All @@ -49,6 +50,7 @@ const ErrorAlert: React.FC<ErrorAlertProps> = ({
children,
closable = true,
showIcon = true,
className,
}) => {
const [isDescriptionVisible, setIsDescriptionVisible] = useState(
!descriptionDetailsCollapsed,
Expand All @@ -66,7 +68,7 @@ const ErrorAlert: React.FC<ErrorAlertProps> = ({
const color =
type === 'warning' ? theme.colors.warning.base : theme.colors.error.base;
return (
<div style={{ cursor: 'pointer' }}>
<div className={className} style={{ cursor: 'pointer' }}>
<span style={{ color }}>{icon} </span>
{errorType}
</div>
Expand Down Expand Up @@ -100,13 +102,13 @@ const ErrorAlert: React.FC<ErrorAlertProps> = ({
)}
</div>
);

const renderAlert = (closable: boolean) => (
<Alert
description={renderDescription()}
type={type}
showIcon
closable={closable}
className={className}
>
<strong>{errorType}</strong>
{message && (
Expand Down
20 changes: 14 additions & 6 deletions superset-frontend/src/views/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
useLocation,
} from 'react-router-dom';
import { bindActionCreators } from 'redux';
import { css } from '@superset-ui/core';
import { GlobalStyles } from 'src/GlobalStyles';
import ErrorBoundary from 'src/components/ErrorBoundary';
import Loading from 'src/components/Loading';
Expand Down Expand Up @@ -83,12 +84,19 @@ const App = () => (
{routes.map(({ path, Component, props = {}, Fallback = Loading }) => (
<Route path={path} key={path}>
<Suspense fallback={<Fallback />}>
<Layout.Content>
<div style={{ padding: '16px' }}>
<ErrorBoundary>
<Component user={bootstrapData.user} {...props} />
</ErrorBoundary>
</div>
<Layout.Content
css={css`
display: flex;
flex-direction: column;
`}
>
<ErrorBoundary
css={css`
margin: 16px;
`}
>
<Component user={bootstrapData.user} {...props} />
</ErrorBoundary>
</Layout.Content>
</Suspense>
</Route>
Expand Down
Loading