diff --git a/app/components/PublishingInfo.js b/app/components/PublishingInfo.js
index 78a1582f0..29747d231 100644
--- a/app/components/PublishingInfo.js
+++ b/app/components/PublishingInfo.js
@@ -51,31 +51,31 @@ function PublishingInfo({
if (deletedAt) {
content = (
- deleted ago
+ deleted ago
);
} else if (archivedAt) {
content = (
- archived ago
+ archived ago
);
} else if (publishedAt && (neverUpdated || showPublished)) {
content = (
- published ago
+ published ago
);
} else if (isDraft) {
content = (
- saved ago
+ saved ago
);
} else {
content = (
- updated ago
+ updated ago
);
}
@@ -84,7 +84,7 @@ function PublishingInfo({
return (
- {updatedBy.name}
+ {updatedBy.name}
{content}
{showCollection &&
collection && (
diff --git a/app/models/Collection.js b/app/models/Collection.js
index 8cc5b7d11..c69d7f121 100644
--- a/app/models/Collection.js
+++ b/app/models/Collection.js
@@ -60,6 +60,25 @@ export default class Collection extends BaseModel {
travelDocuments(this.documents);
}
+ getDocumentChildren(documentId: string): NavigationNode[] {
+ let result = [];
+ const traveler = nodes => {
+ nodes.forEach(childNode => {
+ if (childNode.id === documentId) {
+ result = childNode.children;
+ return;
+ }
+ return traveler(childNode.children);
+ });
+ };
+
+ if (this.documents) {
+ traveler(this.documents);
+ }
+
+ return result;
+ }
+
pathToDocument(document: Document) {
let path;
const traveler = (nodes, previousPath) => {
diff --git a/app/scenes/Document/Document.js b/app/scenes/Document/Document.js
index 015448fb1..27cfa1549 100644
--- a/app/scenes/Document/Document.js
+++ b/app/scenes/Document/Document.js
@@ -23,7 +23,7 @@ import Header from './components/Header';
import DocumentMove from './components/DocumentMove';
import Branding from './components/Branding';
import KeyboardShortcuts from './components/KeyboardShortcuts';
-import Backlinks from './components/Backlinks';
+import References from './components/References';
import ErrorBoundary from 'components/ErrorBoundary';
import LoadingPlaceholder from 'components/LoadingPlaceholder';
import LoadingIndicator from 'components/LoadingIndicator';
@@ -415,12 +415,7 @@ class DocumentScene extends React.Component {
schema={schema}
/>
{!this.isEditing &&
- !isShare && (
-
- )}
+ !isShare && }
diff --git a/app/scenes/Document/components/Backlinks.js b/app/scenes/Document/components/Backlinks.js
deleted file mode 100644
index 9781c84ef..000000000
--- a/app/scenes/Document/components/Backlinks.js
+++ /dev/null
@@ -1,46 +0,0 @@
-// @flow
-import * as React from 'react';
-import { observer } from 'mobx-react';
-import Fade from 'components/Fade';
-import Subheading from 'components/Subheading';
-import DocumentsStore from 'stores/DocumentsStore';
-import Document from 'models/Document';
-import Backlink from './Backlink';
-
-type Props = {
- document: Document,
- documents: DocumentsStore,
-};
-
-@observer
-class Backlinks extends React.Component {
- componentDidMount() {
- this.props.documents.fetchBacklinks(this.props.document.id);
- }
-
- render() {
- const { documents, document } = this.props;
- const backlinks = documents.getBacklinedDocuments(document.id);
- const showBacklinks = !!backlinks.length;
-
- return (
- showBacklinks && (
-
- Referenced By
- {backlinks.map(backlinkedDocument => (
-
- ))}
-
- )
- );
- }
-}
-
-export default Backlinks;
diff --git a/app/scenes/Document/components/Backlink.js b/app/scenes/Document/components/ReferenceListItem.js
similarity index 77%
rename from app/scenes/Document/components/Backlink.js
rename to app/scenes/Document/components/ReferenceListItem.js
index f07c506b2..e3913273a 100644
--- a/app/scenes/Document/components/Backlink.js
+++ b/app/scenes/Document/components/ReferenceListItem.js
@@ -5,10 +5,11 @@ import { Link } from 'react-router-dom';
import styled from 'styled-components';
import PublishingInfo from 'components/PublishingInfo';
import Document from 'models/Document';
+import type { NavigationNode } from 'types';
type Props = {
- document: Document,
- anchor: string,
+ document: Document | NavigationNode,
+ anchor?: string,
showCollection?: boolean,
};
@@ -43,7 +44,7 @@ const Title = styled.h3`
`;
@observer
-class Backlink extends React.Component {
+class ReferenceListItem extends React.Component {
render() {
const { document, showCollection, anchor, ...rest } = this.props;
@@ -51,16 +52,18 @@ class Backlink extends React.Component {
{document.title}
-
+ {document.updatedBy && (
+
+ )}
);
}
}
-export default Backlink;
+export default ReferenceListItem;
diff --git a/app/scenes/Document/components/References.js b/app/scenes/Document/components/References.js
new file mode 100644
index 000000000..4d35a7bef
--- /dev/null
+++ b/app/scenes/Document/components/References.js
@@ -0,0 +1,83 @@
+// @flow
+import * as React from 'react';
+import { observer, inject } from 'mobx-react';
+import { withRouter, type Location } from 'react-router-dom';
+import Fade from 'components/Fade';
+import Tabs from 'components/Tabs';
+import Tab from 'components/Tab';
+import DocumentsStore from 'stores/DocumentsStore';
+import CollectionsStore from 'stores/CollectionsStore';
+import Document from 'models/Document';
+import ReferenceListItem from './ReferenceListItem';
+
+type Props = {
+ document: Document,
+ documents: DocumentsStore,
+ collections: CollectionsStore,
+ location: Location,
+};
+
+@observer
+class References extends React.Component {
+ componentDidMount() {
+ this.props.documents.fetchBacklinks(this.props.document.id);
+ }
+
+ render() {
+ const { documents, collections, document } = this.props;
+ const backlinks = documents.getBacklinedDocuments(document.id);
+ const collection = collections.get(document.collectionId);
+ const children = collection
+ ? collection.getDocumentChildren(document.id)
+ : [];
+
+ const showBacklinks = !!backlinks.length;
+ const showChildren = !!children.length;
+ const isBacklinksTab =
+ this.props.location.hash === '#backlinks' || !showChildren;
+
+ return (
+ (showBacklinks || showChildren) && (
+
+
+ {showChildren && (
+ !isBacklinksTab}>
+ Child documents
+
+ )}
+ {showBacklinks && (
+ isBacklinksTab}>
+ References
+
+ )}
+
+ {isBacklinksTab
+ ? backlinks.map(backlinkedDocument => (
+
+ ))
+ : children.map(node => {
+ // If we have the document in the store already then use it to get the extra
+ // contextual info, otherwise the collection node will do (only has title and id)
+ const document = documents.get(node.id);
+ return (
+
+ );
+ })}
+
+ )
+ );
+ }
+}
+
+export default withRouter(inject('documents', 'collections')(References));
diff --git a/app/scenes/Search/Search.js b/app/scenes/Search/Search.js
index 776a65313..d2c84d962 100644
--- a/app/scenes/Search/Search.js
+++ b/app/scenes/Search/Search.js
@@ -128,7 +128,9 @@ class Search extends React.Component {
};
handleNewDoc = () => {
- this.props.history.push(newDocumentUrl(this.collectionId));
+ if (this.collectionId) {
+ this.props.history.push(newDocumentUrl(this.collectionId));
+ }
};
get includeArchived() {