Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions moon/apps/web/components/CodeView/TreeView/CustomLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface CustomLabelProps {
}

// Custom label component used to render each node in the tree structure
export function CustomLabel({ icon: Icon, children, onClick, ...other }: CustomLabelProps) {
export function CustomLabel({ icon: Icon, children, ...other }: CustomLabelProps) {
return (
<TreeItemLabel
{...other}
Expand All @@ -22,15 +22,11 @@ export function CustomLabel({ icon: Icon, children, onClick, ...other }: CustomL
{Icon && (
<Box component={Icon} className="labelIcon" color="inherit" sx={{ mr: 1, fontSize: '1.2rem' }} />
)}
<TreeItemLabel
sx={{fontSize: '14px', cursor: 'pointer'}}
onClick={(e) => {
e.stopPropagation();
onClick?.(e);
}}
<div
style={{fontSize: '14px', cursor: 'pointer'}}
>
{children}
</TreeItemLabel>
</div>
Comment on lines +25 to +29

Copilot AI Sep 4, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replacing TreeItemLabel with a div loses semantic meaning and accessibility features. Consider keeping TreeItemLabel and removing only the onClick handler instead of replacing the entire component.

Copilot uses AI. Check for mistakes.
</TreeItemLabel>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface CustomTreeItemProps

// Custom tree structure node component, used to render elements such as icons and labels for each node
export const CustomTreeItem = React.forwardRef(function CustomTreeItem(
{ onLabelClick, loadingDirectories, ...props }: CustomTreeItemProps,
{ loadingDirectories, ...props }: CustomTreeItemProps,
ref: React.Ref<HTMLLIElement>,
) {
const { id, itemId, label, disabled, children, ...other } = props;
Expand Down Expand Up @@ -81,11 +81,6 @@ export const CustomTreeItem = React.forwardRef(function CustomTreeItem(
{...getLabelProps({
icon,
})}
onClick={() => {
if (item.content_type) {
onLabelClick?.(item.path, item.content_type === 'directory');
}
}}
/>

<TreeItemDragAndDropOverlay {...getDragAndDropOverlayProps()} />
Expand Down
20 changes: 18 additions & 2 deletions moon/apps/web/components/CodeView/TreeView/RepoTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { CustomTreeItem } from './CustomTreeItem';
import toast from 'react-hot-toast';
import { useAtom } from 'jotai';
import { expandedNodesAtom, treeAllDataAtom } from './codeTreeAtom';
import { useTreeViewApiRef } from "@mui/x-tree-view";

const RepoTree = ({ onCommitInfoChange }: { onCommitInfoChange?:Function }) => {
const router = useRouter();
Expand All @@ -19,7 +20,9 @@ const RepoTree = ({ onCommitInfoChange }: { onCommitInfoChange?:Function }) => {
const basePath = pathname?.replace(
new RegExp(`\\/${scope}\\/code\\/(tree|blob)`),
''
) || '/';
) || '/';

const apiRef = useTreeViewApiRef();

const [treeAllData, setTreeAllData] = useAtom(treeAllDataAtom)
const [expandedNodes, setExpandedNodes] = useAtom(expandedNodesAtom)
Expand Down Expand Up @@ -116,6 +119,18 @@ const handleNodeToggle = useCallback((_event: React.SyntheticEvent | null, nodeI
}
}, [router, scope]);

const handleFocusItem = (_e: React.SyntheticEvent | null, itemId: string) => {
const item = apiRef.current!.getItem(itemId)

if (item.content_type) {
handleLabelClick(item.path, item.content_type === 'directory');
apiRef.current?.setItemSelection({
Comment on lines +123 to +127

Copilot AI Sep 4, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using non-null assertion operator (!) is risky here. Consider adding a null check to handle cases where the API reference might not be initialized or the item doesn't exist.

Suggested change
const item = apiRef.current!.getItem(itemId)
if (item.content_type) {
handleLabelClick(item.path, item.content_type === 'directory');
apiRef.current?.setItemSelection({
if (!apiRef.current) {
// Optionally, you could log or handle the error here
return;
}
const item = apiRef.current.getItem(itemId);
if (item && item.content_type) {
handleLabelClick(item.path, item.content_type === 'directory');
apiRef.current.setItemSelection({

Copilot uses AI. Check for mistakes.
itemId,
keepExistingSelection: false
})
}
}

useEffect(() => {
if (basePath) {
onCommitInfoChange?.(basePath);
Expand All @@ -131,15 +146,16 @@ const handleNodeToggle = useCallback((_event: React.SyntheticEvent | null, nodeI
)
: (
<RichTreeView
apiRef={apiRef}
items={treeAllData}
onItemFocus={handleFocusItem}
expandedItems={expandedNodes}
onExpandedItemsChange={handleNodeToggle}
sx={{ height: 'fit-content', flexGrow: 1, width: '100%', overflow: 'auto' }}
slots={{
item: (itemProps) => (
<CustomTreeItem
{...itemProps}
onLabelClick={handleLabelClick}
loadingDirectories={loadingDirectories}
/>
)
Expand Down