Merge pull request #205 from alexef/filter-main-branch

Filter main branch
This commit is contained in:
Laszlo Fogas 2021-05-27 16:10:21 +02:00 committed by GitHub
commit 9bf8e05fd0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 3 deletions

View file

@ -9,7 +9,7 @@
"lesshint": "lesshint --config .lesshintrc src/",
"test": "jest",
"start": "webpack-dev-server --progress --hot --inline",
"format": "prettier --use-tabs --trailing-comma all --write {src/*.js,src/**/*.js,src/**/*/*.js,src/*/*/*/*.js,src/*/*/*/*/*.js,src/*/*/*/*/*/*.js,src/*/*/*/*/*/*.js,src/*/*/*/*/*/*/*.js}"
"format": "prettier --trailing-comma all --write {src/*.js,src/**/*.js,src/**/*/*.js,src/*/*/*/*.js,src/*/*/*/*/*.js,src/*/*/*/*/*/*.js,src/*/*/*/*/*/*.js,src/*/*/*/*/*/*/*.js}"
},
"jest": {
"moduleFileExtensions": [

View file

@ -28,6 +28,7 @@ export default class Main extends Component {
super(props, context);
this.fetchNextBuildPage = this.fetchNextBuildPage.bind(this);
this.selectBranch = this.selectBranch.bind(this);
}
componentWillMount() {
@ -40,7 +41,8 @@ export default class Main extends Component {
(nextProps.builds !== undefined &&
this.props.builds !== nextProps.builds) ||
this.props.error !== nextProps.error ||
this.props.loaded !== nextProps.loaded
this.props.loaded !== nextProps.loaded ||
this.state.branch !== nextState.branch
);
}
@ -79,8 +81,15 @@ export default class Main extends Component {
);
}
selectBranch(branch) {
this.setState({
branch: branch,
});
}
render() {
const { repo, builds, loaded, error } = this.props;
const { branch } = this.state;
const list = Object.values(builds || {});
function renderBuild(build) {
@ -91,6 +100,10 @@ export default class Main extends Component {
);
}
const filterBranch = build => {
return !branch || build.branch === branch;
};
if (error) {
return <div>Not Found</div>;
}
@ -109,7 +122,23 @@ export default class Main extends Component {
return (
<div className={styles.root}>
<List>{list.sort(compareBuild).map(renderBuild)}</List>
<div className={styles.right}>
{!branch ? (
<button onClick={() => this.selectBranch(repo.default_branch)}>
Show {repo.default_branch} branch only
</button>
) : (
<button onClick={() => this.selectBranch(undefined)}>
Show all branches
</button>
)}
</div>
<List>
{list
.sort(compareBuild)
.filter(filterBranch)
.map(renderBuild)}
</List>
{list.length < repo.last_build && (
<button
onClick={() => this.fetchNextBuildPage(list)}

View file

@ -22,3 +22,7 @@ button {
margin-top: 10px;
}
}
.right {
text-align: right;
}