import React from 'react'; import PropTypes from 'prop-types'; import DirentListView from './dirent-list-view'; const propTypes = { isShowFile: PropTypes.bool, selectedPath: PropTypes.string, selectedRepo: PropTypes.object, repo: PropTypes.object.isRequired, initToShowChildren: PropTypes.bool.isRequired, onDirentItemClick: PropTypes.func.isRequired, onRepoItemClick: PropTypes.func.isRequired, }; class RepoListItem extends React.Component { constructor(props) { super(props); this.state = { isShowChildren: this.props.initToShowChildren, }; } onToggleClick = () => { this.setState({isShowChildren: !this.state.isShowChildren}); } onDirentItemClick = (filePath, dirent) => { let repo = this.props.repo; this.props.onDirentItemClick(repo, filePath, dirent); } onRepoItemClick = () => { if (!this.isCurrentRepo()) { this.props.onRepoItemClick(this.props.repo); } else { this.onToggleClick(); } } isCurrentRepo = () => { let { selectedRepo, repo } = this.props; return selectedRepo && (repo.repo_id === selectedRepo.repo_id); } render() { let repoActive = false; let isCurrentRepo = this.isCurrentRepo(); if (isCurrentRepo && !this.props.selectedPath) { repoActive = true; } return (