From 9ba63c60548ca56a129f44d28319d8c18f8d58a3 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sun, 31 Jan 2021 14:41:18 -0800 Subject: [PATCH] feat: Show nested document count on document list items on collection home --- app/components/DocumentListItem.js | 3 +++ app/components/DocumentMeta.js | 12 ++++++++++++ app/components/PaginatedDocumentList.js | 1 + app/scenes/Collection.js | 1 + app/scenes/Document/components/References.js | 8 ++++---- shared/i18n/locales/en_US/translation.json | 2 ++ 6 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app/components/DocumentListItem.js b/app/components/DocumentListItem.js index e940e6d0d..78fe61d54 100644 --- a/app/components/DocumentListItem.js +++ b/app/components/DocumentListItem.js @@ -23,6 +23,7 @@ type Props = {| document: Document, highlight?: ?string, context?: ?string, + showNestedDocuments?: boolean, showCollection?: boolean, showPublished?: boolean, showPin?: boolean, @@ -44,6 +45,7 @@ function DocumentListItem(props: Props) { const [menuOpen, setMenuOpen] = React.useState(false); const { document, + showNestedDocuments, showCollection, showPublished, showPin, @@ -104,6 +106,7 @@ function DocumentListItem(props: Props) { document={document} showCollection={showCollection} showPublished={showPublished} + showNestedDocuments={showNestedDocuments} showLastViewed /> diff --git a/app/components/DocumentMeta.js b/app/components/DocumentMeta.js index 07976305b..093e0a2ce 100644 --- a/app/components/DocumentMeta.js +++ b/app/components/DocumentMeta.js @@ -27,6 +27,7 @@ type Props = {| showCollection?: boolean, showPublished?: boolean, showLastViewed?: boolean, + showNestedDocuments?: boolean, document: Document, children: React.Node, to?: string, @@ -36,6 +37,7 @@ function DocumentMeta({ showPublished, showCollection, showLastViewed, + showNestedDocuments, document, children, to, @@ -123,6 +125,10 @@ function DocumentMeta({ ); }; + const nestedDocumentsCount = collection + ? collection.getDocumentChildren(document.id).length + : 0; + return ( {updatedByMe ? t("You") : updatedBy.name}  @@ -135,6 +141,12 @@ function DocumentMeta({ )} + {showNestedDocuments && nestedDocumentsCount > 0 && ( + +  · {nestedDocumentsCount}{" "} + {t("nested document", { count: nestedDocumentsCount })} + + )}  {timeSinceNow()} {children} diff --git a/app/components/PaginatedDocumentList.js b/app/components/PaginatedDocumentList.js index 322ce6d44..f6fabd9a6 100644 --- a/app/components/PaginatedDocumentList.js +++ b/app/components/PaginatedDocumentList.js @@ -11,6 +11,7 @@ type Props = {| options?: Object, heading?: React.Node, empty?: React.Node, + showNestedDocuments?: boolean, showCollection?: boolean, showPublished?: boolean, showPin?: boolean, diff --git a/app/scenes/Collection.js b/app/scenes/Collection.js index aade71b2f..6b6ae53a3 100644 --- a/app/scenes/Collection.js +++ b/app/scenes/Collection.js @@ -352,6 +352,7 @@ class CollectionScene extends React.Component { sort: collection.sort.field, direction: "ASC", }} + showNestedDocuments showPin /> diff --git a/app/scenes/Document/components/References.js b/app/scenes/Document/components/References.js index 2dc265276..7851cafa0 100644 --- a/app/scenes/Document/components/References.js +++ b/app/scenes/Document/components/References.js @@ -32,15 +32,15 @@ class References extends React.Component { : []; const showBacklinks = !!backlinks.length; - const showChildren = !!children.length; + const showNestedDocuments = !!children.length; const isBacklinksTab = - this.props.location.hash === "#backlinks" || !showChildren; + this.props.location.hash === "#backlinks" || !showNestedDocuments; return ( - (showBacklinks || showChildren) && ( + (showBacklinks || showNestedDocuments) && ( - {showChildren && ( + {showNestedDocuments && ( !isBacklinksTab}> Nested documents diff --git a/shared/i18n/locales/en_US/translation.json b/shared/i18n/locales/en_US/translation.json index d8c075809..f75279760 100644 --- a/shared/i18n/locales/en_US/translation.json +++ b/shared/i18n/locales/en_US/translation.json @@ -23,6 +23,8 @@ "Never viewed": "Never viewed", "Viewed": "Viewed", "in": "in", + "nested document": "nested document", + "nested document_plural": "nested documents", "Insert column after": "Insert column after", "Insert column before": "Insert column before", "Insert row after": "Insert row after",