2017-05-18 02:36:31 +00:00
|
|
|
// @flow
|
|
|
|
import React, { Component } from 'react';
|
2017-05-18 03:31:33 +00:00
|
|
|
import { withRouter } from 'react-router-dom';
|
2017-09-10 05:12:59 +00:00
|
|
|
import { inject, observer } from 'mobx-react';
|
2017-06-29 04:50:54 +00:00
|
|
|
import Document from 'models/Document';
|
2017-09-10 05:12:59 +00:00
|
|
|
import UiStore from 'stores/UiStore';
|
2017-09-04 20:23:20 +00:00
|
|
|
import Icon from 'components/Icon';
|
2017-09-15 04:59:59 +00:00
|
|
|
import { documentMoveUrl } from 'utils/routeHelpers';
|
2017-09-04 20:23:20 +00:00
|
|
|
import { DropdownMenu, DropdownMenuItem } from 'components/DropdownMenu';
|
2017-05-18 02:36:31 +00:00
|
|
|
|
2017-09-10 05:12:59 +00:00
|
|
|
@observer class DocumentMenu extends Component {
|
|
|
|
props: {
|
|
|
|
ui: UiStore,
|
|
|
|
label?: React$Element<any>,
|
|
|
|
history: Object,
|
|
|
|
document: Document,
|
|
|
|
};
|
2017-05-18 02:36:31 +00:00
|
|
|
|
|
|
|
onCreateDocument = () => {
|
2017-07-05 06:02:06 +00:00
|
|
|
this.props.history.push(`${this.props.document.collection.url}/new`);
|
2017-05-18 02:36:31 +00:00
|
|
|
};
|
|
|
|
|
2017-09-15 04:59:59 +00:00
|
|
|
handleDelete = () => {
|
2017-09-10 05:12:59 +00:00
|
|
|
const { document } = this.props;
|
2017-09-10 05:51:22 +00:00
|
|
|
this.props.ui.setActiveModal('document-delete', { document });
|
2017-05-18 02:36:31 +00:00
|
|
|
};
|
|
|
|
|
2017-09-15 04:59:59 +00:00
|
|
|
handleMove = () => {
|
|
|
|
this.props.history.push(documentMoveUrl(this.props.document));
|
|
|
|
};
|
|
|
|
|
|
|
|
handleStar = () => {
|
|
|
|
this.props.document.star();
|
|
|
|
};
|
|
|
|
|
|
|
|
handleUnstar = () => {
|
|
|
|
this.props.document.unstar();
|
|
|
|
};
|
|
|
|
|
|
|
|
handleExport = () => {
|
2017-09-09 23:55:02 +00:00
|
|
|
this.props.document.download();
|
2017-05-18 02:36:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
2017-09-10 05:12:59 +00:00
|
|
|
const { document, label } = this.props;
|
2017-09-15 04:59:59 +00:00
|
|
|
const { allowDelete } = document;
|
2017-09-09 23:55:02 +00:00
|
|
|
|
|
|
|
return (
|
2017-09-10 05:12:59 +00:00
|
|
|
<DropdownMenu label={label || <Icon type="MoreHorizontal" />}>
|
2017-09-15 04:59:59 +00:00
|
|
|
{document.starred
|
|
|
|
? <DropdownMenuItem onClick={this.handleUnstar}>
|
|
|
|
Unstar
|
|
|
|
</DropdownMenuItem>
|
|
|
|
: <DropdownMenuItem onClick={this.handleStar}>Star</DropdownMenuItem>}
|
|
|
|
|
|
|
|
<DropdownMenuItem onClick={this.handleMove}>Move</DropdownMenuItem>
|
|
|
|
<DropdownMenuItem onClick={this.handleExport}>Export</DropdownMenuItem>
|
2017-09-09 23:55:02 +00:00
|
|
|
{allowDelete &&
|
2017-09-15 04:59:59 +00:00
|
|
|
<DropdownMenuItem onClick={this.handleDelete}>
|
|
|
|
Delete
|
|
|
|
</DropdownMenuItem>}
|
2017-09-09 23:55:02 +00:00
|
|
|
</DropdownMenu>
|
|
|
|
);
|
2017-05-18 02:36:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-10 05:12:59 +00:00
|
|
|
export default withRouter(inject('ui')(DocumentMenu));
|