Skip to content

feat (desktop): added open first file on changes open#693

Merged
AviPeltz merged 3 commits into
mainfrom
open-file-when-opening-changes
Jan 10, 2026
Merged

feat (desktop): added open first file on changes open#693
AviPeltz merged 3 commits into
mainfrom
open-file-when-opening-changes

Conversation

@AviPeltz
Copy link
Copy Markdown
Collaborator

@AviPeltz AviPeltz commented Jan 9, 2026

Description

Related Issues

Type of Change

  • Bug fix
  • New feature
  • Documentation
  • Refactor
  • Other (please describe):

Testing

Screenshots (if applicable)

Additional Notes

Summary by CodeRabbit

Release Notes

  • New Features
    • Sidebar now automatically opens the first available changed file when activated
    • Smart file selection prioritizes files by change status (staged, unstaged, untracked)
    • File content automatically refreshes after opening from the sidebar
    • Streamlined workflow for navigating recent changes in your workspace

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 9, 2026

📝 Walkthrough

Walkthrough

The SidebarControl component was enhanced to automatically open the first available changed file when the sidebar is activated. It queries workspace context, resolves the base branch, determines file changes by priority category (against-base, staged, unstaged, untracked), and integrates with tab management to display the file while invalidating cached content.

Changes

Cohort / File(s) Summary
Sidebar Auto-File Opening
apps/desktop/src/renderer/screens/main/components/SidebarControl/SidebarControl.tsx
Added priority-based file selection logic that activates when sidebar is toggled. Fetches workspace/worktree context, resolves base branch, queries file changes, integrates with tab management (addFileViewerPane, selectFile), and invalidates file content. Introduces handleClick handler replacing direct onClick behavior and adds FILE_CATEGORIES constant.

Sequence Diagrams

sequenceDiagram
    actor User
    participant SidebarControl
    participant WorkspaceStore
    participant FileChangesAPI
    participant TabManager
    participant FileContentCache

    User->>SidebarControl: Click toggle button
    SidebarControl->>SidebarControl: Check sidebar state
    alt Sidebar is closed
        SidebarControl->>WorkspaceStore: Fetch active workspace
        WorkspaceStore-->>SidebarControl: Return workspace/worktree context
        SidebarControl->>WorkspaceStore: Get base branch (with fallback)
        WorkspaceStore-->>SidebarControl: Return base branch
        SidebarControl->>FileChangesAPI: Query file changes by category
        FileChangesAPI-->>SidebarControl: Return prioritized file list
        SidebarControl->>SidebarControl: Select first available file
        SidebarControl->>TabManager: Add file to viewer pane
        TabManager-->>SidebarControl: File opened
        SidebarControl->>TabManager: Select file in tabs
        SidebarControl->>FileContentCache: Invalidate file content
        FileContentCache-->>SidebarControl: Cache cleared
    end
    SidebarControl->>SidebarControl: Toggle sidebar visibility
    SidebarControl-->>User: Sidebar toggled (+ file opened if closed)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 A button click now whispers "Come and see!"
Files opened first, by priority spree,
Workspace roots and branches dance in code,
Tab panes light up along the well-worn road,
The sidebar hops alive with eager glee! ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The pull request description is entirely templated with no actual content filled in by the author. Fill in all required sections: provide a clear description of changes, link related issues, specify the type of change, describe testing performed, and add any relevant screenshots or notes.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding functionality to open the first file when changes are opened, which aligns with the feature implementation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@AviPeltz AviPeltz marked this pull request as ready for review January 9, 2026 19:33
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
apps/desktop/src/renderer/screens/main/components/SidebarControl/SidebarControl.tsx (1)

107-114: Consider simplifying by extracting the common toggleSidebar() call.

Both branches call toggleSidebar(), which can be extracted to reduce duplication.

♻️ Suggested simplification
 const handleClick = useCallback(() => {
-	if (isSidebarOpen) {
-		toggleSidebar();
-	} else {
-		toggleSidebar();
+	const wasOpen = isSidebarOpen;
+	toggleSidebar();
+	if (!wasOpen) {
 		openFirstFile();
 	}
 }, [isSidebarOpen, toggleSidebar, openFirstFile]);
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3e43658 and a628a09.

📒 Files selected for processing (1)
  • apps/desktop/src/renderer/screens/main/components/SidebarControl/SidebarControl.tsx
🧰 Additional context used
📓 Path-based instructions (6)
apps/desktop/**/*.{ts,tsx}

📄 CodeRabbit inference engine (apps/desktop/AGENTS.md)

apps/desktop/**/*.{ts,tsx}: For Electron interprocess communication, ALWAYS use tRPC as defined in src/lib/trpc
Use alias as defined in tsconfig.json when possible
Prefer zustand for state management if it makes sense. Do not use effect unless absolutely necessary.
For tRPC subscriptions with trpc-electron, ALWAYS use the observable pattern from @trpc/server/observable instead of async generators, as the library explicitly checks isObservable(result) and throws an error otherwise

Files:

  • apps/desktop/src/renderer/screens/main/components/SidebarControl/SidebarControl.tsx
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx}: Use object parameters for functions with 2+ parameters instead of positional arguments
Functions with 2+ parameters should accept a single params object with named properties for self-documentation and extensibility
Use prefixed console logging with context pattern: [domain/operation] message
Extract magic numbers and hardcoded values to named constants at module top
Use lookup objects/maps instead of repeated if (type === ...) conditionals
Avoid using any type - maintain type safety in TypeScript code
Never swallow errors silently - at minimum log them with context
Import from concrete files directly when possible - avoid barrel file abuse that creates circular dependencies
Avoid deep nesting (4+ levels) - use early returns, extract functions, and invert conditions
Use named properties in options objects instead of boolean parameters to avoid boolean blindness

Files:

  • apps/desktop/src/renderer/screens/main/components/SidebarControl/SidebarControl.tsx
apps/desktop/src/renderer/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Never import Node.js modules (fs, path, os, net) in renderer process or shared code - they are externalized for browser compatibility

Files:

  • apps/desktop/src/renderer/screens/main/components/SidebarControl/SidebarControl.tsx
**/*.tsx

📄 CodeRabbit inference engine (AGENTS.md)

One component per file - do not create multi-component files

Files:

  • apps/desktop/src/renderer/screens/main/components/SidebarControl/SidebarControl.tsx
apps/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use Drizzle ORM for all database operations - never use raw SQL

Files:

  • apps/desktop/src/renderer/screens/main/components/SidebarControl/SidebarControl.tsx
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use Biome for formatting and linting - run at root level with bun run lint:fix or biome check --write

Files:

  • apps/desktop/src/renderer/screens/main/components/SidebarControl/SidebarControl.tsx
🧬 Code graph analysis (1)
apps/desktop/src/renderer/screens/main/components/SidebarControl/SidebarControl.tsx (1)
apps/desktop/src/shared/changes-types.ts (1)
  • ChangeCategory (15-19)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build
🔇 Additional comments (4)
apps/desktop/src/renderer/screens/main/components/SidebarControl/SidebarControl.tsx (4)

27-44: Query enabling logic is well-structured.

The conditional query enabling (!isSidebarOpen) ensures data is pre-fetched while the sidebar is closed and available immediately when the user clicks. This avoids unnecessary refetches while the sidebar is open.


50-70: LGTM!

Good error handling with proper context logging following the [domain/operation] pattern. The parallel invalidation with Promise.all is efficient.


72-105: LGTM!

The priority-based file selection logic is clear and efficient. The early return guards prevent unnecessary processing, and the callback properly chains the file selection, pane opening, and cache invalidation.


14-22: The status object does include the untracked property. The GitChangesStatus type (returned by the getStatus endpoint) explicitly defines untracked: ChangedFile[], and the router returns this field directly. The FILE_CATEGORIES mapping is correct.

@AviPeltz AviPeltz merged commit 85a98a2 into main Jan 10, 2026
5 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

  • ⚠️ Neon database branch
  • ⚠️ Electric Fly.io app

Thank you for your contribution! 🎉

saddlepaddle pushed a commit that referenced this pull request Jan 10, 2026
* added open file on changes open

* make less verbose and fewer trpc calls
@Kitenite Kitenite deleted the open-file-when-opening-changes branch January 10, 2026 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant