Refactor to routeHelpers

This commit is contained in:
Tom Moor committed 2017-09-28 21:57:27 -07:00
1 parent bb9686b112
commit 26a3f2c7e3
2 files changed
+12 -7

No files matched your search

+4 -7
View File
@@ -12,6 +12,8 @@ import {
collectionUrl,
updateDocumentUrl,
documentMoveUrl,
documentEditUrl,
documentNewUrl,
matchDocumentEdit,
matchDocumentMove,
} from 'utils/routeHelpers';
@@ -57,7 +59,6 @@ type Props = {
@observable isSaving = false;
@observable showAsSaved = false;
@observable notFound = false;
@observable moveModalOpen: boolean = false;
componentWillMount() {
@@ -144,16 +145,12 @@ type Props = {
onClickEdit = () => {
if (!this.document) return;
const url = `${this.document.url}/edit`;
this.props.history.push(url);
this.props.history.push(documentEditUrl(this.document));
};
onClickNew = () => {
if (!this.document) return;
let newUrl = `${this.document.collection.url}/new`;
if (this.document.parentDocumentId)
newUrl = `${newUrl}?parentDocument=${this.document.parentDocumentId}`;
this.props.history.push(newUrl);
this.props.history.push(documentNewUrl(this.document));
};
handleCloseMoveModal = () => (this.moveModalOpen = false);
+8
View File
@@ -22,6 +22,14 @@ export function documentUrl(doc: Document): string {
return doc.url;
}
export function documentNewUrl(doc: Document): string {
const newUrl = `${doc.collection.url}/new`;
if (doc.parentDocumentId) {
return `${newUrl}?parentDocument=${doc.parentDocumentId}`;
}
return newUrl;
}
export function documentEditUrl(doc: Document): string {
return `${doc.url}/edit`;
}