Refactor to routeHelpers

This commit is contained in:
Tom Moor
2017-09-28 20:36:29 -07:00
parent bb9686b112
commit 26a3f2c7e3
2 changed files with 12 additions and 7 deletions

View File

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

View File

@ -22,6 +22,14 @@ export function documentUrl(doc: Document): string {
return doc.url; 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 { export function documentEditUrl(doc: Document): string {
return `${doc.url}/edit`; return `${doc.url}/edit`;
} }