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

81 lines
2.1 KiB
JavaScript
Raw Permalink 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-05-05 14:18:07 +01:00
import { getProjectRecentBuilds } from '../../actions';
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-05-05 14:18:07 +01:00
import { connect } from 'react-redux';
2016-03-13 19:28:22 +00:00
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
},
});
2016-05-05 14:18:07 +01:00
export class BuildList extends React.Component {
2016-03-11 11:53:55 +00:00
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-05-05 14:18:07 +01:00
const actionCallback = function (recentBuilds) {
2016-03-13 19:28:22 +00:00
recentBuilds = _.sortBy(recentBuilds, (b) => b.stop_time).reverse();
callback(recentBuilds, {
allLoaded: recentBuilds.length < this.renderLimit
});
2016-05-05 14:18:07 +01:00
loaderHandler.hideLoader();
}.bind(this);
this.props.getProjectRecentBuilds(
project.username,
project.reponame,
this.renderLimit,
this.renderLimit * (page - 1),
actionCallback
);
2016-03-13 19:28:22 +00:00
}
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
);
}
};
2016-05-05 14:18:07 +01:00
function mapStateToProps(state) {
return {
recentBuilds: state.recentBuilds,
};
}
export default connect(mapStateToProps, { getProjectRecentBuilds }) (BuildList);