fix(desktop): reset to branch name when workspace rename is cleared#1172
Conversation
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.
|
Caution Review failedThe pull request is closed. 📝 WalkthroughWalkthroughWorkspace rename flow becomes branch-aware: the update procedure accepts an optional Changes
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
…empty" This reverts commit eb2eb51.
There was a problem hiding this comment.
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.
| 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); |
There was a problem hiding this comment.
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
e1f1299 to
b2e2db4
Compare
🧹 Preview Cleanup CompleteThe following preview resources have been cleaned up:
Thank you for your contribution! 🎉 |
Summary
isUnnamed=trueso the auto-rename feature can still prompt for a nameisUnnamedfield to workspace update patch schema for explicit controlTest plan
Summary by CodeRabbit
New Features
Bug Fixes