From ce3466734435826d90a03b4ffadc78d3a9689cfe Mon Sep 17 00:00:00 2001 From: hdinia <33469289+hdinia@users.noreply.github.com> Date: Thu, 23 Jan 2025 10:27:15 +0100 Subject: [PATCH] fix(ui): resolve sonar complexity warning --- .../src/components/App/Singlestudy/NavHeader/Details.tsx | 4 ++-- webapp/src/services/utils/index.ts | 8 ++------ 2 files changed, 4 insertions(+), 8 deletions(-) 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) {