2017-06-16 23:28:51 -06:00
|
|
|
import React, {Component} from 'react';
|
|
|
|
import { StyleSheet, css } from 'aphrodite/no-important';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
import OpenDbc from '../api/opendbc';
|
|
|
|
|
|
|
|
export default class GithubDbcList extends Component {
|
|
|
|
static propTypes = {
|
|
|
|
onDbcLoaded: PropTypes.func.isRequired,
|
2017-06-28 21:28:39 -06:00
|
|
|
repo: PropTypes.string.isRequired,
|
|
|
|
openDbcClient: PropTypes.instanceOf(OpenDbc).isRequired
|
2017-06-16 23:28:51 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props){
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
paths: [],
|
|
|
|
selectedPath: null,
|
|
|
|
};
|
|
|
|
|
|
|
|
this.rowForPath = this.rowForPath.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
|
if(nextProps.repo != this.props.repo) {
|
2017-06-28 21:28:39 -06:00
|
|
|
this.props.openDbcClient.list(nextProps.repo).then((paths) => {
|
2017-06-21 19:11:04 -06:00
|
|
|
this.setState({paths, selectedPath: null})
|
2017-06-16 23:28:51 -06:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillMount() {
|
2017-06-28 21:28:39 -06:00
|
|
|
this.props.openDbcClient.list(this.props.repo).then((paths) => {
|
2017-06-30 23:17:05 -06:00
|
|
|
paths = paths.filter((path) => path.indexOf(".dbc") !== -1);
|
2017-06-16 23:28:51 -06:00
|
|
|
this.setState({paths})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
selectPath(path) {
|
|
|
|
this.setState({selectedPath: path})
|
2017-06-28 21:28:39 -06:00
|
|
|
this.props.openDbcClient.getDbcContents(path, this.props.repo).then((dbcContents) => {
|
2017-06-16 23:28:51 -06:00
|
|
|
this.props.onDbcLoaded(path, dbcContents);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
rowForPath(path) {
|
|
|
|
const textClassName = this.state.selectedPath === path ? css(Styles.selectedPath) : null
|
|
|
|
return (<div
|
|
|
|
key={path}
|
|
|
|
className={css(Styles.row)}
|
|
|
|
onClick={() => {this.selectPath(path)}}>
|
|
|
|
<p className={textClassName}>{path}</p>
|
|
|
|
</div>);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (<div className={css(Styles.root)}>
|
2017-06-21 00:01:41 -06:00
|
|
|
<p className={css(Styles.repoName)}><a href={`https://github.com/${this.props.repo}`}
|
|
|
|
target={"_blank"}
|
|
|
|
className={css(Styles.repoLink)}>{this.props.repo}</a></p>
|
2017-06-16 23:28:51 -06:00
|
|
|
<input className={css(Styles.search)} type="text" />
|
|
|
|
<div className={css(Styles.list)}>
|
|
|
|
{this.state.paths.map(this.rowForPath)}
|
|
|
|
</div>
|
|
|
|
</div>)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const Styles = StyleSheet.create({
|
2017-06-21 00:01:41 -06:00
|
|
|
repoName: {
|
|
|
|
paddingBottom: 10
|
|
|
|
},
|
|
|
|
repoLink: {
|
|
|
|
color: 'inherit',
|
|
|
|
':hover': {textDecoration: 'underline'},
|
|
|
|
':visited': {
|
|
|
|
color: 'inherit'
|
|
|
|
}
|
2017-06-16 23:28:51 -06:00
|
|
|
},
|
|
|
|
row: {
|
|
|
|
width: '100%',
|
|
|
|
borderBottom: '1px solid black',
|
2017-06-20 23:52:57 -06:00
|
|
|
cursor: 'pointer',
|
|
|
|
paddingTop: 10,
|
|
|
|
paddingBottom: 10
|
2017-06-16 23:28:51 -06:00
|
|
|
},
|
|
|
|
selectedPath: {
|
|
|
|
fontWeight: 'bold'
|
|
|
|
}
|
|
|
|
})
|