onlook icon indicating copy to clipboard operation
onlook copied to clipboard

fix: branch deletion in template copies by querying database directly

Open naaa760 opened this issue 2 months ago • 2 comments

Description

fixes: #2896

  • Fixed branch deletion issue in template copies where users couldn't delete branches even when multiple branches existed. The problem was caused by unreliable local state checking that didn't reflect the actual database state.

Related Issues

  • Fixes the bug where branches aren't deletable in template copies.

Type of Change

  • [x] Bug fix

Summary by CodeRabbit

  • New Features
    • Automatically selects a valid target branch when deleting the active branch for a seamless transition.
  • Bug Fixes
    • Prevents deleting when it would leave no branches, using a live branch count.
    • Deletion logic now uses real-time data instead of cached state for improved reliability.
  • Style
    • Simplified Delete button label to “Delete branch” and removed the “only branch” disabled state to reduce confusion.

naaa760 avatar Oct 02 '25 04:10 naaa760

@naaa760 is attempting to deploy a commit to the Onlook Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Oct 02 '25 04:10 vercel[bot]

Walkthrough

Replaced in-memory branch checks with a live database query during deletion, added selection of a valid target branch before deleting an active branch, and simplified the Delete button state and title. The deletion flow now depends on querying remaining branches and switching to a determined target branch when required.

Changes

Cohort / File(s) Summary of Changes
Branch deletion control flow update
apps/web/client/src/app/project/[id]/_components/left-panel/branches-tab/branch-management.tsx
Replace in-memory last-branch detection with live DB check; compute otherBranches from queried remaining branches; select targetBranch (default or first) before deleting if active; throw if ≤1 remaining or no target; simplify Delete button to use isDeleting and static title.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant UI as BranchManagement UI
    participant API as api.branch.getByProjectId
    participant EE as EditorEngine

    U->>UI: Click "Delete branch"
    UI->>API: Query remaining branches for project
    API-->>UI: Remaining branches list
    alt ≤1 remaining
        UI-->>U: Error: cannot delete last/only branch
    else Active branch being deleted?
        alt Yes
            UI->>UI: Determine targetBranch (default or first)
            alt targetBranch exists
                UI->>EE: Switch to targetBranch
            else
                UI-->>U: Error: no valid target branch
            end
            UI->>API: Delete branch
            API-->>UI: Deletion success
            UI-->>U: Update UI (branch removed)
        else No
            UI->>API: Delete branch
            API-->>UI: Deletion success
            UI-->>U: Update UI (branch removed)
        end
    end

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I nibbled through branches, neat and clean,
Checked the burrow’s map with a database sheen.
If one twig left—halt! I thump and wait,
Pick a safe limb, then hop to create.
Snip goes the old, the new stands bright—
A tidy warren, just right tonight. 🐇🌿

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request description uses a "### Description" header instead of the template’s "## Description" and lacks a required Testing section, while also omitting placeholders for screenshots and additional notes. Please update the description to use the exact template headings (e.g., "## Description"), add a Testing section detailing steps or tests performed, and include any relevant screenshots or additional notes.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly and concisely describes the main change of fixing branch deletion in template copies by querying the database directly, which aligns with the implemented update in the changeset.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • [ ] 📝 Generate Docstrings
🧪 Generate unit tests
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

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.

coderabbitai[bot] avatar Oct 02 '25 04:10 coderabbitai[bot]