import React, { Fragment } from 'react'; import PropTypes from 'prop-types'; import moment from 'moment'; import { gettext } from '../../utils/constants'; import { Utils } from '../../utils/utils'; import EditFileTagDialog from '../dialog/edit-filetag-dialog'; const propTypes = { repoInfo: PropTypes.object.isRequired, repoID: PropTypes.string.isRequired, dirent: PropTypes.object.isRequired, direntType: PropTypes.string.isRequired, direntDetail: PropTypes.object.isRequired, path: PropTypes.string.isRequired, fileTagList: PropTypes.array.isRequired, onFileTagChanged: PropTypes.func.isRequired, }; class DetailListView extends React.Component { constructor(props) { super(props); this.state = { isEditFileTagShow: false, }; } getDirentPostion = () => { let { repoInfo } = this.props; let direntPath = this.getDirentPath(); let position = repoInfo.repo_name; if (direntPath !== '/') { let index = direntPath.lastIndexOf('/'); let path = direntPath.slice(0, index); position = position + path; } return position; } onEditFileTagToggle = () => { this.setState({ isEditFileTagShow: !this.state.isEditFileTagShow }); } onFileTagChanged = () => { let direntPath = this.getDirentPath(); this.props.onFileTagChanged(this.props.dirent, direntPath); } getDirentPath = () => { let { dirent, path } = this.props; return Utils.joinPath(path, dirent.name); } render() { let { direntType, direntDetail, fileTagList } = this.props; let position = this.getDirentPostion(); let direntPath = this.getDirentPath(); if (direntType === 'dir') { return (
{gettext('Folder')}{direntDetail.dir_count}
{gettext('File')}{direntDetail.file_count}
{gettext('Size')}{Utils.bytesToSize(direntDetail.size)}
{gettext('Position')}{position}
{gettext('Last Update')}{moment(direntDetail.mtime).format('YYYY-MM-DD')}
); } else { return (
{gettext('Size')}{direntDetail.size}
{gettext('Position')}{position}
{gettext('Last Update')}{moment(direntDetail.last_modified).fromNow()}
{gettext('Tags')}
    {fileTagList.map((fileTag) => { return (
  • {fileTag.name}
  • ); })}
{ this.state.isEditFileTagShow && }
); } } } DetailListView.propTypes = propTypes; export default DetailListView;