diff --git a/webapp/src/components/App/Singlestudy/explore/Debug/Tree/FileTreeItem.tsx b/webapp/src/components/App/Singlestudy/explore/Debug/Tree/FileTreeItem.tsx index aaabe7d212..a59cf6a640 100644 --- a/webapp/src/components/App/Singlestudy/explore/Debug/Tree/FileTreeItem.tsx +++ b/webapp/src/components/App/Singlestudy/explore/Debug/Tree/FileTreeItem.tsx @@ -1,8 +1,8 @@ import { Box } from "@mui/material"; -import { TreeItem, type TreeItemProps } from "@mui/x-tree-view/TreeItem"; import { TreeData, getFileType, getFileIcon, isFolder } from "../utils"; import DebugContext from "../DebugContext"; import { useContext } from "react"; +import TreeItemEnhanced from "../../../../../common/TreeItemEnhanced"; interface Props { name: string; @@ -15,22 +15,12 @@ function FileTreeItem({ name, treeData, path }: Props) { const filePath = path ? `${path}/${name}` : name; const fileType = getFileType(treeData); const FileIcon = getFileIcon(fileType); - const canExpand = isFolder(treeData) && Object.keys(treeData).length > 0; //////////////////////////////////////////////////////////////// // Event handlers //////////////////////////////////////////////////////////////// - const handleClick: TreeItemProps["onClick"] = ({ target }) => { - // The item is not selected if the click is on the expand/collapse icon - if ( - canExpand && - target instanceof Element && - target.closest(".MuiTreeItem-iconContainer") - ) { - return; - } - + const handleClick = () => { setSelectedFile({ fileType, filename: name, filePath, treeData }); }; @@ -39,7 +29,7 @@ function FileTreeItem({ name, treeData, path }: Props) { //////////////////////////////////////////////////////////////// return ( - @@ -48,24 +38,6 @@ function FileTreeItem({ name, treeData, path }: Props) { } onClick={handleClick} - sx={{ - ".MuiTreeItem-content": { - p: 0, - alignItems: "normal", - // Expand/collapse icon - ".MuiTreeItem-iconContainer": { - alignItems: "center", - borderTopLeftRadius: "inherit", - borderBottomLeftRadius: "inherit", - "&:hover": { - background: canExpand ? "inherit" : "none", - }, - }, - ".MuiTreeItem-label": { - py: 0.5, - }, - }, - }} > {isFolder(treeData) && Object.keys(treeData).map((childName) => ( @@ -76,7 +48,7 @@ function FileTreeItem({ name, treeData, path }: Props) { treeData={treeData[childName]} /> ))} - + ); } diff --git a/webapp/src/components/common/TreeItemEnhanced.tsx b/webapp/src/components/common/TreeItemEnhanced.tsx new file mode 100644 index 0000000000..d1e8313d31 --- /dev/null +++ b/webapp/src/components/common/TreeItemEnhanced.tsx @@ -0,0 +1,62 @@ +import { TreeItem, type TreeItemProps } from "@mui/x-tree-view/TreeItem"; +import { mergeSxProp } from "../../utils/muiUtils"; +import * as RA from "ramda-adjunct"; + +export type TreeItemEnhancedProps = TreeItemProps; + +function TreeItemEnhanced({ onClick, sx, ...rest }: TreeItemEnhancedProps) { + const canExpand = rest.children && RA.isNotEmpty(rest.children); + + //////////////////////////////////////////////////////////////// + // Event Handlers + //////////////////////////////////////////////////////////////// + + const handleClick: TreeItemEnhancedProps["onClick"] = (event) => { + const { target } = event; + + // The item is not selected if the click is on the expand/collapse icon + if ( + canExpand && + target instanceof Element && + target.closest(".MuiTreeItem-iconContainer") + ) { + return; + } + + onClick?.(event); + }; + + //////////////////////////////////////////////////////////////// + // JSX + //////////////////////////////////////////////////////////////// + + return ( + + ); +} + +export default TreeItemEnhanced;