Skip to content

Commit 3491d22

Browse files
committed
feat: make dismiss errors button optional in ErrorBanner component
If the function prop clearErrors is not provided, the button to clear errors is not displayed
1 parent 0f6e6f9 commit 3491d22

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

src/misc/ErrorBanner/ErrorBanner.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,18 @@ export const ErrorBanner = (props) => {
3333
{copyButtonText}
3434
</Button>
3535
)}
36-
<Button
37-
className={classes.errorButton}
38-
size="small"
39-
color="inherit"
40-
variant="outlined"
41-
data-cy="dismiss-error-button"
42-
onClick={clearErrors}
43-
>
44-
{labels.dismissButtonText}
45-
</Button>
36+
{clearErrors && (
37+
<Button
38+
className={classes.errorButton}
39+
size="small"
40+
color="inherit"
41+
variant="outlined"
42+
data-cy="dismiss-error-button"
43+
onClick={clearErrors}
44+
>
45+
{labels.dismissButtonText}
46+
</Button>
47+
)}
4648
</div>
4749
</Paper>
4850
</Slide>
@@ -51,19 +53,20 @@ export const ErrorBanner = (props) => {
5153

5254
ErrorBanner.propTypes = {
5355
error: PropTypes.object.isRequired,
54-
clearErrors: PropTypes.func.isRequired,
56+
clearErrors: PropTypes.func,
5557
labels: PropTypes.shape({
5658
tooLongErrorMessage: PropTypes.string,
57-
dismissButtonText: PropTypes.string.isRequired,
59+
dismissButtonText: PropTypes.string,
5860
secondButtonText: PropTypes.string.isRequired,
5961
toggledButtonText: PropTypes.string,
6062
}),
6163
};
6264
ErrorBanner.defaultProps = {
6365
labels: {
66+
dismissButtonText: 'Dismiss',
6467
tooLongErrorMessage:
65-
// eslint-disable-next-line max-len
66-
'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.',
68+
'Detailed error message is too long to be displayed. To read it, please use the COPY button and paste it in ' +
69+
'your favorite text editor.',
6770
toggledButtonText: 'Copied',
6871
},
6972
};

0 commit comments

Comments
 (0)