diff --git a/webapp/src/components/App/Singlestudy/NavHeader/Details.tsx b/webapp/src/components/App/Singlestudy/NavHeader/Details.tsx index 3a557db208..4ea99b62fb 100644 --- a/webapp/src/components/App/Singlestudy/NavHeader/Details.tsx +++ b/webapp/src/components/App/Singlestudy/NavHeader/Details.tsx @@ -24,7 +24,7 @@ import { Link } from "react-router-dom"; import { buildModificationDate, convertUTCToLocalTime, - countAllChildrens, + countDescendants, displayVersionName, } from "../../../../services/utils"; import type { StudyMetadata, VariantTree } from "../../../../common/types"; @@ -105,7 +105,7 @@ function Details({ study, parent, childrenTree }: Props) { {childrenTree && ( - {countAllChildrens(childrenTree)} + {countDescendants(childrenTree)} )} diff --git a/webapp/src/components/App/Studies/StudiesList/index.tsx b/webapp/src/components/App/Studies/StudiesList/index.tsx index 82587d0e12..dba3866d98 100644 --- a/webapp/src/components/App/Studies/StudiesList/index.tsx +++ b/webapp/src/components/App/Studies/StudiesList/index.tsx @@ -285,7 +285,7 @@ function StudiesList(props: StudiesListProps) { > {`${t("studies.scanFolder")} ${folder}?`} diff --git a/webapp/src/components/App/Studies/StudyTree/StudyTreeNode.tsx b/webapp/src/components/App/Studies/StudyTree/StudyTreeNode.tsx index e84b9592c9..7d3644f06f 100644 --- a/webapp/src/components/App/Studies/StudyTree/StudyTreeNode.tsx +++ b/webapp/src/components/App/Studies/StudyTree/StudyTreeNode.tsx @@ -12,7 +12,8 @@ * This file is part of the Antares project. */ -import { memo } from "react"; +import { memo, useMemo } from "react"; +import * as R from "ramda"; import type { StudyTreeNodeProps } from "./types"; import TreeItemEnhanced from "@/components/common/TreeItemEnhanced"; import { t } from "i18next"; @@ -25,6 +26,11 @@ export default memo(function StudyTreeNode({ const isLoadingFolder = studyTreeNode.hasChildren && studyTreeNode.children.length === 0; const id = parentId ? `${parentId}/${studyTreeNode.name}` : studyTreeNode.name; + const sortedChildren = useMemo( + () => R.sortBy(R.prop("name"), studyTreeNode.children), + [studyTreeNode.children], + ); + if (isLoadingFolder) { return ( onNodeClick(id, studyTreeNode)} > - {studyTreeNode.children.map((child) => ( + {sortedChildren.map((child) => ( { - if (tree.children.length > 0) { - return tree.children.map((elm) => 1 + countAllChildrens(elm)).reduce((acc, curr) => acc + curr); - } - return 0; -}; +export const countDescendants = (tree: VariantTree): number => + tree.children.length + ? tree.children.reduce((sum, child) => sum + 1 + countDescendants(child), 0) + : 0; export const findNodeInTree = (studyId: string, tree: VariantTree): VariantTree | undefined => { if (studyId === tree.node.id) {