fix(app): collapse commit diff files from their header - #4467
fix(app): collapse commit diff files from their header#4467CN-liuzhiyang wants to merge 1 commit into
Conversation
|
| Filename | Overview |
|---|---|
| packages/app/src/git/diff-document/types.ts | Makes collapse state a required shared capability for both working and commit diff modes. |
| packages/app/src/git/file-header.tsx | Separates pressability from working-tree actions and leaves disabled context-menu triggers transparent. |
| packages/app/src/components/ui/context-menu.tsx | Prevents disabled web triggers from consuming context-menu events. |
| packages/app/src/panels/diff-panel.tsx | Persists and supplies collapsed file paths for commit-diff panels. |
| packages/app/e2e/browser/commit-diff-panel.spec.ts | Adds collapse/expand coverage and extracts navigation mechanics, but retains the accessible-selector violation tracked by the prior review thread. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Commit diff file header] -->|Primary press| B[DocumentFileHeader activate]
B --> C[Toggle path in collapse state]
C --> D[Persist commit panel state]
D --> E[Hide or show diff file body]
A -->|Right click| F[Disabled file-actions trigger]
F -->|Event propagates| G[Outer diff-surface context menu]
Reviews (2): Last reviewed commit: "fix(app): collapse commit diff files fro..." | Re-trigger Greptile
| if (isNative) return; | ||
| // A disabled trigger owns no menu, so it must let the event reach whatever | ||
| // encloses it instead of swallowing the right click and showing nothing. | ||
| if (!shouldEnableOnThisPlatform || disabled) return; |
There was a problem hiding this comment.
When a commit header is right-clicked, this disabled trigger now lets the event bubble, but WebFileHeaderSection stops it before it reaches the outer diff-surface trigger. As a result, the Copy, Copy line, and Select all menu still does not open over commit headers, so the right-click fix is incomplete.
| const commitsSection = page.getByRole("button", { name: /Commits/i }); | ||
| await expect(commitsSection).toBeVisible({ timeout: 30_000 }); | ||
| await commitsSection.click(); | ||
| await page.locator('[data-testid^="commit-row-"]').filter({ hasText: COMMIT_SUBJECT }).click(); |
There was a problem hiding this comment.
E2E test violates requirements
This helper uses a CSS attribute selector for a user-visible commit row, and the related test body directly performs 12 lines of setup, navigation, clicks, and assertions. The repository requires accessible role/name selectors for visible controls and E2E bodies of roughly 3–8 lines of user intent, with browser mechanics moved into helpers. These requirements must be satisfied before merging.
Rule Used: # Code Review Pattern Reference: Slop, Tests, Feat... (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
The commit diff rendered file headers that could not be pressed, while the working diff collapsed a file on click. Collapse state was declared on the working branch of the DiffDocument props union, so the commit panel had no way to pass one, and DocumentFileHeader returned early on any non-working mode. Move collapseState onto the document's base props and let both modes toggle. FileHeader now separates the two things `interactive` used to mean: press and hover follow onActivate, while the drag source and the file-actions menu stay behind `interactive`, which the commit diff does not have. A disabled ContextMenuTrigger no longer swallows the right click, so a header without its own menu still lets the diff's Copy/Select all menu through. The commit panel persists collapsed paths per tab, matching the Changes panel.
06cf0cc to
a4b4615
Compare
|
Closing this commit-diff folding proposal. Please discuss the workflow and shared need in Discussions, following CONTRIBUTING.md. |
Linked issue
Closes #
Type of change
Reasoning
Clicking a file header in the working diff collapses that file. The same header in a commit diff does nothing — it is not even pressable. Nothing about collapsing is specific to the working tree; a commit that touches twenty files is exactly where you want to fold away the ones you have already read.
The reason it was missing is structural:
collapseStatewas declared on the working branch of theDiffDocumentPropsunion, so the commit panel had no way to pass one, andDocumentFileHeaderreturned early on any non-working mode.Goals
Non-goals
Implementation notes
collapseStatemoves onto the document's base props so both modes toggle.FileHeaderseparates the two thingsinteractiveused to mean. Press and hover now followonActivate; the drag source and the file-actions menu stay behindinteractive, which the commit diff does not set. Without that split a commit header would mount aContextMenuwhose content rendersnull, and right click would be swallowed for a menu that never appears.That is also why
ContextMenuTriggerchanges: a trigger withenabled={false}still calledpreventDefault/stopPropagation, so it ate the right click and showed nothing. It now lets the event through, and the diff surface's own Copy / Copy line / Select all menu still opens over a commit diff header. No existing caller passesenabled={false}, so nothing else changes.QA
Automated, on this branch:
New browser coverage in
packages/app/e2e/browser/commit-diff-panel.spec.ts:Manual, Windows desktop, against a real daemon in a real browser, through the same steps the spec runs (Changes → Commits → commit row):
Expanded:
After pressing the
feature.txtheader:Pressing again restores the body. Right clicking the header still opens the diff Copy / Copy line / Select all menu.
DocumentFileHeaderpath with web; not run on devicecommit-diff-panel.spec.tscould not be run locally: on this machine thewithWorkspacefixture never gets past "No projects yet", and it fails the same way on a clean checkout ofmain, so it is an environment problem rather than something this branch introduced. The collapse behaviour above was verified through aseedWorkspace-based run of the identical steps. CI covers the committed spec.Checklist
npm run typecheckpassesnpm run lintpassesnpm run formatpasses