From 2710b6025b6e4303f40b4a44e704dfd50890423b Mon Sep 17 00:00:00 2001 From: Pierre Jeanjean Date: Wed, 18 Dec 2024 02:59:26 -0800 Subject: [PATCH] CRISTAL-236: Navigation tree with no child sometimes have an expand button (#527) --- .../src/components/componentsInit.ts | 5 ++- .../src/components/componentsInit.ts | 39 ++++++++++--------- .../src/components/componentsInit.ts | 4 +- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/core/navigation-tree/navigation-tree-filesystem/src/components/componentsInit.ts b/core/navigation-tree/navigation-tree-filesystem/src/components/componentsInit.ts index 4f55f3d0d..0f90f1c4a 100644 --- a/core/navigation-tree/navigation-tree-filesystem/src/components/componentsInit.ts +++ b/core/navigation-tree/navigation-tree-filesystem/src/components/componentsInit.ts @@ -75,7 +75,10 @@ class FileSystemNavigationTreeSource implements NavigationTreeSource { page: id, }, }).href, - has_children: true, // TODO: Detect empty folders. + has_children: + (await fileSystemStorage.listChildren(id)).filter( + (c: string) => c != "attachments", + ).length > 0, }); } } diff --git a/core/navigation-tree/navigation-tree-nextcloud/src/components/componentsInit.ts b/core/navigation-tree/navigation-tree-nextcloud/src/components/componentsInit.ts index 8a91d4eea..67e0ca7e0 100644 --- a/core/navigation-tree/navigation-tree-nextcloud/src/components/componentsInit.ts +++ b/core/navigation-tree/navigation-tree-nextcloud/src/components/componentsInit.ts @@ -56,26 +56,29 @@ class NextcloudNavigationTreeSource implements NavigationTreeSource { async getChildNodes(id?: string): Promise> { const currentId = id ? id : ""; const navigationTree: Array = []; + const currentDepth = currentId ? currentId.split("/").length : 0; const subdirectories = await this.getSubDirectories(currentId); for (const d of subdirectories) { const spaces = d.split("/"); const currentPageData = await this.cristalApp.getPage(d); - navigationTree.push({ - id: d, - label: - currentPageData && currentPageData.name - ? currentPageData.name - : spaces[spaces.length - 1], - location: new SpaceReference(undefined, ...spaces), - url: this.cristalApp.getRouter().resolve({ - name: "view", - params: { - page: d, - }, - }).href, - has_children: true, // TODO: Detect empty folders. - }); + if (spaces.length == currentDepth + 1) { + navigationTree.push({ + id: d, + label: + currentPageData && currentPageData.name + ? currentPageData.name + : spaces[spaces.length - 1], + location: new SpaceReference(undefined, ...spaces), + url: this.cristalApp.getRouter().resolve({ + name: "view", + params: { + page: d, + }, + }).href, + has_children: subdirectories.some((d2) => d2.startsWith(`${d}/`)), + }); + } } return navigationTree; @@ -92,7 +95,7 @@ class NextcloudNavigationTreeSource implements NavigationTreeSource { method: "PROPFIND", headers: { ...this.getBaseHeaders(), - Depth: "1", + Depth: "2", }, }, ); @@ -111,9 +114,7 @@ class NextcloudNavigationTreeSource implements NavigationTreeSource { // Remove attachments folders if (subdirectory !== "attachments") { - subdirectories.push( - `${directory ? directory + "/" : ""}${subdirectory}`, - ); + subdirectories.push(urlFragments.slice(6, -1).join("/")); } } } diff --git a/core/navigation-tree/navigation-tree-xwiki/src/components/componentsInit.ts b/core/navigation-tree/navigation-tree-xwiki/src/components/componentsInit.ts index 157c12b13..4ee062262 100644 --- a/core/navigation-tree/navigation-tree-xwiki/src/components/componentsInit.ts +++ b/core/navigation-tree/navigation-tree-xwiki/src/components/componentsInit.ts @@ -131,6 +131,8 @@ class XWikiNavigationTreeSource implements NavigationTreeSource { ["data", "children"], ["compact", "true"], ["offset", offset.toString()], + ["showTranslations", "false"], + ["showAttachments", "false"], ]).toString(); const response = await fetch(navigationTreeRequestUrl, { headers }); @@ -165,7 +167,7 @@ class XWikiNavigationTreeSource implements NavigationTreeSource { page: this.referenceSerializer.serialize(documentReference), }, }).href, - has_children: treeNode.children, //TODO: ignore translations and attachments + has_children: treeNode.children, }); } }