Removed mentions of navigationTree

This commit is contained in:
Jori Lallo
2017-06-05 23:12:47 -07:00
parent 3528b2d0ef
commit 9027b55930
5 changed files with 54 additions and 68 deletions

View File

@@ -14,7 +14,7 @@ class Collection {
id: string;
name: string;
type: 'atlas' | 'journal';
navigationTree: NavigationNode;
documents: Array<NavigationNode>;
updatedAt: string;
url: string;

View File

@@ -40,7 +40,7 @@ type State = {
throw new Error('TODO code up non-atlas collections');
this.setState({
redirectUrl: collection.navigationTree.url,
redirectUrl: collection.documents[0].url,
});
})
.catch(() => {

View File

@@ -1,5 +1,5 @@
// @flow
import { observable, action, computed, toJS } from 'mobx';
import { observable, action, computed } from 'mobx';
import get from 'lodash/get';
import invariant from 'invariant';
import { client } from 'utils/ApiClient';
@@ -49,42 +49,22 @@ class DocumentStore {
return !!this.document && this.document.collection.type === 'atlas';
}
@computed get collectionTree(): ?Object {
if (
this.document &&
this.document.collection &&
this.document.collection.type === 'atlas'
) {
const tree = this.document.collection.navigationTree;
const collapseNodes = node => {
node.collapsed = this.collapsedNodes.includes(node.id);
node.children = node.children.map(childNode => {
return collapseNodes(childNode);
});
return node;
};
return collapseNodes(toJS(tree));
}
}
@computed get pathToDocument(): Array<NavigationNode> {
let path;
const traveler = (node, previousPath) => {
if (this.document && node.id === this.document.id) {
path = previousPath;
return;
} else {
node.children.forEach(childNode => {
const newPath = [...previousPath, node];
const traveler = (nodes, previousPath) => {
nodes.forEach(childNode => {
const newPath = [...previousPath, childNode];
if (childNode.id === this.document.id) {
path = previousPath;
return;
} else {
return traveler(childNode, newPath);
});
}
}
});
};
if (this.document && this.collectionTree) {
traveler(this.collectionTree, []);
if (this.document && this.document.collection.documents) {
traveler(this.document.collection.documents, []);
invariant(path, 'Path is not available for collection, abort');
return path.splice(1);
}
@@ -97,23 +77,23 @@ class DocumentStore {
@action fetchDocument = async () => {
this.isFetching = true;
try {
const res = await client.get(
'/documents.info',
{
id: this.documentId,
},
{ cache: true }
);
invariant(res && res.data, 'Data should be available');
if (this.newChildDocument) {
this.parentDocument = res.data;
} else {
this.document = res.data;
}
} catch (e) {
console.error('Something went wrong');
// try {
const res = await client.get(
'/documents.info',
{
id: this.documentId,
},
{ cache: true }
);
invariant(res && res.data, 'Data should be available');
if (this.newChildDocument) {
this.parentDocument = res.data;
} else {
this.document = res.data;
}
// } catch (e) {
// console.error('Something went wrong');
// }
this.isFetching = false;
};

View File

@@ -55,24 +55,31 @@ type Props = {
render() {
const document = get(this.props, 'document');
const collection = get(document, 'collection.type') === 'atlas';
const allowDelete =
collection &&
document.id !== get(document, 'collection.navigationTree.id');
if (document) {
const collection = document.collection;
debugger;
const allowDelete =
collection &&
collection.type === 'atlas' &&
collection.documents &&
collection.documents.length > 1;
return (
<DropdownMenu label={<MoreIcon />}>
{collection &&
<div>
<MenuItem onClick={this.onCreateDocument}>
New document
</MenuItem>
<MenuItem onClick={this.onCreateChild}>New child</MenuItem>
</div>}
<MenuItem onClick={this.onExport}>Export</MenuItem>
{allowDelete && <MenuItem onClick={this.onDelete}>Delete</MenuItem>}
</DropdownMenu>
);
return (
<DropdownMenu label={<MoreIcon />}>
{collection &&
<div>
<MenuItem onClick={this.onCreateDocument}>
New document
</MenuItem>
<MenuItem onClick={this.onCreateChild}>New child</MenuItem>
</div>}
<MenuItem onClick={this.onExport}>Export</MenuItem>
{allowDelete && <MenuItem onClick={this.onDelete}>Delete</MenuItem>}
</DropdownMenu>
);
} else {
return <div />;
}
}
}

View File

@@ -15,7 +15,6 @@ export type NavigationNode = {
id: string,
title: string,
url: string,
collapsed: boolean,
children: Array<NavigationNode>,
};