This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
Sphere/app/components/builds/BuildList.js

66 lines
1.8 KiB
JavaScript
Raw Normal View History

2016-03-11 11:53:55 +00:00
import React from 'react-native';
2016-03-13 19:28:22 +00:00
import GiftedListView from 'react-native-gifted-listview';
2016-03-11 20:56:26 +00:00
import GlobalStyles from '../../settings/styles';
2016-03-13 19:28:22 +00:00
import loaderHandler from 'react-native-busy-indicator/LoaderHandler';
2016-03-11 11:53:55 +00:00
import BuildItem from './BuildItem';
import BuildItemEnd from './BuildItemEnd';
2016-03-13 19:28:22 +00:00
import { getProjectRecentBuilds } from '../../api/CircleCI';
import _ from 'underscore';
2016-03-11 11:53:55 +00:00
const {
StyleSheet,
2016-03-13 19:28:22 +00:00
View
2016-03-11 11:53:55 +00:00
} = React;
const styles = StyleSheet.create({
listView: {
flex: 1,
flexDirection: 'column',
alignItems: 'stretch',
justifyContent: 'center',
flexWrap: 'wrap',
paddingHorizontal: 5
},
});
export default class BuildList extends React.Component {
constructor(props) {
super(props);
2016-03-13 19:28:22 +00:00
this._fetch = this._fetch.bind(this);
this.renderRow = this.renderRow.bind(this);
this.renderLimit = 20;
2016-03-11 11:53:55 +00:00
}
renderRow(build) {
2016-03-11 21:21:58 +00:00
if (build.build_time_millis < 1) {
return null;
}
const statusColour = GlobalStyles.get('CIRCLE_TEST_COLOURS').get(build.status.toUpperCase());
2016-03-11 20:56:26 +00:00
return <BuildItem build={build} project={this.props.project} statusColour={statusColour} />;
2016-03-11 11:53:55 +00:00
}
2016-03-13 19:28:22 +00:00
_fetch(page = 1, callback, options) {
const project = this.props.project;
2016-03-13 19:29:39 +00:00
getProjectRecentBuilds(project.username, project.reponame, this.renderLimit, this.renderLimit * (page - 1))
.then((recentBuilds) => {
2016-03-13 19:28:22 +00:00
recentBuilds = _.sortBy(recentBuilds, (b) => b.stop_time).reverse();
loaderHandler.hideLoader();
callback(recentBuilds, {
allLoaded: recentBuilds.length < this.renderLimit
});
});
}
2016-03-11 11:53:55 +00:00
render() {
return (
2016-03-13 19:28:22 +00:00
<View style={styles.listView}>
<GiftedListView
rowView={this.renderRow}
refreshable={true}
onFetch={this._fetch}
paginationAllLoadedView={() => <BuildItemEnd />}/>
2016-03-13 19:28:22 +00:00
</View>
2016-03-11 11:53:55 +00:00
);
}
};