Merge pull request #259 from jorilallo/issue-241
Added move and star to document menu
This commit is contained in:
@ -5,6 +5,7 @@ import { inject, observer } from 'mobx-react';
|
|||||||
import Document from 'models/Document';
|
import Document from 'models/Document';
|
||||||
import UiStore from 'stores/UiStore';
|
import UiStore from 'stores/UiStore';
|
||||||
import Icon from 'components/Icon';
|
import Icon from 'components/Icon';
|
||||||
|
import { documentMoveUrl } from 'utils/routeHelpers';
|
||||||
import { DropdownMenu, DropdownMenuItem } from 'components/DropdownMenu';
|
import { DropdownMenu, DropdownMenuItem } from 'components/DropdownMenu';
|
||||||
|
|
||||||
@observer class DocumentMenu extends Component {
|
@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`);
|
this.props.history.push(`${this.props.document.collection.url}/new`);
|
||||||
};
|
};
|
||||||
|
|
||||||
onCreateChild = () => {
|
handleDelete = () => {
|
||||||
this.props.history.push(`${this.props.document.url}/new`);
|
|
||||||
};
|
|
||||||
|
|
||||||
onDelete = () => {
|
|
||||||
const { document } = this.props;
|
const { document } = this.props;
|
||||||
this.props.ui.setActiveModal('document-delete', { document });
|
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();
|
this.props.document.download();
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { document, label } = this.props;
|
const { document, label } = this.props;
|
||||||
const { collection, allowDelete } = document;
|
const { allowDelete } = document;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DropdownMenu label={label || <Icon type="MoreHorizontal" />}>
|
<DropdownMenu label={label || <Icon type="MoreHorizontal" />}>
|
||||||
{collection &&
|
{document.starred
|
||||||
<DropdownMenuItem onClick={this.onCreateDocument}>
|
? <DropdownMenuItem onClick={this.handleUnstar}>
|
||||||
New document
|
Unstar
|
||||||
</DropdownMenuItem>}
|
</DropdownMenuItem>
|
||||||
<DropdownMenuItem onClick={this.onExport}>Export</DropdownMenuItem>
|
: <DropdownMenuItem onClick={this.handleStar}>Star</DropdownMenuItem>}
|
||||||
|
|
||||||
|
<DropdownMenuItem onClick={this.handleMove}>Move</DropdownMenuItem>
|
||||||
|
<DropdownMenuItem onClick={this.handleExport}>Export</DropdownMenuItem>
|
||||||
{allowDelete &&
|
{allowDelete &&
|
||||||
<DropdownMenuItem onClick={this.onDelete}>Delete</DropdownMenuItem>}
|
<DropdownMenuItem onClick={this.handleDelete}>
|
||||||
|
Delete
|
||||||
|
</DropdownMenuItem>}
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,8 @@ import Flex from 'components/Flex';
|
|||||||
import { color, layout } from 'styles/constants';
|
import { color, layout } from 'styles/constants';
|
||||||
import {
|
import {
|
||||||
collectionUrl,
|
collectionUrl,
|
||||||
updateDocumentUrl,
|
documentUpdateUrl,
|
||||||
|
documentMoveUrl,
|
||||||
matchDocumentEdit,
|
matchDocumentEdit,
|
||||||
matchDocumentMove,
|
matchDocumentMove,
|
||||||
} from 'utils/routeHelpers';
|
} from 'utils/routeHelpers';
|
||||||
@ -78,9 +79,9 @@ type Props = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@keydown('m')
|
@keydown('m')
|
||||||
goToMove(event) {
|
goToMove(ev) {
|
||||||
event.preventDefault();
|
ev.preventDefault();
|
||||||
if (this.document) this.props.history.push(`${this.document.url}/move`);
|
if (this.document) this.props.history.push(documentMoveUrl(this.document));
|
||||||
}
|
}
|
||||||
|
|
||||||
loadDocument = async props => {
|
loadDocument = async props => {
|
||||||
@ -108,7 +109,7 @@ type Props = {
|
|||||||
|
|
||||||
// Update url to match the current one
|
// Update url to match the current one
|
||||||
this.props.history.replace(
|
this.props.history.replace(
|
||||||
updateDocumentUrl(this.props.match.url, document.url)
|
documentUpdateUrl(this.props.match.url, document.url)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// Render 404 with search
|
// Render 404 with search
|
||||||
|
@ -26,6 +26,20 @@ export function documentEditUrl(doc: Document): string {
|
|||||||
return `${doc.url}/edit`;
|
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 {
|
export function newDocumentUrl(collection: Collection): string {
|
||||||
return `${collection.url}/new`;
|
return `${collection.url}/new`;
|
||||||
}
|
}
|
||||||
@ -44,13 +58,3 @@ export const matchDocumentSlug =
|
|||||||
|
|
||||||
export const matchDocumentEdit = `/doc/${matchDocumentSlug}/edit`;
|
export const matchDocumentEdit = `/doc/${matchDocumentSlug}/edit`;
|
||||||
export const matchDocumentMove = `/doc/${matchDocumentSlug}/move`;
|
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('/');
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user