Added ways to define the save location of the document
This commit is contained in:
@ -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 (
|
||||
<DropdownMenu label={label || <Icon type="MoreHorizontal" />}>
|
||||
{collection &&
|
||||
<DropdownMenuItem onClick={this.onNewDocument}>
|
||||
New document
|
||||
</DropdownMenuItem>}
|
||||
{collection &&
|
||||
<DropdownMenuItem onClick={this.onEdit}>Edit</DropdownMenuItem>}
|
||||
{allowDelete &&
|
||||
|
@ -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', () => {
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user