fix(welcome): show new database groups without restart (#1704)#1709
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e78a16211a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let group = ConnectionGroup(name: name, color: color, parentId: parentId) | ||
| groupStorage.addGroup(group) | ||
| groups = groupStorage.loadGroups() | ||
| guard groups.contains(where: { $0.id == group.id }) else { return } |
There was a problem hiding this comment.
Clear pending move when group creation fails
When this is reached from Move to Group > New Group..., pendingMoveToNewGroup is already populated. If addGroup rejects the new group (for example a duplicate sibling name), this early return leaves that pending list set while the sheet still dismisses; the next unrelated successful group creation will hit the later pendingMoveToNewGroup block and move the old connections into that new group unexpectedly. Clear the pending move on the failure path or only retain it while the sheet remains active.
Useful? React with 👍 / 👎.
Fixes #1704.
Problem
Creating a new database group did not show it in the connection list until a full app restart.
Root cause
The welcome list renders
WelcomeViewModel.treeItems, which is built only byrebuildTree(). The.newGroupsheet completion persisted the group and setvm.groups, but never calledrebuildTree(). Since the view model is@Observable, only views that read a property that was written get invalidated, andtreeItemswas never rewritten, so the list stayed stale untilloadGroups()ran at the next launch. This is the documented "WelcomeViewModel tree rebuild" invariant, violated for thegroupsside.The one path that worked was Move to Group > New Group..., because it called
moveConnections, which happens to rebuild.Fix
WelcomeViewModel.createGroup(name:color:parentId:), mirroring the other group mutators (confirmRenameGroup,updateGroupColor,moveGroup) that all end inrebuildTree(). The reload-and-guard also stops the group from being expanded or moved into whenaddGroupsilently rejects it (duplicate name, depth cap, cycle).WelcomeWindowViewnow callsvm.createGroup(...)instead of reaching intoGroupStorage.sharedand mutatingvm.groupsfrom the view body, which is what let it drift out of step in the first place.Tests
New
WelcomeViewModelTestswith isolated storage:treeItemsimmediately (the regression)Notes
swiftlint lint --strictclean on the changed files.ConnectionGroupPickercopy ofCreateGroupSheet(connection form) is unaffected: it reloads its own list locally.