2021-09-13 10:37:07 +08:00
|
|
|
import React, { Fragment } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2021-10-12 11:41:26 +08:00
|
|
|
import { gettext } from '../../../utils/constants';
|
|
|
|
import OpIcon from '../../op-icon';
|
2021-09-13 10:37:07 +08:00
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
permission: PropTypes.object.isRequired,
|
|
|
|
onEditCustomPermission: PropTypes.func.isRequired,
|
|
|
|
onDeleteCustomPermission: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
class CustomPermissionItem extends React.Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
isShowOperations: false
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
onMouseEnter = () => {
|
|
|
|
this.setState({isShowOperations: true});
|
|
|
|
}
|
2021-10-12 11:41:26 +08:00
|
|
|
|
2021-09-13 10:37:07 +08:00
|
|
|
onMouseOver = () => {
|
|
|
|
this.setState({isShowOperations: true});
|
|
|
|
}
|
2021-10-12 11:41:26 +08:00
|
|
|
|
2021-09-13 10:37:07 +08:00
|
|
|
onMouseLeave = () => {
|
|
|
|
this.setState({isShowOperations: false});
|
|
|
|
}
|
|
|
|
|
|
|
|
onEditCustomPermission = () => {
|
|
|
|
const { permission } = this.props;
|
2021-10-12 11:41:26 +08:00
|
|
|
this.props.onEditCustomPermission(permission);
|
2021-09-13 10:37:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
onDeleteCustomPermission = () => {
|
|
|
|
const { permission } = this.props;
|
2021-10-12 11:41:26 +08:00
|
|
|
this.props.onDeleteCustomPermission(permission);
|
2021-09-13 10:37:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { permission } = this.props;
|
|
|
|
const { id, name, description } = permission;
|
|
|
|
return (
|
2021-10-12 11:41:26 +08:00
|
|
|
<tr key={id} onMouseEnter={this.onMouseEnter} onMouseLeave={this.onMouseLeave} onMouseOver={this.onMouseOver} tabIndex="0" onFocus={this.onMouseEnter}>
|
2021-09-13 10:37:07 +08:00
|
|
|
<td width='22%' className="text-truncate" title={name}>{name}</td>
|
|
|
|
<td width='56%' className="text-truncate">{description}</td>
|
|
|
|
<td width='22%'>
|
|
|
|
{this.state.isShowOperations && (
|
|
|
|
<Fragment>
|
2021-10-12 11:41:26 +08:00
|
|
|
<OpIcon
|
|
|
|
className="fa fa-pencil-alt attr-action-icon"
|
|
|
|
title={gettext('Edit')}
|
|
|
|
op={this.onEditCustomPermission}
|
|
|
|
/>
|
|
|
|
<OpIcon
|
|
|
|
className="fa fa-trash attr-action-icon"
|
|
|
|
title={gettext('Delete')}
|
|
|
|
op={this.onDeleteCustomPermission}
|
|
|
|
/>
|
2021-09-13 10:37:07 +08:00
|
|
|
</Fragment>
|
|
|
|
)}
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CustomPermissionItem.propTypes = propTypes;
|
|
|
|
|
|
|
|
export default CustomPermissionItem;
|