Skip to content

Commit

Permalink
fix filter not selected when we click on folder name
Browse files Browse the repository at this point in the history
  • Loading branch information
Anis SMAIL committed Jan 30, 2025
1 parent 76ccf7b commit f4d7db3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
10 changes: 6 additions & 4 deletions webapp/src/components/App/Studies/StudiesList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +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";
import { DEFAULT_WORKSPACE_PREFIX, ROOT_FOLDER_NAME } from "@/components/common/utils/constants";

const CARD_TARGET_WIDTH = 500;
const CARD_HEIGHT = 250;
Expand All @@ -88,7 +88,9 @@ 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(DEFAULT_WORKSPACE_PREFIX);
const isInDefaultWorkspace = !!folder && folder.startsWith(DEFAULT_WORKSPACE_PREFIX);
const isRootFolder = folder === ROOT_FOLDER_NAME;
const scanDisabled: boolean = isInDefaultWorkspace || isRootFolder;

useEffect(() => {
setFolderList(folder.split("/"));
Expand Down Expand Up @@ -267,14 +269,14 @@ function StudiesList(props: StudiesListProps) {
</Tooltip>
)}

{folder !== "root" && (
{!scanDisabled && (
<Tooltip title={t("studies.scanFolder") as string}>
<IconButton onClick={() => setConfirmFolderScan(true)} disabled={scanDisabled}>
<RadarIcon />
</IconButton>
</Tooltip>
)}
{folder !== "root" && confirmFolderScan && (
{!isRootFolder && confirmFolderScan && (
<ConfirmationDialog
titleIcon={RadarIcon}
onCancel={() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default memo(function StudyTreeNode({
studyTreeNode,
parentId,
itemsLoading,
onNodeClick,
}: StudyTreeNodeProps) {
const id = parentId ? `${parentId}/${studyTreeNode.name}` : studyTreeNode.name;
const isLoadingFolder = itemsLoading.includes(id);
Expand All @@ -40,13 +41,14 @@ export default memo(function StudyTreeNode({
}

return (
<TreeItemEnhanced itemId={id} label={studyTreeNode.name}>
<TreeItemEnhanced itemId={id} label={studyTreeNode.name} onClick={() => onNodeClick(id)}>
{sortedChildren.map((child) => (
<StudyTreeNode
key={`${id}/${child.name}`}
studyTreeNode={child}
parentId={id}
itemsLoading={itemsLoading}
onNodeClick={onNodeClick}
/>
))}
</TreeItemEnhanced>
Expand Down
17 changes: 15 additions & 2 deletions webapp/src/components/App/Studies/StudyTree/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,24 @@ function StudyTree() {
// Event Handlers
////////////////////////////////////////////////////////////////

// we need to handle both the expand event and the onClick event
// because the onClick isn't triggered when user click on arrow
// Also the expanse event isn't triggered when the item doesn't have any subfolder
// but we stil want to apply the filter on the clicked folder
const handleItemExpansionToggle = async (
event: React.SyntheticEvent<Element, Event>,
itemId: string,
isExpanded: boolean,
) => {
if (isExpanded) {
dispatch(updateStudyFilters({ folder: itemId }));
updateTree(itemId, studiesTree);
}
};

const handleTreeItemClick = (itemId: string) => {
dispatch(updateStudyFilters({ folder: itemId }));
};

////////////////////////////////////////////////////////////////
// JSX
////////////////////////////////////////////////////////////////
Expand All @@ -144,7 +152,12 @@ function StudyTree() {
}}
onItemExpansionToggle={handleItemExpansionToggle}
>
<StudyTreeNodeComponent studyTreeNode={studiesTree} parentId="" itemsLoading={itemsLoading} />
<StudyTreeNodeComponent
studyTreeNode={studiesTree}
parentId=""
itemsLoading={itemsLoading}
onNodeClick={handleTreeItemClick}
/>
</SimpleTreeView>
);
}
Expand Down
1 change: 1 addition & 0 deletions webapp/src/components/App/Studies/StudyTree/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ export interface StudyTreeNodeProps {
studyTreeNode: StudyTreeNode;
parentId: string;
itemsLoading: string[];
onNodeClick: (id: string) => void;
}

0 comments on commit f4d7db3

Please sign in to comment.