2019-10-19 03:57:58 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2023-09-04 01:50:14 +00:00
|
|
|
import { Utils } from '../../../utils/utils';
|
2019-10-19 03:57:58 +00:00
|
|
|
import { siteRoot, gettext } from '../../../utils/constants';
|
|
|
|
|
2021-12-15 03:40:11 +00:00
|
|
|
const { enableSysAdminViewRepo } = window.sysadmin.pageOptions;
|
|
|
|
|
2019-10-19 03:57:58 +00:00
|
|
|
const RepoItemPropTypes = {
|
|
|
|
repo: PropTypes.object.isRequired,
|
2023-05-15 02:57:46 +00:00
|
|
|
showDeleteRepoDialog: PropTypes.func.isRequired
|
2019-10-19 03:57:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class RepoItem extends React.Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
2023-05-15 02:57:46 +00:00
|
|
|
highlight: false
|
2019-10-19 03:57:58 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
onMouseEnter = () => {
|
|
|
|
this.setState({ highlight: true });
|
|
|
|
}
|
|
|
|
|
|
|
|
onMouseLeave = () => {
|
|
|
|
this.setState({ highlight: false });
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2023-05-15 02:57:46 +00:00
|
|
|
const { repo } = this.props;
|
|
|
|
const repoName = repo.name || repo.repo_name;
|
2019-10-19 03:57:58 +00:00
|
|
|
const highlight = this.state.highlight;
|
|
|
|
let iconUrl = Utils.getLibIconUrl(repo);
|
|
|
|
return (
|
|
|
|
<tr className={highlight ? 'tr-highlight' : ''} onMouseEnter={this.onMouseEnter} onMouseLeave={this.onMouseLeave}>
|
|
|
|
<td><img src={iconUrl} width="24" alt={gettext('icon')}/></td>
|
2021-12-15 03:40:11 +00:00
|
|
|
{ enableSysAdminViewRepo ?
|
2023-05-15 02:57:46 +00:00
|
|
|
<td><a href={`${siteRoot}sys/libraries/${repo.repo_id}/${encodeURIComponent(repoName)}/`}>{repoName}</a></td>
|
2021-12-15 03:40:11 +00:00
|
|
|
:
|
2023-05-15 02:57:46 +00:00
|
|
|
<td>{repoName}</td>
|
2021-12-15 03:40:11 +00:00
|
|
|
}
|
2023-05-15 02:57:46 +00:00
|
|
|
<td>{Utils.bytesToSize(repo.size)}</td>
|
|
|
|
<td className="cursor-pointer text-center" onClick={this.props.showDeleteRepoDialog.bind(this, repo)}>
|
|
|
|
<span className={`sf2-icon-delete action-icon ${highlight ? '' : 'vh'}`} title="Delete"></span>
|
|
|
|
</td>
|
2019-10-19 03:57:58 +00:00
|
|
|
</tr>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RepoItem.propTypes = RepoItemPropTypes;
|
|
|
|
|
2019-12-05 07:45:16 +00:00
|
|
|
export default RepoItem;
|