Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Anis SMAIL committed Jan 30, 2025
1 parent d41ed19 commit 76ccf7b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion webapp/src/components/App/Studies/StudiesList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import { scanFolder } from "../../../../services/api/study";
import useEnqueueErrorSnackbar from "../../../../hooks/useEnqueueErrorSnackbar";
import ConfirmationDialog from "../../../common/dialogs/ConfirmationDialog";
import CheckBoxFE from "@/components/common/fieldEditors/CheckBoxFE";
import { DEFAULT_WORKSPACE_PREFIX } from "@/components/common/utils/constants";

const CARD_TARGET_WIDTH = 500;
const CARD_HEIGHT = 250;
Expand All @@ -87,7 +88,7 @@ function StudiesList(props: StudiesListProps) {
const [selectionMode, setSelectionMode] = useState(false);
const [confirmFolderScan, setConfirmFolderScan] = useState(false);
const [isRecursiveScan, setIsRecursiveScan] = useState(false);
const scanDisabled: boolean = !!folder && folder.startsWith("root/default");
const scanDisabled: boolean = !!folder && folder.startsWith(DEFAULT_WORKSPACE_PREFIX);

useEffect(() => {
setFolderList(folder.split("/"));
Expand Down
7 changes: 4 additions & 3 deletions webapp/src/components/App/Studies/StudyTree/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { fetchAndInsertSubfolders, fetchAndInsertWorkspaces } from "./utils";
import { useTranslation } from "react-i18next";
import { toError } from "@/utils/fnUtils";
import StudyTreeNodeComponent from "./StudyTreeNode";
import { DEFAULT_WORKSPACE_PREFIX, ROOT_FOLDER_NAME } from "@/components/common/utils/constants";

function StudyTree() {
const initialStudiesTree = useAppSelector(getStudiesTree);
Expand All @@ -42,7 +43,7 @@ function StudyTree() {
useUpdateEffectOnce(() => {
// be carefull to pass initialStudiesTree and not studiesTree at rootNode parameter
// otherwise we'll lose the default workspace
updateTree("root", initialStudiesTree);
updateTree(ROOT_FOLDER_NAME, initialStudiesTree);
}, [initialStudiesTree]);

/**
Expand All @@ -62,7 +63,7 @@ function StudyTree() {
* @param selectedNode - The node of the item clicked
*/
async function updateTree(itemId: string, rootNode: StudyTreeNode) {
if (itemId.startsWith("root/default")) {
if (itemId.startsWith(DEFAULT_WORKSPACE_PREFIX)) {
// we don't update the tree if the user clicks on the default workspace
// api doesn't allow to fetch the subfolders of the default workspace
return;
Expand All @@ -80,7 +81,7 @@ function StudyTree() {
let pathsToFetch: string[] = [];
// If the user clicks on the root folder, we fetch the workspaces and insert them.
// Then we fetch the direct subfolders of the workspaces.
if (itemId === "root") {
if (itemId === ROOT_FOLDER_NAME) {
try {
treeAfterWorkspacesUpdate = await fetchAndInsertWorkspaces(rootNode);
} catch (error) {
Expand Down
3 changes: 3 additions & 0 deletions webapp/src/components/common/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ export const PUBLIC_MODE_LIST: GenericInfo[] = [
{ id: "EDIT", name: "global.edit" },
{ id: "FULL", name: "study.fullPublicMode" },
];

export const ROOT_FOLDER_NAME = "root";
export const DEFAULT_WORKSPACE_PREFIX = `${ROOT_FOLDER_NAME}/default`;

0 comments on commit 76ccf7b

Please sign in to comment.