Skip to content

fix(desktop): reset to branch name when workspace rename is cleared#1172

Merged
Kitenite merged 3 commits into
mainfrom
kitenite/replace
Feb 3, 2026
Merged

fix(desktop): reset to branch name when workspace rename is cleared#1172
Kitenite merged 3 commits into
mainfrom
kitenite/replace

Conversation

@Kitenite
Copy link
Copy Markdown
Collaborator

@Kitenite Kitenite commented Feb 3, 2026

Summary

  • When users clear the workspace name during rename (trim to empty), now resets to branch name instead of keeping empty
  • Sets isUnnamed=true so the auto-rename feature can still prompt for a name
  • Added isUnnamed field to workspace update patch schema for explicit control

Test plan

  • Open a workspace and double-click to rename it
  • Clear the name field completely and press Enter
  • Verify the workspace name resets to the branch name
  • Verify the workspace is marked as unnamed (auto-rename prompt should appear)

Summary by CodeRabbit

  • New Features

    • Workspace rename is branch-aware: the rename flow now uses the workspace branch; clearing the rename field reverts the name to the branch and marks the workspace as unnamed.
  • Bug Fixes

    • Unnamed-status handling during renames is clarified with explicit precedence rules, removing prior implicit resets when names change.

When users provide an empty string as a custom workspace name, use the
branch name as fallback and keep isUnnamed set to true. Changed from
nullish coalescing (??) to logical OR (||) so empty strings trigger
the fallback behavior.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 3, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

Workspace rename flow becomes branch-aware: the update procedure accepts an optional isUnnamed in the patch and applies explicit precedence logic. The useWorkspaceRename hook gains a branch parameter and treats empty rename inputs as a revert to the branch name with isUnnamed: true. Call sites were updated to pass the branch.

Changes

Cohort / File(s) Summary
Backend API Schema
apps/desktop/src/lib/trpc/routers/workspaces/procedures/status.ts
Added optional isUnnamed to the patch input schema and changed patch-application precedence: apply patch.isUnnamed if present; else, if name changed and preserveUnnamedStatus is false, set isUnnamed false; otherwise leave isUnnamed unchanged.
Hook Implementation
apps/desktop/src/renderer/screens/main/hooks/useWorkspaceRename/useWorkspaceRename.ts
Hook signature extended with branch: string. Submit logic updated: empty trimmed input submits name = branch and isUnnamed = true and syncs local rename state; non-empty different names submit a name change; unchanged input resets local state.
Hook Call Sites
apps/desktop/src/renderer/routes/_authenticated/settings/workspace/$workspaceId/page.tsx, apps/desktop/src/renderer/screens/main/components/WorkspaceSidebar/WorkspaceListItem/WorkspaceListItem.tsx
Updated useWorkspaceRename invocations to pass workspace?.branch ?? "" (third branch argument).

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant UI as Client UI
  participant Hook as useWorkspaceRename
  participant TRPC as TRPC Server
  participant DB as Database

  rect rgba(200,230,255,0.5)
  UI->>Hook: user submits new name (trimmedValue)
  end

  alt trimmedValue is empty
    Hook->>TRPC: update(workspaceId, patch: { name: branch, isUnnamed: true })
  else trimmedValue != workspaceName
    Hook->>TRPC: update(workspaceId, patch: { name: trimmedValue })
  else trimmedValue == workspaceName
    Hook-->>UI: reset local renameValue to workspaceName
  end

  TRPC->>DB: apply patch (respect patch.isUnnamed precedence)
  DB-->>TRPC: updated workspace
  TRPC-->>Hook: update result
  Hook-->>UI: reflect new name / state
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐇 I nudged a name back to its branch with glee,
An empty field whispers, "be unnamed, be free."
Patch carries a flag, explicit and bright,
Branch cradles the name through day and night.
Hooray — a tiny rabbit cheers the rename flight!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
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.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main behavior change: resetting workspace name to branch name when rename is cleared, which aligns with the primary objective of the changeset.
Description check ✅ Passed The description covers the main change, test plan, and mentions the schema modification, but lacks some required template sections like Related Issues and Type of Change.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch kitenite/replace

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.

@Kitenite Kitenite changed the title fix(desktop): fallback to branch name when workspace name is empty fix(desktop): reset to branch name when workspace rename is cleared Feb 3, 2026
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: 1

🤖 Fix all issues with AI agents
In
`@apps/desktop/src/renderer/screens/main/hooks/useWorkspaceRename/useWorkspaceRename.ts`:
- Around line 32-38: When trimmedValue is empty the current fallback uses branch
which can also be empty; update the empty-name branch in the useWorkspaceRename
logic to guard against an empty branch by computing a defaultName (e.g., const
defaultName = branch || 'Untitled Workspace') and use that for
updateWorkspace.mutate({ id: workspaceId, patch: { name: defaultName, isUnnamed:
true }}) and setRenameValue(defaultName) so the workspace never gets an empty
string name.
🧹 Nitpick comments (1)
apps/desktop/src/renderer/screens/main/hooks/useWorkspaceRename/useWorkspaceRename.ts (1)

4-8: Consider using a params object for better readability.

The function now accepts 3 positional parameters. Per coding guidelines, functions with 2+ parameters should accept a single params object with named properties.

♻️ Suggested refactor
-export function useWorkspaceRename(
-	workspaceId: string,
-	workspaceName: string,
-	branch: string,
-) {
+export function useWorkspaceRename(params: {
+	workspaceId: string;
+	workspaceName: string;
+	branch: string;
+}) {
+	const { workspaceId, workspaceName, branch } = params;

Note: This is optional since hooks commonly use positional parameters for ergonomic reasons.

Comment on lines +32 to +38
if (!trimmedValue) {
// Empty name: revert to branch name and mark as unnamed for auto-rename
updateWorkspace.mutate({
id: workspaceId,
patch: { name: branch, isUnnamed: true },
});
setRenameValue(branch);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Consider edge case when branch is also empty.

If branch is an empty string (e.g., workspace without a branch), the fallback would set the name to an empty string, which may not be the intended behavior. Consider adding a safeguard or using a default placeholder.

🛡️ Proposed defensive fix
 	const submitRename = () => {
 		const trimmedValue = renameValue.trim();
 		if (!trimmedValue) {
+			const fallbackName = branch || "Unnamed Workspace";
 			// Empty name: revert to branch name and mark as unnamed for auto-rename
 			updateWorkspace.mutate({
 				id: workspaceId,
-				patch: { name: branch, isUnnamed: true },
+				patch: { name: fallbackName, isUnnamed: true },
 			});
-			setRenameValue(branch);
+			setRenameValue(fallbackName);
 		} else if (trimmedValue !== workspaceName) {
🤖 Prompt for AI Agents
In
`@apps/desktop/src/renderer/screens/main/hooks/useWorkspaceRename/useWorkspaceRename.ts`
around lines 32 - 38, When trimmedValue is empty the current fallback uses
branch which can also be empty; update the empty-name branch in the
useWorkspaceRename logic to guard against an empty branch by computing a
defaultName (e.g., const defaultName = branch || 'Untitled Workspace') and use
that for updateWorkspace.mutate({ id: workspaceId, patch: { name: defaultName,
isUnnamed: true }}) and setRenameValue(defaultName) so the workspace never gets
an empty string name.

When users clear the workspace name (trim to empty), revert to the branch
name and set isUnnamed=true so the auto-rename feature can still work.

Changes:
- Add isUnnamed field to workspace update patch schema
- Update useWorkspaceRename hook to accept branch parameter
- Handle empty name by setting name to branch and isUnnamed=true
@Kitenite Kitenite merged commit 3d05277 into main Feb 3, 2026
1 check was pending
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 3, 2026

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

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

Thank you for your contribution! 🎉

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