Skip to content

Commit 7346e62

Browse files
Fix toggle click and directory stat display bugs in ChatView
- Fix first toggle click failing for unregistered top-level directories by passing the effective expanded state to toggleDirectory instead of toggling the raw (possibly undefined) state value. - Fix directory nodes showing +0/-0 when all children lack stats by guarding DiffStatLabel render with hasNonZeroStat, consistent with file nodes and the summary header. Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
1 parent d898b66 commit 7346e62

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

apps/web/src/components/ChatView.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3176,10 +3176,10 @@ const ChangedFilesTree = memo(function ChangedFilesTree(props: {
31763176
() => buildInitiallyExpandedDirectoryState(treeNodes),
31773177
);
31783178

3179-
const toggleDirectory = useCallback((pathValue: string) => {
3179+
const toggleDirectory = useCallback((pathValue: string, currentlyExpanded: boolean) => {
31803180
setExpandedDirectories((current) => ({
31813181
...current,
3182-
[pathValue]: !current[pathValue],
3182+
[pathValue]: !currentlyExpanded,
31833183
}));
31843184
}, []);
31853185

@@ -3193,7 +3193,7 @@ const ChangedFilesTree = memo(function ChangedFilesTree(props: {
31933193
type="button"
31943194
className="group flex w-full items-center gap-1.5 rounded-md py-1 pr-2 text-left hover:bg-background/80"
31953195
style={{ paddingLeft: `${leftPadding}px` }}
3196-
onClick={() => toggleDirectory(node.path)}
3196+
onClick={() => toggleDirectory(node.path, isExpanded)}
31973197
>
31983198
<ChevronRightIcon
31993199
aria-hidden="true"
@@ -3210,9 +3210,11 @@ const ChangedFilesTree = memo(function ChangedFilesTree(props: {
32103210
<span className="truncate font-mono text-[11px] text-muted-foreground/90 group-hover:text-foreground/90">
32113211
{node.name}
32123212
</span>
3213-
<span className="ml-auto shrink-0 font-mono text-[10px] tabular-nums">
3214-
<DiffStatLabel additions={node.stat.additions} deletions={node.stat.deletions} />
3215-
</span>
3213+
{hasNonZeroStat(node.stat) && (
3214+
<span className="ml-auto shrink-0 font-mono text-[10px] tabular-nums">
3215+
<DiffStatLabel additions={node.stat.additions} deletions={node.stat.deletions} />
3216+
</span>
3217+
)}
32163218
</button>
32173219
{isExpanded && (
32183220
<div className="space-y-0.5">

0 commit comments

Comments
 (0)