Skip to content

Commit

Permalink
fix(ui): resolve sonar complexity warning
Browse files Browse the repository at this point in the history
  • Loading branch information
hdinia committed Jan 23, 2025
1 parent e48d550 commit ce34667
Show file tree
Hide file tree
Showing 2 changed files with 4 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
8 changes: 2 additions & 6 deletions webapp/src/services/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Check failure on line 205 in webapp/src/services/utils/index.ts

View workflow job for this annotation

GitHub Actions / npm-lint

Replace `tree.children.length·?·tree.children.reduce((sum,·child)·=>·sum·+·1·+·countDescendants(child),·0)` with `·tree.children.length⏎····?·tree.children.reduce((sum,·child)·=>·sum·+·1·+·countDescendants(child),·0)⏎···`

export const findNodeInTree = (studyId: string, tree: VariantTree): VariantTree | undefined => {
if (studyId === tree.node.id) {
Expand Down

0 comments on commit ce34667

Please sign in to comment.