// @flow import * as React from 'react'; import { Redirect } from 'react-router-dom'; import { observable } from 'mobx'; import { inject, observer } from 'mobx-react'; import { MoreIcon } from 'outline-icons'; import Document from 'models/Document'; import UiStore from 'stores/UiStore'; import AuthStore from 'stores/AuthStore'; import { documentMoveUrl, documentHistoryUrl } from 'utils/routeHelpers'; import { DropdownMenu, DropdownMenuItem } from 'components/DropdownMenu'; type Props = { ui: UiStore, auth: AuthStore, label?: React.Node, document: Document, className: string, showPrint?: boolean, showToggleEmbeds?: boolean, }; @observer class DocumentMenu extends React.Component { @observable redirectTo: ?string; componentDidUpdate() { this.redirectTo = undefined; } handleNewChild = (ev: SyntheticEvent<*>) => { const { document } = this.props; this.redirectTo = `${document.collection.url}/new?parentDocument=${ document.id }`; }; handleDelete = (ev: SyntheticEvent<*>) => { const { document } = this.props; this.props.ui.setActiveModal('document-delete', { document }); }; handleDocumentHistory = () => { this.redirectTo = documentHistoryUrl(this.props.document); }; handleMove = (ev: SyntheticEvent<*>) => { this.redirectTo = documentMoveUrl(this.props.document); }; handleDuplicate = async (ev: SyntheticEvent<*>) => { const duped = await this.props.document.duplicate(); this.redirectTo = duped.url; }; handlePin = (ev: SyntheticEvent<*>) => { this.props.document.pin(); }; handleUnpin = (ev: SyntheticEvent<*>) => { this.props.document.unpin(); }; handleStar = (ev: SyntheticEvent<*>) => { this.props.document.star(); }; handleUnstar = (ev: SyntheticEvent<*>) => { this.props.document.unstar(); }; handleExport = (ev: SyntheticEvent<*>) => { this.props.document.download(); }; handleShareLink = async (ev: SyntheticEvent<*>) => { const { document } = this.props; if (!document.shareUrl) await document.share(); this.props.ui.setActiveModal('document-share', { document }); }; render() { if (this.redirectTo) return ; const { document, label, className, showPrint, auth } = this.props; const canShareDocuments = auth.team && auth.team.sharing; return ( } className={className}> {!document.isDraft && ( {document.pinned ? ( Unpin ) : ( Pin )} {document.starred ? ( Unstar ) : ( Star )} {canShareDocuments && ( Share link… )}
Document history New child document Duplicate Move…
)} Delete…
Download {showPrint && ( Print )}
); } } export default inject('ui', 'auth')(DocumentMenu);