Skip to content

Commit e44eb0b

Browse files
committed
Update component ErrorList
1 parent 9020a27 commit e44eb0b

File tree

1 file changed

+25
-31
lines changed

1 file changed

+25
-31
lines changed

src/common/components/utils/ErrorList.js

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,40 @@
11
import React from 'react';
22
import { connect } from 'react-redux';
33
import Grid from 'react-bootstrap/lib/Grid';
4+
import Alert from 'react-bootstrap/lib/Alert';
45
import Errors from '../../constants/Errors';
56
import { removeError } from '../../actions/errorActions';
67

8+
function renderMeta(error) {
9+
let messages = [];
10+
if (error.code === Errors.STATE_PRE_FETCHING_FAIL.code) {
11+
messages.push(error.meta.detail);
12+
}
13+
if (error.meta.path) {
14+
messages.push(`(at path '${error.meta.path}')`);
15+
}
16+
if (error.code === Errors.UNKNOWN_EXCEPTION.code) {
17+
messages.push(error.meta.toString());
18+
}
19+
return messages.map((message) => (
20+
<p key={message}>
21+
{message}
22+
</p>
23+
));
24+
}
25+
726
let ErrorList = ({ errors, dispatch }) => (
827
<Grid>
928
{errors.map((error) => (
10-
<div
29+
<Alert
1130
key={error.id}
12-
className="alert alert-danger alert-dismissible"
13-
role="alert"
31+
bsStyle="danger"
32+
onDismiss={() => dispatch(removeError(error.id))}
1433
>
15-
<button
16-
type="button"
17-
className="close"
18-
data-dismiss="alert"
19-
aria-label="Close"
20-
onClick={() => dispatch(removeError(error.id))}
21-
>
22-
<span aria-hidden="true">&times;</span>
23-
</button>
24-
<strong>{error.title}</strong>
34+
<h4>{error.title}</h4>
2535
{' ' + error.detail}
26-
{error.meta && [(
27-
<p key="0">
28-
{error.code === Errors.STATE_PRE_FETCHING_FAIL.code && (
29-
<span>{error.meta.detail}</span>
30-
)}
31-
</p>
32-
), (
33-
<p key="1">
34-
{error.meta.path && `(at path '${error.meta.path}')`}
35-
</p>
36-
), (
37-
<p key="2">
38-
{error.code === Errors.UNKNOWN_EXCEPTION.code && (
39-
<span>{error.meta.toString()}</span>
40-
)}
41-
</p>
42-
)]}
43-
</div>
36+
{error.meta && renderMeta(error)}
37+
</Alert>
4438
))}
4539
</Grid>
4640
);

0 commit comments

Comments
 (0)