Skip to content

Commit

Permalink
Merge branch 'dev' into feature/2547-normalize-study-path
Browse files Browse the repository at this point in the history
  • Loading branch information
Anis SMAIL committed Jan 24, 2025
2 parents 021df2e + a31f9c1 commit 4ce505f
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 13 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
2 changes: 1 addition & 1 deletion webapp/src/components/App/Studies/StudiesList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ function StudiesList(props: StudiesListProps) {
>
{`${t("studies.scanFolder")} ${folder}?`}
<CheckBoxFE
label={t("studies.requestDeepScan")}
label={t("studies.recursiveScan")}
value={isRecursiveScan}
onChange={handleRecursiveScan}
/>
Expand Down
10 changes: 8 additions & 2 deletions webapp/src/components/App/Studies/StudyTree/StudyTreeNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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 (
<TreeItemEnhanced
Expand All @@ -43,7 +49,7 @@ export default memo(function StudyTreeNode({
label={studyTreeNode.name}
onClick={() => onNodeClick(id, studyTreeNode)}
>
{studyTreeNode.children.map((child) => (
{sortedChildren.map((child) => (
<StudyTreeNode
key={`${id}/${child.name}`}
studyTreeNode={child}
Expand Down
10 changes: 10 additions & 0 deletions webapp/src/components/App/Studies/StudyTree/__test__/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ export const FIXTURES_BUILD_STUDY_TREE = {
name: "root",
path: "",
children: [
{
name: "default",
path: "/default",
children: [],
},
{
name: "workspace",
path: "/workspace",
Expand Down Expand Up @@ -270,6 +275,11 @@ export const FIXTURES_BUILD_STUDY_TREE = {
name: "root",
path: "",
children: [
{
name: "default",
path: "/default",
children: [],
},
{
name: "workspace",
path: "/workspace",
Expand Down
11 changes: 10 additions & 1 deletion webapp/src/components/App/Studies/StudyTree/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,18 @@ import type { StudyTreeNode, NonStudyFolderDTO } from "./types";
* @returns A tree structure representing the studies.
*/
export function buildStudyTree(studies: StudyMetadata[]) {
// It is important to initialize the root node with the default workspace as a child
// Otherwise we won't see the default workspace if no study has a path (which only
// happens when a user moves a study to another folder)
const tree: StudyTreeNode = {
name: "root",
children: [],
children: [
{
name: "default",
children: [],
path: "/default",
},
],
path: "",
};

Expand Down
2 changes: 1 addition & 1 deletion webapp/src/redux/ducks/studies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const initialState = studiesAdapter.getInitialState({
filters: {
inputValue: "",
folder: "root",
strictFolder: true,
strictFolder: false,
managed: false,
archived: false,
variant: false,
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 4ce505f

Please sign in to comment.