Skip to content

Commit 9299a76

Browse files
committed
🤖 Review: Move Files Changed to top and remove prefix subtraction
- Position file tree on top/left instead of bottom/right - Remove common prefix extraction logic - Show full directory structure without automatic prefix subtraction - Users can now collapse/expand the entire tree hierarchy In wide layout, file tree now appears on the left side. In narrow layout, file tree appears at the top. Changed border from border-left to border-right to match new layout. Net -43 LoC (55 deletions, 12 insertions)
1 parent fc0d5c7 commit 9299a76

File tree

2 files changed

+12
-70
lines changed

2 files changed

+12
-70
lines changed

src/components/RightSidebar/CodeReview/FileTree.tsx

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,6 @@ const TreeHeader = styled.div`
132132
gap: 8px;
133133
`;
134134

135-
const CommonPrefix = styled.div`
136-
padding: 6px 12px;
137-
background: #1e1e1e;
138-
border-bottom: 1px solid #3e3e42;
139-
font-size: 11px;
140-
color: #888;
141-
font-family: var(--font-monospace);
142-
`;
143-
144135
const EmptyState = styled.div`
145136
padding: 20px;
146137
color: #888;
@@ -194,7 +185,6 @@ const TreeNodeContent: React.FC<{
194185
depth: number;
195186
selectedPath: string | null;
196187
onSelectFile: (path: string | null) => void;
197-
commonPrefix: string | null;
198188
getFileReadStatus?: (filePath: string) => { total: number; read: number } | null;
199189
expandStateMap: Record<string, boolean>;
200190
setExpandStateMap: (
@@ -205,7 +195,6 @@ const TreeNodeContent: React.FC<{
205195
depth,
206196
selectedPath,
207197
onSelectFile,
208-
commonPrefix,
209198
getFileReadStatus,
210199
expandStateMap,
211200
setExpandStateMap,
@@ -317,7 +306,6 @@ const TreeNodeContent: React.FC<{
317306
depth={depth + 1}
318307
selectedPath={selectedPath}
319308
onSelectFile={onSelectFile}
320-
commonPrefix={commonPrefix}
321309
getFileReadStatus={getFileReadStatus}
322310
expandStateMap={expandStateMap}
323311
setExpandStateMap={setExpandStateMap}
@@ -332,7 +320,6 @@ interface FileTreeExternalProps {
332320
selectedPath: string | null;
333321
onSelectFile: (path: string | null) => void;
334322
isLoading?: boolean;
335-
commonPrefix?: string | null;
336323
getFileReadStatus?: (filePath: string) => { total: number; read: number } | null;
337324
workspaceId: string;
338325
}
@@ -342,7 +329,6 @@ export const FileTree: React.FC<FileTreeExternalProps> = ({
342329
selectedPath,
343330
onSelectFile,
344331
isLoading = false,
345-
commonPrefix = null,
346332
getFileReadStatus,
347333
workspaceId,
348334
}) => {
@@ -353,42 +339,23 @@ export const FileTree: React.FC<FileTreeExternalProps> = ({
353339
{ listener: true }
354340
);
355341

356-
// Find the node at the common prefix path to start rendering from
357-
const startNode = React.useMemo(() => {
358-
if (!commonPrefix || !root) return root;
359-
360-
// Navigate to the node at the common prefix path
361-
const parts = commonPrefix.split("/");
362-
let current = root;
363-
364-
for (const part of parts) {
365-
const child = current.children.find((c) => c.name === part);
366-
if (!child) return root; // Fallback if path not found
367-
current = child;
368-
}
369-
370-
return current;
371-
}, [root, commonPrefix]);
372-
373342
return (
374343
<>
375344
<TreeHeader>
376345
<span>Files Changed</span>
377346
{selectedPath && <ClearButton onClick={() => onSelectFile(null)}>Clear filter</ClearButton>}
378347
</TreeHeader>
379-
{commonPrefix && <CommonPrefix>{commonPrefix}/</CommonPrefix>}
380348
<TreeContainer>
381-
{isLoading && !startNode ? (
349+
{isLoading && !root ? (
382350
<EmptyState>Loading file tree...</EmptyState>
383-
) : startNode ? (
384-
startNode.children.map((child) => (
351+
) : root ? (
352+
root.children.map((child) => (
385353
<TreeNodeContent
386354
key={child.path}
387355
node={child}
388356
depth={0}
389357
selectedPath={selectedPath}
390358
onSelectFile={onSelectFile}
391-
commonPrefix={commonPrefix}
392359
getFileReadStatus={getFileReadStatus}
393360
expandStateMap={expandStateMap}
394361
setExpandStateMap={setExpandStateMap}

src/components/RightSidebar/CodeReview/ReviewPanel.tsx

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,7 @@ import { useReviewState } from "@/hooks/useReviewState";
3232
import { parseDiff, extractAllHunks } from "@/utils/git/diffParser";
3333
import { getReviewSearchStateKey } from "@/constants/storage";
3434
import { Tooltip, TooltipWrapper } from "@/components/Tooltip";
35-
import {
36-
parseNumstat,
37-
buildFileTree,
38-
extractNewPath,
39-
extractCommonPrefix,
40-
} from "@/utils/git/numstatParser";
35+
import { parseNumstat, buildFileTree, extractNewPath } from "@/utils/git/numstatParser";
4136
import type { DiffHunk, ReviewFilters as ReviewFiltersType } from "@/types/review";
4237
import type { FileTreeNode } from "@/utils/git/numstatParser";
4338
import { matchesKeybind, KEYBINDS, formatKeybind } from "@/utils/ui/keybinds";
@@ -79,15 +74,10 @@ const PanelContainer = styled.div`
7974

8075
const ContentContainer = styled.div`
8176
display: flex;
82-
flex-direction: row; /* Default: wide layout */
77+
flex-direction: column; /* Always vertical - file tree on top */
8378
flex: 1;
8479
min-height: 0;
8580
overflow: hidden;
86-
87-
/* Switch to vertical layout when container is narrow */
88-
@container review-panel (max-width: 800px) {
89-
flex-direction: column;
90-
}
9181
`;
9282

9383
const HunksSection = styled.div`
@@ -97,7 +87,7 @@ const HunksSection = styled.div`
9787
flex-direction: column;
9888
overflow: hidden;
9989
min-width: 0;
100-
order: 1; /* Stay in middle regardless of layout */
90+
order: 2; /* Come after FileTreeSection */
10191
`;
10292

10393
// Search bar styling - unified component approach
@@ -195,25 +185,16 @@ const HunkList = styled.div`
195185
`;
196186

197187
const FileTreeSection = styled.div`
198-
/* Default: Wide layout - fixed width on right side */
199-
width: 300px;
200-
flex-shrink: 0;
201-
border-left: 1px solid #3e3e42;
188+
/* Always on top, full width, scrolls away with content */
189+
width: 100%;
190+
flex: 0 1 auto; /* Can shrink but doesn't grow */
191+
max-height: 400px; /* Limit height so it doesn't dominate viewport */
202192
display: flex;
203193
flex-direction: column;
204194
overflow: hidden;
205195
min-height: 0;
206-
order: 2; /* Come after HunksSection in wide mode */
207-
208-
/* Narrow layout: full width, grow to fit full tree, above hunks */
209-
@container review-panel (max-width: 800px) {
210-
width: 100%;
211-
height: auto; /* Let it grow to show full tree */
212-
flex: 0 0 auto; /* Fixed size based on content */
213-
border-left: none;
214-
border-bottom: 1px solid #3e3e42;
215-
order: 0; /* Come before HunksSection in narrow mode */
216-
}
196+
order: 1; /* Always come before HunksSection */
197+
border-bottom: 1px solid #3e3e42;
217198
`;
218199

219200
const EmptyState = styled.div`
@@ -426,7 +407,6 @@ export const ReviewPanel: React.FC<ReviewPanelProps> = ({
426407
const [isPanelFocused, setIsPanelFocused] = useState(false);
427408
const [refreshTrigger, setRefreshTrigger] = useState(0);
428409
const [fileTree, setFileTree] = useState<FileTreeNode | null>(null);
429-
const [commonPrefix, setCommonPrefix] = useState<string | null>(null);
430410
// Map of hunkId -> toggle function for expand/collapse
431411
const toggleExpandFnsRef = useRef<Map<string, () => void>>(new Map());
432412

@@ -509,13 +489,9 @@ export const ReviewPanel: React.FC<ReviewPanelProps> = ({
509489
const numstatOutput = numstatResult.data.output ?? "";
510490
const fileStats = parseNumstat(numstatOutput);
511491

512-
// Extract common prefix for display (don't modify paths)
513-
const prefix = extractCommonPrefix(fileStats);
514-
515492
// Build tree with original paths (needed for git commands)
516493
const tree = buildFileTree(fileStats);
517494
setFileTree(tree);
518-
setCommonPrefix(prefix);
519495
}
520496
} catch (err) {
521497
console.error("Failed to load file tree:", err);
@@ -971,7 +947,6 @@ export const ReviewPanel: React.FC<ReviewPanelProps> = ({
971947
selectedPath={selectedFilePath}
972948
onSelectFile={setSelectedFilePath}
973949
isLoading={isLoadingTree}
974-
commonPrefix={commonPrefix}
975950
getFileReadStatus={getFileReadStatus}
976951
workspaceId={workspaceId}
977952
/>

0 commit comments

Comments
 (0)