Skip to content

Commit

Permalink
fix(ui): resolve sonar complexity warning (#2311)
Browse files Browse the repository at this point in the history
  • Loading branch information
hdinia authored Jan 23, 2025
1 parent 0e87c2f commit 5c3f165
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions webapp/src/components/App/Singlestudy/NavHeader/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -105,7 +105,7 @@ function Details({ study, parent, childrenTree }: Props) {
{childrenTree && (
<BoxContainer>
<AccountTreeOutlinedIcon sx={{ color: "text.secondary", mr: 1 }} />
<TinyText>{countAllChildrens(childrenTree)}</TinyText>
<TinyText>{countDescendants(childrenTree)}</TinyText>
</BoxContainer>
)}
<StyledDivider />
Expand Down
10 changes: 4 additions & 6 deletions webapp/src/services/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,10 @@ 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) {
Expand Down

0 comments on commit 5c3f165

Please sign in to comment.