Skip to content

Commit 3ff7737

Browse files
ayushsnhaExtravert-ir
authored andcommitted
changing into functional component and mapping stateToProps
1 parent 3a81d9d commit 3ff7737

File tree

4 files changed

+59
-52
lines changed

4 files changed

+59
-52
lines changed

client/src/components/BuildDetails.js

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,54 @@
11
import React from 'react';
2-
class BuildDetails extends React.Component {
3-
renderBuild = build => {
4-
return (
5-
<React.Fragment key={build.buildid}>
6-
<div className='col-sm-3'>
7-
<a
8-
target='_blank'
9-
rel='noreferrer noopener'
10-
href={`https://build.reactos.org/#builders/${
11-
build.builderid
12-
}/builds/${build.number}`}
13-
>
14-
{this.props.builders[build.builderid - 1].name}
15-
</a>
16-
</div>
17-
<div className='col-sm-3'>
18-
{build.state_string}
19-
{build.state_string === 'build successful' ? (
20-
<i className='fa fa-check' />
21-
) : (
22-
<i />
23-
)}
24-
</div>
25-
<div className='col-sm-3'>started_at:{build.started_at}</div>
26-
<div className='col-sm-3'>complete_at:{build.complete_at}</div>
27-
</React.Fragment>
28-
);
29-
};
30-
render() {
31-
return this.props.build ? (
32-
<React.Fragment>
33-
{this.props.build.length > 0 ? (
34-
<div className='row'>{this.props.build.map(this.renderBuild)}</div>
35-
) : (
36-
<p>
37-
<strong>No data Exists</strong>
38-
</p>
39-
)}
40-
</React.Fragment>
2+
import { connect } from 'react-redux';
3+
4+
function Build({builderid, number, builderName, started_at, complete_at, state_string}) {
5+
return (<React.Fragment>
6+
<div className='col-sm-3'>
7+
<a
8+
target='_blank'
9+
rel='noreferrer noopener'
10+
href={`https://build.reactos.org/#builders/${
11+
builderid
12+
}/builds/${number}`}
13+
>
14+
{builderName}
15+
</a>
16+
</div>
17+
<div className='col-sm-3'>
18+
{state_string}
19+
{state_string === 'build successful' ? (
20+
<i className='fa fa-check' />
21+
) : (
22+
<i />
23+
)}
24+
</div>
25+
<div className='col-sm-3'>started_at:{started_at}</div>
26+
<div className='col-sm-3'>complete_at:{complete_at}</div>
27+
</React.Fragment>);
28+
}
29+
30+
function renderBuild(props) {
31+
return <Build key={props.buildid} {...props} />;
32+
}
33+
34+
function BuildDetails({builds}) {
35+
return (<React.Fragment>
36+
{builds.length > 0 ? (
37+
<div className='row'>{builds.map(renderBuild)}</div>
4138
) : (
42-
<h6>No data Exists</h6>
43-
);
44-
}
39+
<p>
40+
<strong>No data Exists</strong>
41+
</p>
42+
)}
43+
</React.Fragment>);
4544
}
4645

47-
export default BuildDetails;
46+
const mapStateToProps = ({ builders }, ownProps) => {
47+
return {
48+
builds: ownProps.builds.map(
49+
build => {...build, builderName: builders[build.builderid].name}
50+
)
51+
};
52+
};
53+
54+
export default connect(mapStateToProps)(BuildDetails);

client/src/components/Commits.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ class Commits extends React.Component {
1414
renderCommits = commit => {
1515
return (
1616
<div className='panel-margin' key={commit.sha}>
17-
<CommitsCard
18-
{...commit}
19-
builds={this.props.build[commit.sha]}
20-
builders={this.props.builders}
21-
/>
17+
<CommitsCard {...commit} builds={this.props.build[commit.sha]} />
2218
</div>
2319
);
2420
};

client/src/components/CommitsCard.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ function CommitsCard(props) {
8181
</a>
8282
</div>
8383
</div>
84-
<h5>Build Details:</h5>
8584
<hr />
86-
<BuildDetails build={props.builds} builders={props.builders} />
85+
<h5>Build Details:</h5>
86+
<BuildDetails builds={props.builds} />
8787
</CardBody>
8888
</UncontrolledCollapse>
8989
</Card>

client/src/redux/reducers/builderReducer.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import { BUILDERS } from '../constants';
22

3-
const builderReducer = (state = [], action) => {
3+
const builderReducer = (state = {}, action) => {
44
if (action.type === BUILDERS.LOAD_SUCCESS) {
5-
return [...action.builders];
5+
const builders = {};
6+
for (const builder of action.builders) {
7+
builders[action.builders.builderid] = builder;
8+
}
9+
return builders;
610
}
711
return state;
812
};

0 commit comments

Comments
 (0)