Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor ErrorContent to use styled slots #3826

Merged
merged 1 commit into from
Nov 30, 2023
Merged
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
61 changes: 31 additions & 30 deletions src/components/ErrorContent.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
import { Component } from 'react';
import PropTypes from 'prop-types';
import { styled } from '@mui/material/styles';
import Accordion from '@mui/material/Accordion';
import AccordionSummary from '@mui/material/AccordionSummary';
import AccordionDetails from '@mui/material/AccordionDetails';
import Typography from '@mui/material/Typography';
import Stack from '@mui/material/Stack';
import Alert from '@mui/material/Alert';
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import { PluginHook } from './PluginHook';

const ErrorStackTrace = styled('pre', { name: 'ErrorContent', slot: 'stacktrace' })({
overflowY: 'scroll',
});

const ErrorMetadata = styled('pre', { name: 'ErrorContent', slot: 'metadata' })({
height: '100px',
overflowY: 'scroll',
});

const InlineAccordion = styled(Accordion, { name: 'ErrorContent', slot: 'accordion' })({
backgroundColor: 'inherit',
color: 'inherit',
margin: 0,
});

/** */
export class ErrorContent extends Component {
/** */
Expand All @@ -22,38 +38,23 @@ export class ErrorContent extends Component {
if (!showJsError) return null;

return (
<>
<Alert elevation={6} variant="filled" severity="error">
{t('errorDialogTitle')}
</Alert>

<Alert elevation={6} variant="filled" severity="error">
{t('errorDialogTitle')}
{showJsError && (
<Accordion
square
sx={{
backgroundColor: 'error.main',
color: '#fff',
fontWeight: 'fontWeightMedium',
}}
>
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
<Typography>{t('jsError', { message: error.message, name: error.name })}</Typography>
</AccordionSummary>
<AccordionDetails sx={{
'& pre': {
height: '100px',
overflowY: 'scroll',
},
flexDirection: 'column',
}}
>
<pre>{t('jsStack', { stack: error.stack })}</pre>
{metadata && <pre>{JSON.stringify(metadata, null, 2)}</pre>}
</AccordionDetails>
</Accordion>
<InlineAccordion elevation={2} square>
<AccordionSummary sx={{ marginInlineStart: '-1rem' }} expandIcon={<ExpandMoreIcon sx={{ color: '#fff' }} />}>
{t('jsError', { message: error.message, name: error.name })}
</AccordionSummary>
<AccordionDetails>
<Stack>
<ErrorStackTrace>{t('jsStack', { stack: error.stack })}</ErrorStackTrace>
{metadata && <ErrorMetadata>{JSON.stringify(metadata, null, 2)}</ErrorMetadata>}
</Stack>
</AccordionDetails>
</InlineAccordion>
)}
<PluginHook {...this.props} />
</>
</Alert>
);
}
}
Expand Down