Added predictive document title
This commit is contained in:
@@ -25,6 +25,7 @@ type Options = {
|
||||
type DocumentPathItem = {
|
||||
id: string,
|
||||
title: string,
|
||||
url: string,
|
||||
type: 'document' | 'collection',
|
||||
};
|
||||
|
||||
@@ -59,16 +60,16 @@ class CollectionsStore {
|
||||
let results = [];
|
||||
const travelDocuments = (documentList, path) =>
|
||||
documentList.forEach(document => {
|
||||
const { id, title } = document;
|
||||
const node = { id, title, type: 'document' };
|
||||
const { id, title, url } = document;
|
||||
const node = { id, title, url, type: 'document' };
|
||||
results.push(_.concat(path, node));
|
||||
travelDocuments(document.children, _.concat(path, [node]));
|
||||
});
|
||||
|
||||
if (this.isLoaded) {
|
||||
this.data.forEach(collection => {
|
||||
const { id, name } = collection;
|
||||
const node = { id, title: name, type: 'collection' };
|
||||
const { id, name, url } = collection;
|
||||
const node = { id, title: name, url, type: 'collection' };
|
||||
results.push([node]);
|
||||
travelDocuments(collection.documents, [node]);
|
||||
});
|
||||
@@ -87,6 +88,11 @@ class CollectionsStore {
|
||||
return this.pathsToDocuments.find(path => path.id === documentId);
|
||||
}
|
||||
|
||||
titleForDocument(documentUrl: string): ?string {
|
||||
const path = this.pathsToDocuments.find(path => path.url === documentUrl);
|
||||
if (path) return path.title;
|
||||
}
|
||||
|
||||
/* Actions */
|
||||
|
||||
@action fetchAll = async (): Promise<*> => {
|
||||
|
||||
Reference in New Issue
Block a user