Skip to content

Commit

Permalink
feat: make dismiss errors button optional in ErrorBanner component
Browse files Browse the repository at this point in the history
If the function prop clearErrors is not provided, the button to clear errors
is not displayed
  • Loading branch information
csm-thu committed Jul 11, 2022
1 parent 0f6e6f9 commit 3491d22
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/misc/ErrorBanner/ErrorBanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,18 @@ export const ErrorBanner = (props) => {
{copyButtonText}
</Button>
)}
<Button
className={classes.errorButton}
size="small"
color="inherit"
variant="outlined"
data-cy="dismiss-error-button"
onClick={clearErrors}
>
{labels.dismissButtonText}
</Button>
{clearErrors && (
<Button
className={classes.errorButton}
size="small"
color="inherit"
variant="outlined"
data-cy="dismiss-error-button"
onClick={clearErrors}
>
{labels.dismissButtonText}
</Button>
)}
</div>
</Paper>
</Slide>
Expand All @@ -51,19 +53,20 @@ export const ErrorBanner = (props) => {

ErrorBanner.propTypes = {
error: PropTypes.object.isRequired,
clearErrors: PropTypes.func.isRequired,
clearErrors: PropTypes.func,
labels: PropTypes.shape({
tooLongErrorMessage: PropTypes.string,
dismissButtonText: PropTypes.string.isRequired,
dismissButtonText: PropTypes.string,
secondButtonText: PropTypes.string.isRequired,
toggledButtonText: PropTypes.string,
}),
};
ErrorBanner.defaultProps = {
labels: {
dismissButtonText: 'Dismiss',
tooLongErrorMessage:
// eslint-disable-next-line max-len
'Detailed error message is too long to be displayed. To read it, please use the COPY button and paste it in your favorite text editor.',
'Detailed error message is too long to be displayed. To read it, please use the COPY button and paste it in ' +
'your favorite text editor.',
toggledButtonText: 'Copied',
},
};

0 comments on commit 3491d22

Please sign in to comment.