Refactor to routeHelpers
This commit is contained in:
@ -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);
|
||||||
|
@ -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`;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user