Skip to content

Commit 3eedc50

Browse files
authored
Merge pull request #11 from cloudhx/iss7
Added new feature: retrieve issues by clicking Refresh button. [Issue 7]
2 parents dad704e + 554529d commit 3eedc50

File tree

3 files changed

+63
-49
lines changed

3 files changed

+63
-49
lines changed

src/components/issues/IssueList.js

Lines changed: 54 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,64 @@
11
import React from "react";
22
import PropTypes from "prop-types";
33

4-
const IssueList = ({ issues, onCloseClick }) => (
5-
<table className="table">
6-
<thead>
7-
<tr>
8-
<th>Title</th>
9-
<th>Labels</th>
10-
<th>Assignee</th>
11-
<th>State</th>
12-
<th />
13-
</tr>
14-
</thead>
15-
<tbody>
16-
{issues.map(issue => {
17-
return (
18-
<tr key={issue.id}>
19-
<td>
20-
<a
21-
href={issue.html_url}
22-
target="_blank"
23-
rel="noopener noreferrer"
24-
>
25-
{issue.title}
26-
</a>
27-
</td>
28-
<td>
29-
{issue.labels.map(label => (
30-
<React.Fragment key={label.id}>
31-
<span className="badge badge-primary">{label.name}</span>
32-
<span> </span>
33-
</React.Fragment>
34-
))}
35-
</td>
36-
<td>{issue.assignee.login}</td>
37-
<td>{issue.state}</td>
38-
<td>
39-
<button
40-
className="btn btn-outline-danger"
41-
onClick={() => onCloseClick(issue)}
42-
>
43-
Close
44-
</button>
45-
</td>
46-
</tr>
47-
);
48-
})}
49-
</tbody>
50-
</table>
4+
const IssueList = ({ issues, onCloseClick, onRefreshClick }) => (
5+
<>
6+
<button className="btn btn-primary my-2" onClick={() => onRefreshClick()}>
7+
Refresh
8+
</button>
9+
<table className="table">
10+
<thead>
11+
<tr>
12+
<th>Title</th>
13+
<th>Labels</th>
14+
<th>Assignee</th>
15+
<th>State</th>
16+
<th />
17+
</tr>
18+
</thead>
19+
<tbody>
20+
{issues.map(issue => {
21+
return (
22+
<tr key={issue.id}>
23+
<td>
24+
<a
25+
href={issue.html_url}
26+
target="_blank"
27+
rel="noopener noreferrer"
28+
>
29+
{issue.title}
30+
</a>
31+
</td>
32+
<td>
33+
{issue.labels.map(label => (
34+
<React.Fragment key={label.id}>
35+
<span className="badge badge-primary">{label.name}</span>
36+
<span> </span>
37+
</React.Fragment>
38+
))}
39+
</td>
40+
<td>{issue.assignee.login}</td>
41+
<td>{issue.state}</td>
42+
<td>
43+
<button
44+
className="btn btn-outline-danger"
45+
onClick={() => onCloseClick(issue)}
46+
>
47+
Close
48+
</button>
49+
</td>
50+
</tr>
51+
);
52+
})}
53+
</tbody>
54+
</table>
55+
</>
5156
);
5257

5358
IssueList.propTypes = {
5459
issues: PropTypes.array.isRequired,
55-
onCloseClick: PropTypes.func.isRequired
60+
onCloseClick: PropTypes.func.isRequired,
61+
onRefreshClick: PropTypes.func.isRequired
5662
};
5763

5864
export default IssueList;

src/components/issues/IssuesPage.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ class IssuesPage extends React.Component {
2727
}
2828
};
2929

30+
handleRefresh = () => {
31+
this.props.actions.loadIssues().catch(error => {
32+
alert("Loading issues failed" + error);
33+
});
34+
};
35+
3036
render() {
3137
return (
3238
<>
@@ -37,6 +43,7 @@ class IssuesPage extends React.Component {
3743
<IssueList
3844
issues={this.props.issues}
3945
onCloseClick={this.handleClose}
46+
onRefreshClick={this.handleRefresh}
4047
/>
4148
)}
4249
</>

src/components/issues/issueList.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ function renderIssueList(args) {
99
let defaultProps = {
1010
issues: [],
1111
closing: false,
12-
onCloseClick: () => {}
12+
onCloseClick: () => {},
13+
onRefreshClick: () => {}
1314
};
1415
const props = { ...defaultProps, ...args };
1516
return render(

0 commit comments

Comments
 (0)