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/projects/ProjectItem.js

131 lines
3.8 KiB
JavaScript
Raw Permalink Normal View History

2016-02-21 12:05:14 +00:00
import React from 'react-native';
2016-02-23 23:12:32 +00:00
import GlobalStyles from '../../settings/styles';
import { getProjectRecentBuilds } from '../../api/CircleCI';
import moment from 'moment';
2016-03-11 11:00:07 +00:00
import Icon from 'react-native-vector-icons/Octicons';
2016-03-11 11:53:55 +00:00
import RouteMaster from '../routes/RouteMaster';
2016-02-21 12:05:14 +00:00
2016-02-23 23:12:32 +00:00
const {
2016-02-21 12:05:14 +00:00
View,
Text,
2016-02-24 22:23:44 +00:00
StyleSheet,
TouchableHighlight
2016-02-21 12:05:14 +00:00
} = React;
2016-02-23 23:12:32 +00:00
const styles = StyleSheet.create({
container: {
flex: 1,
height: 70,
alignItems: 'stretch',
backgroundColor: GlobalStyles.get('CIRCLE_ITEM_BG'),
borderBottomColor: GlobalStyles.get('CIRCLE_ITEM_BORDER'),
2016-02-24 18:00:50 +00:00
borderBottomWidth: 2,
flexDirection: 'row',
2016-02-23 23:12:32 +00:00
},
2016-02-24 22:23:44 +00:00
button: {
marginVertical: 2.5,
},
2016-02-24 18:00:50 +00:00
repoCell: {
2016-02-23 23:12:32 +00:00
paddingHorizontal: 4,
2016-02-24 18:00:50 +00:00
paddingVertical: 3,
2016-02-24 21:59:55 +00:00
flex: 0.84
2016-02-23 23:12:32 +00:00
},
2016-02-24 18:00:50 +00:00
buildCell: {
2016-02-24 21:59:55 +00:00
flex: 0.25,
2016-02-24 22:23:44 +00:00
padding: 4,
2016-02-24 18:10:26 +00:00
borderLeftColor: GlobalStyles.get('CIRCLE_ITEM_BORDER'),
borderLeftWidth: 1
2016-02-24 18:00:50 +00:00
},
colourPanel: {
flex: 0.02
2016-02-23 23:12:32 +00:00
},
repoName: {
2016-02-24 18:00:50 +00:00
fontSize: 15,
2016-02-23 23:12:32 +00:00
fontWeight: '500'
2016-02-24 18:00:50 +00:00
},
details: {
2016-02-24 22:23:44 +00:00
fontSize: 12.5,
fontWeight: '300',
2016-03-11 11:10:00 +00:00
},
detailsRow: {
flex: 1,
flexDirection: 'row'
},
mainDetails: {
marginRight: 10
2016-02-23 23:12:32 +00:00
}
});
2016-02-21 12:05:14 +00:00
export default class ProjectItem extends React.Component {
2016-02-23 23:12:32 +00:00
constructor() {
super();
this.state = {
recentBuild: false
};
this._displayMoreInfo = this._displayMoreInfo.bind(this);
2016-02-24 22:23:44 +00:00
this._viewBuildDetails = this._viewBuildDetails.bind(this);
2016-02-23 23:12:32 +00:00
}
componentDidMount() {
getProjectRecentBuilds(this.props.project.username, this.props.project.reponame).then(function (recentBuild) {
this.setState({ recentBuild: recentBuild[0] });
}.bind(this));
}
2016-02-24 22:23:44 +00:00
_viewBuildDetails() {
2016-03-11 11:53:55 +00:00
const destination = RouteMaster.get('PROJECT_DETAILS');
2016-03-11 20:56:26 +00:00
destination.title = this.props.project.reponame;
2016-03-11 11:53:55 +00:00
destination.props = {
project: this.props.project
};
this.props.nav.push(destination);
2016-02-24 22:23:44 +00:00
}
2016-02-23 23:12:32 +00:00
_displayMoreInfo(mostRecentBuild) {
const mask = mostRecentBuild.build_time_millis <= 60000 ? 'ss[s]' : 'm:ss';
const buildTime = moment.duration(mostRecentBuild.build_time_millis, 'ms').format(mask);
2016-02-24 18:00:50 +00:00
const commit = mostRecentBuild.all_commit_details[0];
2016-02-23 23:12:32 +00:00
return (
2016-02-24 21:59:55 +00:00
<View style={styles.buildCell}>
2016-03-11 11:00:07 +00:00
<Text style={styles.details}><Icon name="pulse" /> #{ mostRecentBuild.build_num }</Text>
2016-03-11 11:10:00 +00:00
<Text style={styles.details}><Icon name="clock" /> { buildTime }</Text>
2016-03-11 11:00:07 +00:00
<Text style={styles.details}><Icon name="git-commit" /> { commit.commit.substring(0, 6) }</Text>
2016-02-24 18:00:50 +00:00
</View>
2016-02-23 23:12:32 +00:00
);
}
2016-02-21 12:05:14 +00:00
render() {
2016-02-23 23:12:32 +00:00
const project = this.props.project;
const mostRecentBuild = this.state.recentBuild;
2016-02-24 21:59:55 +00:00
const master = project.branches[project.default_branch].recent_builds[0];
const statusColour = GlobalStyles.get('CIRCLE_TEST_COLOURS').get(master.outcome.toUpperCase());
2016-02-24 21:59:55 +00:00
const username = this.props.userDetails && this.props.userDetails.login !== project.username ?
2016-03-11 11:10:00 +00:00
(<Text style={[styles.details, styles.mainDetails]}><Icon name="person" /> {project.username}</Text>) : null;
2016-02-24 21:59:55 +00:00
const language = project.language ?
2016-03-11 11:10:00 +00:00
(<Text style={[styles.details, styles.mainDetails]}><Icon name="keyboard" /> {project.language}</Text>) : null;
2016-02-24 21:59:55 +00:00
2016-02-23 23:12:32 +00:00
const buildDetails = mostRecentBuild ? this._displayMoreInfo(mostRecentBuild) : null;
2016-02-21 12:05:14 +00:00
return (
2016-02-24 22:23:44 +00:00
<TouchableHighlight
style={styles.button}
underlayColor={GlobalStyles.get('CIRCLE_BG')}
onPress={this._viewBuildDetails}>
<View style={styles.container}>
<View style={styles.repoCell}>
<Text style={styles.repoName}>{project.reponame}</Text>
2016-03-11 11:10:00 +00:00
<View style={styles.detailsRow}>
{ username }
{ language }
</View>
2016-02-24 22:23:44 +00:00
</View>
{ buildDetails }
<View style={[styles.colourPanel, {backgroundColor: statusColour}]} />
2016-02-23 23:12:32 +00:00
</View>
2016-02-24 22:23:44 +00:00
</TouchableHighlight>
2016-02-21 12:05:14 +00:00
);
}
};