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/services/utils/index.ts b/webapp/src/services/utils/index.ts index 4c73f86c13..612a11e416 100644 --- a/webapp/src/services/utils/index.ts +++ b/webapp/src/services/utils/index.ts @@ -201,12 +201,8 @@ export const buildModificationDate = ( return duration.locale(language.substring(0, 2) === "fr" ? "fr" : "en").humanize(); }; -export const countAllChildrens = (tree: VariantTree): number => { - 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) {