diff --git a/frontend/menus/CollectionMenu.js b/frontend/menus/CollectionMenu.js
index 9fdff8ac3..ccaab464d 100644
--- a/frontend/menus/CollectionMenu.js
+++ b/frontend/menus/CollectionMenu.js
@@ -15,6 +15,11 @@ import { DropdownMenu, DropdownMenuItem } from 'components/DropdownMenu';
collection: Collection,
};
+ onNewDocument = () => {
+ const { collection, history } = this.props;
+ history.push(`${collection.url}/new`);
+ };
+
onEdit = () => {
const { collection } = this.props;
this.props.ui.setActiveModal('collection-edit', { collection });
@@ -31,6 +36,10 @@ import { DropdownMenu, DropdownMenuItem } from 'components/DropdownMenu';
return (
}>
+ {collection &&
+
+ New document
+ }
{collection &&
Edit}
{allowDelete &&
diff --git a/frontend/models/Document.js b/frontend/models/Document.js
index 95504f48b..e13df65f6 100644
--- a/frontend/models/Document.js
+++ b/frontend/models/Document.js
@@ -33,7 +33,7 @@ class Document extends BaseModel {
starred: boolean = false;
text: string = '';
title: string = '';
- parentDocument: ?Document;
+ parentDocument: ?string;
updatedAt: string;
updatedBy: User;
url: string;
@@ -95,6 +95,12 @@ class Document extends BaseModel {
);
}
+ @computed get parentDocumentId(): ?string {
+ return this.pathToDocument.length > 1
+ ? this.pathToDocument[this.pathToDocument.length - 1].id
+ : null;
+ }
+
/* Actions */
@action star = async () => {
@@ -166,9 +172,10 @@ class Document extends BaseModel {
title: this.title,
text: this.text,
};
- // if (this.parentDocument) {
- // data.parentDocument = this.parentDocument.id;
- // }
+ if (this.parentDocument) {
+ data.parentDocument = this.parentDocument;
+ }
+ debugger;
res = await client.post('/documents.create', data);
}
runInAction('Document#save', () => {
diff --git a/frontend/scenes/Document/Document.js b/frontend/scenes/Document/Document.js
index 4a2a077f4..0900761ce 100644
--- a/frontend/scenes/Document/Document.js
+++ b/frontend/scenes/Document/Document.js
@@ -39,6 +39,7 @@ Are you sure you want to discard them?
type Props = {
match: Object,
history: Object,
+ location: Object,
keydown: Object,
documents: DocumentsStore,
newDocument?: boolean,
@@ -88,6 +89,9 @@ type Props = {
if (props.newDocument) {
const newDocument = new Document({
collection: { id: props.match.params.id },
+ parentDocument: new URLSearchParams(props.location.search).get(
+ 'parentDocument'
+ ),
title: '',
text: '',
});
@@ -139,7 +143,10 @@ type Props = {
onClickNew = () => {
if (!this.document) return;
- this.props.history.push(`${this.document.collection.url}/new`);
+ let newUrl = `${this.document.collection.url}/new`;
+ if (this.document.parentDocumentId)
+ newUrl = `${newUrl}?parentDocument=${this.document.parentDocumentId}`;
+ this.props.history.push(newUrl);
};
handleCloseMoveModal = () => (this.moveModalOpen = false);