From 9027b55930d5e61e5db492ea6c3170e332712f4d Mon Sep 17 00:00:00 2001 From: Jori Lallo Date: Mon, 5 Jun 2017 23:12:47 -0700 Subject: [PATCH] Removed mentions of navigationTree --- frontend/models/Collection.js | 2 +- frontend/scenes/Collection/Collection.js | 2 +- frontend/scenes/Document/DocumentStore.js | 76 ++++++++------------- frontend/scenes/Document/components/Menu.js | 41 ++++++----- frontend/types/index.js | 1 - 5 files changed, 54 insertions(+), 68 deletions(-) diff --git a/frontend/models/Collection.js b/frontend/models/Collection.js index 47c4e9323..4b89f27c3 100644 --- a/frontend/models/Collection.js +++ b/frontend/models/Collection.js @@ -14,7 +14,7 @@ class Collection { id: string; name: string; type: 'atlas' | 'journal'; - navigationTree: NavigationNode; + documents: Array; updatedAt: string; url: string; diff --git a/frontend/scenes/Collection/Collection.js b/frontend/scenes/Collection/Collection.js index 72f2f039b..96210a58c 100644 --- a/frontend/scenes/Collection/Collection.js +++ b/frontend/scenes/Collection/Collection.js @@ -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(() => { diff --git a/frontend/scenes/Document/DocumentStore.js b/frontend/scenes/Document/DocumentStore.js index 9a5aa2da2..e4d3dbe36 100644 --- a/frontend/scenes/Document/DocumentStore.js +++ b/frontend/scenes/Document/DocumentStore.js @@ -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 { 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; }; diff --git a/frontend/scenes/Document/components/Menu.js b/frontend/scenes/Document/components/Menu.js index 38e493d8c..6d050aa49 100644 --- a/frontend/scenes/Document/components/Menu.js +++ b/frontend/scenes/Document/components/Menu.js @@ -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 ( - }> - {collection && -
- - New document - - New child -
} - Export - {allowDelete && Delete} -
- ); + return ( + }> + {collection && +
+ + New document + + New child +
} + Export + {allowDelete && Delete} +
+ ); + } else { + return
; + } } } diff --git a/frontend/types/index.js b/frontend/types/index.js index 9b0ed127e..1e2d2d0e1 100644 --- a/frontend/types/index.js +++ b/frontend/types/index.js @@ -15,7 +15,6 @@ export type NavigationNode = { id: string, title: string, url: string, - collapsed: boolean, children: Array, };