From 4a9a1f2e637c3dee9cb49dff0ef2774833242ab1 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Thu, 14 Sep 2017 21:59:59 -0700 Subject: [PATCH] Added move and star to document menu --- frontend/menus/DocumentMenu.js | 40 +++++++++++++++++++--------- frontend/scenes/Document/Document.js | 11 ++++---- frontend/utils/routeHelpers.js | 24 ++++++++++------- 3 files changed, 47 insertions(+), 28 deletions(-) diff --git a/frontend/menus/DocumentMenu.js b/frontend/menus/DocumentMenu.js index e87ebc00..11ed5775 100644 --- a/frontend/menus/DocumentMenu.js +++ b/frontend/menus/DocumentMenu.js @@ -5,6 +5,7 @@ import { inject, observer } from 'mobx-react'; import Document from 'models/Document'; import UiStore from 'stores/UiStore'; import Icon from 'components/Icon'; +import { documentMoveUrl } from 'utils/routeHelpers'; import { DropdownMenu, DropdownMenuItem } from 'components/DropdownMenu'; @observer class DocumentMenu extends Component { @@ -19,32 +20,45 @@ import { DropdownMenu, DropdownMenuItem } from 'components/DropdownMenu'; this.props.history.push(`${this.props.document.collection.url}/new`); }; - onCreateChild = () => { - this.props.history.push(`${this.props.document.url}/new`); - }; - - onDelete = () => { + handleDelete = () => { const { document } = this.props; this.props.ui.setActiveModal('document-delete', { document }); }; - onExport = () => { + handleMove = () => { + this.props.history.push(documentMoveUrl(this.props.document)); + }; + + handleStar = () => { + this.props.document.star(); + }; + + handleUnstar = () => { + this.props.document.unstar(); + }; + + handleExport = () => { this.props.document.download(); }; render() { const { document, label } = this.props; - const { collection, allowDelete } = document; + const { allowDelete } = document; return ( }> - {collection && - - New document - } - Export + {document.starred + ? + Unstar + + : Star} + + Move + Export {allowDelete && - Delete} + + Delete + } ); } diff --git a/frontend/scenes/Document/Document.js b/frontend/scenes/Document/Document.js index 5ae41caf..55faca6a 100644 --- a/frontend/scenes/Document/Document.js +++ b/frontend/scenes/Document/Document.js @@ -10,7 +10,8 @@ import Flex from 'components/Flex'; import { color, layout } from 'styles/constants'; import { collectionUrl, - updateDocumentUrl, + documentUpdateUrl, + documentMoveUrl, matchDocumentEdit, matchDocumentMove, } from 'utils/routeHelpers'; @@ -78,9 +79,9 @@ type Props = { } @keydown('m') - goToMove(event) { - event.preventDefault(); - if (this.document) this.props.history.push(`${this.document.url}/move`); + goToMove(ev) { + ev.preventDefault(); + if (this.document) this.props.history.push(documentMoveUrl(this.document)); } loadDocument = async props => { @@ -108,7 +109,7 @@ type Props = { // Update url to match the current one this.props.history.replace( - updateDocumentUrl(this.props.match.url, document.url) + documentUpdateUrl(this.props.match.url, document.url) ); } else { // Render 404 with search diff --git a/frontend/utils/routeHelpers.js b/frontend/utils/routeHelpers.js index e501f2a9..9333e7cc 100644 --- a/frontend/utils/routeHelpers.js +++ b/frontend/utils/routeHelpers.js @@ -26,6 +26,20 @@ export function documentEditUrl(doc: Document): string { return `${doc.url}/edit`; } +export function documentMoveUrl(doc: Document): string { + return `${doc.url}/move`; +} + +/** + * Replace full url's document part with the new one in case + * the document slug has been updated + */ +export function documentUpdateUrl(oldUrl: string, newUrl: string): string { + // Update url to match the current one + const urlParts = oldUrl.split('/'); + return [newUrl, urlParts.slice(3)].join('/'); +} + export function newDocumentUrl(collection: Collection): string { return `${collection.url}/new`; } @@ -44,13 +58,3 @@ export const matchDocumentSlug = export const matchDocumentEdit = `/doc/${matchDocumentSlug}/edit`; export const matchDocumentMove = `/doc/${matchDocumentSlug}/move`; - -/** - * Replace full url's document part with the new one in case - * the document slug has been updated - */ -export function updateDocumentUrl(oldUrl: string, newUrl: string): string { - // Update url to match the current one - const urlParts = oldUrl.split('/'); - return [newUrl, urlParts.slice(3)].join('/'); -}