Skip to content

Commit

Permalink
CRISTAL-236: Navigation tree with no child sometimes have an expand b…
Browse files Browse the repository at this point in the history
…utton (#527)
  • Loading branch information
pjeanjean authored Dec 18, 2024
1 parent a3cd728 commit 2710b60
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,29 @@ class NextcloudNavigationTreeSource implements NavigationTreeSource {
async getChildNodes(id?: string): Promise<Array<NavigationTreeNode>> {
const currentId = id ? id : "";
const navigationTree: Array<NavigationTreeNode> = [];
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;
Expand All @@ -92,7 +95,7 @@ class NextcloudNavigationTreeSource implements NavigationTreeSource {
method: "PROPFIND",
headers: {
...this.getBaseHeaders(),
Depth: "1",
Depth: "2",
},
},
);
Expand All @@ -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("/"));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down Expand Up @@ -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,
});
}
}
Expand Down

0 comments on commit 2710b60

Please sign in to comment.