2019-11-05 07:35:41 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { Dropdown, DropdownMenu, DropdownToggle, DropdownItem } from 'reactstrap';
|
2019-11-18 02:30:35 +00:00
|
|
|
import { gettext } from '../../utils/constants';
|
|
|
|
import { Utils } from '../../utils/utils';
|
2019-11-05 07:35:41 +00:00
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
onFreezedItem: PropTypes.func.isRequired,
|
|
|
|
onUnfreezedItem: PropTypes.func.isRequired,
|
|
|
|
onMenuItemClick: PropTypes.func.isRequired,
|
2019-11-18 02:30:35 +00:00
|
|
|
operations: PropTypes.array.isRequired,
|
|
|
|
translateOperations: PropTypes.func.isRequired
|
2019-11-05 07:35:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class OpMenu extends React.Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
isItemMenuShow: false
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
onMenuItemClick = (e) => {
|
|
|
|
let operation = Utils.getEventData(e, 'op');
|
|
|
|
this.props.onMenuItemClick(operation);
|
|
|
|
}
|
|
|
|
|
|
|
|
onDropdownToggleClick = (e) => {
|
|
|
|
this.toggleOperationMenu(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleOperationMenu = (e) => {
|
|
|
|
this.setState(
|
|
|
|
{isItemMenuShow: !this.state.isItemMenuShow},
|
|
|
|
() => {
|
|
|
|
if (this.state.isItemMenuShow) {
|
|
|
|
this.props.onFreezedItem();
|
|
|
|
} else {
|
|
|
|
this.props.onUnfreezedItem();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { operations, translateOperations } = this.props;
|
|
|
|
return (
|
|
|
|
<Dropdown isOpen={this.state.isItemMenuShow} toggle={this.toggleOperationMenu}>
|
2020-11-02 05:56:35 +00:00
|
|
|
<DropdownToggle
|
2019-11-05 07:35:41 +00:00
|
|
|
tag="i"
|
2019-11-18 02:30:35 +00:00
|
|
|
className="d-flex w-5 h-5 align-items-center justify-content-center sf-dropdown-toggle fa fa-ellipsis-v"
|
2019-11-05 07:35:41 +00:00
|
|
|
title={gettext('More Operations')}
|
2020-11-02 05:56:35 +00:00
|
|
|
data-toggle="dropdown"
|
2019-11-05 07:35:41 +00:00
|
|
|
aria-expanded={this.state.isItemMenuShow}
|
|
|
|
/>
|
2019-11-18 02:30:35 +00:00
|
|
|
<DropdownMenu className="my-1 mr-2">
|
2019-11-05 07:35:41 +00:00
|
|
|
{operations.map((item, index )=> {
|
|
|
|
return (<DropdownItem key={index} data-op={item} onClick={this.onMenuItemClick}>{translateOperations(item)}</DropdownItem>);
|
|
|
|
})}
|
|
|
|
</DropdownMenu>
|
|
|
|
</Dropdown>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OpMenu.propTypes = propTypes;
|
|
|
|
|
|
|
|
export default OpMenu;
|