Added predictive document title
This commit is contained in:
@@ -22,6 +22,7 @@ import Document from 'models/Document';
|
|||||||
import DocumentMove from './components/DocumentMove';
|
import DocumentMove from './components/DocumentMove';
|
||||||
import UiStore from 'stores/UiStore';
|
import UiStore from 'stores/UiStore';
|
||||||
import DocumentsStore from 'stores/DocumentsStore';
|
import DocumentsStore from 'stores/DocumentsStore';
|
||||||
|
import CollectionsStore from 'stores/CollectionsStore';
|
||||||
import DocumentMenu from 'menus/DocumentMenu';
|
import DocumentMenu from 'menus/DocumentMenu';
|
||||||
import SaveAction from './components/SaveAction';
|
import SaveAction from './components/SaveAction';
|
||||||
import LoadingPlaceholder from 'components/LoadingPlaceholder';
|
import LoadingPlaceholder from 'components/LoadingPlaceholder';
|
||||||
@@ -45,6 +46,7 @@ type Props = {
|
|||||||
location: Object,
|
location: Object,
|
||||||
keydown: Object,
|
keydown: Object,
|
||||||
documents: DocumentsStore,
|
documents: DocumentsStore,
|
||||||
|
collections: CollectionsStore,
|
||||||
newDocument?: boolean,
|
newDocument?: boolean,
|
||||||
ui: UiStore,
|
ui: UiStore,
|
||||||
};
|
};
|
||||||
@@ -213,7 +215,9 @@ type Props = {
|
|||||||
const isMoving = this.props.match.path === matchDocumentMove;
|
const isMoving = this.props.match.path === matchDocumentMove;
|
||||||
const document = this.document;
|
const document = this.document;
|
||||||
const isFetching = !document;
|
const isFetching = !document;
|
||||||
const titleText = get(document, 'title', '');
|
const titleText =
|
||||||
|
get(document, 'title', '') ||
|
||||||
|
this.props.collections.titleForDocument(this.props.location.pathname);
|
||||||
|
|
||||||
if (this.notFound) {
|
if (this.notFound) {
|
||||||
return this.renderNotFound();
|
return this.renderNotFound();
|
||||||
@@ -362,4 +366,6 @@ const StyledDropToImport = styled(DropToImport)`
|
|||||||
flex: 1;
|
flex: 1;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export default withRouter(inject('ui', 'user', 'documents')(DocumentScene));
|
export default withRouter(
|
||||||
|
inject('ui', 'user', 'documents', 'collections')(DocumentScene)
|
||||||
|
);
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ type Options = {
|
|||||||
type DocumentPathItem = {
|
type DocumentPathItem = {
|
||||||
id: string,
|
id: string,
|
||||||
title: string,
|
title: string,
|
||||||
|
url: string,
|
||||||
type: 'document' | 'collection',
|
type: 'document' | 'collection',
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -59,16 +60,16 @@ class CollectionsStore {
|
|||||||
let results = [];
|
let results = [];
|
||||||
const travelDocuments = (documentList, path) =>
|
const travelDocuments = (documentList, path) =>
|
||||||
documentList.forEach(document => {
|
documentList.forEach(document => {
|
||||||
const { id, title } = document;
|
const { id, title, url } = document;
|
||||||
const node = { id, title, type: 'document' };
|
const node = { id, title, url, type: 'document' };
|
||||||
results.push(_.concat(path, node));
|
results.push(_.concat(path, node));
|
||||||
travelDocuments(document.children, _.concat(path, [node]));
|
travelDocuments(document.children, _.concat(path, [node]));
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.isLoaded) {
|
if (this.isLoaded) {
|
||||||
this.data.forEach(collection => {
|
this.data.forEach(collection => {
|
||||||
const { id, name } = collection;
|
const { id, name, url } = collection;
|
||||||
const node = { id, title: name, type: 'collection' };
|
const node = { id, title: name, url, type: 'collection' };
|
||||||
results.push([node]);
|
results.push([node]);
|
||||||
travelDocuments(collection.documents, [node]);
|
travelDocuments(collection.documents, [node]);
|
||||||
});
|
});
|
||||||
@@ -87,6 +88,11 @@ class CollectionsStore {
|
|||||||
return this.pathsToDocuments.find(path => path.id === documentId);
|
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 */
|
/* Actions */
|
||||||
|
|
||||||
@action fetchAll = async (): Promise<*> => {
|
@action fetchAll = async (): Promise<*> => {
|
||||||
|
|||||||
Reference in New Issue
Block a user