feat(project): add ability to clear selected project in NewThreadPage#1495
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdded a "clear project" control to NewThreadPage and propagated a new Changes
Sequence DiagramsequenceDiagram
participant User
participant NewThreadPage as NewThreadPage Component
participant ProjectStore as projectStore
participant IPC as IPC / Config Events
User->>NewThreadPage: Click "Clear Project"
NewThreadPage->>NewThreadPage: clearSelectedProject()
NewThreadPage->>ProjectStore: selectProject(null, 'manual')
ProjectStore->>ProjectStore: selectedProjectPath = null<br/>selectionSource = 'manual'
ProjectStore-->>NewThreadPage: state update (selectedProject=null, selectionSource='manual')
IPC->>ProjectStore: DEFAULT_PROJECT_PATH_CHANGED(newDefault)
ProjectStore-->>NewThreadPage: new defaultProjectPath (does not reselect due to manual clear)
NewThreadPage-->>User: UI shows "no project" / cleared state
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
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 docstrings
🧪 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 |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/renderer/src/pages/NewThreadPage.vue (1)
427-452:⚠️ Potential issue | 🟠 MajorExplicit "no project" selection gets clobbered by
applyDraftDefaultsForSelectedAgent.This function is invoked by the
selectedAgentwatcher withimmediate: true, so it runs on mount and on any agent change. When the user has explicitly cleared the project (selectionSource === 'manual',selectedProjectPath === null), both branches below will re-select the global default:
- Line 429-431 (ACP branch):
if (!currentProjectPath && globalDefaultProjectPath) { projectStore.selectProject(globalDefaultProjectPath, 'default') }- Line 450-452 (DeepChat branch): same pattern.
Net effect: the "clear project" action is not durable across agent switches (and potentially across remounts of
NewThreadPage), which contradicts the PR's intent. The newly added store test only covers the IPCDEFAULT_PROJECT_PATH_CHANGEDpath, not this code path.Consider respecting an explicit manual-none selection here, e.g.:
Proposed guard
- if (selectedAgent.value.type === 'acp') { - const resolvedProjectPath = currentProjectPath ?? globalDefaultProjectPath - if (!currentProjectPath && globalDefaultProjectPath) { - projectStore.selectProject(globalDefaultProjectPath, 'default') - } + const hasExplicitNone = + projectStore.selectionSource === 'manual' && !currentProjectPath + if (selectedAgent.value.type === 'acp') { + const resolvedProjectPath = currentProjectPath ?? globalDefaultProjectPath + if (!currentProjectPath && globalDefaultProjectPath && !hasExplicitNone) { + projectStore.selectProject(globalDefaultProjectPath, 'default') + } ... } ... - } else if (!currentProjectPath && globalDefaultProjectPath) { + } else if (!currentProjectPath && globalDefaultProjectPath && !hasExplicitNone) { projectStore.selectProject(globalDefaultProjectPath, 'default') }Adding a test around agent-switch behavior after
selectProject(null, 'manual')would also lock this in.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/renderer/src/pages/NewThreadPage.vue` around lines 427 - 452, The auto-selection of the global default project in applyDraftDefaultsForSelectedAgent (run by the selectedAgent watcher) clobbers an explicit "no project" choice; add a guard that checks the project's selectionSource and selectedProjectPath (e.g., if selectionSource === 'manual' && selectedProjectPath === null) and skip calling projectStore.selectProject and avoid setting draftStore.projectDir when that explicit manual-none selection is present; apply this guard in both the ACP branch (the block setting providerId 'acp') and the DeepChat branch before the existing projectStore.selectProject calls so manual-cleared project selection is preserved across agent changes.
🧹 Nitpick comments (2)
src/renderer/src/pages/NewThreadPage.vue (1)
181-190: Minor: computed relies onselectedProject(projects array lookup) rather thanselectedProjectPath.
hasExplicitNoProjectSelectionandcanClearProjectSelectionboth read from the computedselectedProject, which resolves toundefinedwhenever the path isn't present inprojects.value. In practicereconcileProjectsinjects a synthetic entry for manual selections, so this is fine today — but it couples these flags to reconciliation timing. UsingprojectStore.selectedProjectPathdirectly would be more robust:Suggestion
-const hasExplicitNoProjectSelection = computed( - () => projectStore.selectionSource === 'manual' && !projectStore.selectedProject?.path?.trim() -) +const hasExplicitNoProjectSelection = computed( + () => projectStore.selectionSource === 'manual' && !projectStore.selectedProjectPath?.trim() +) ... -const canClearProjectSelection = computed(() => Boolean(projectStore.selectedProject?.path?.trim())) +const canClearProjectSelection = computed(() => + Boolean(projectStore.selectedProjectPath?.trim()) +)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/renderer/src/pages/NewThreadPage.vue` around lines 181 - 190, The computed flags couple to projectStore.selectedProject (which can be undefined) instead of the raw path; change hasExplicitNoProjectSelection to check projectStore.selectedProjectPath (e.g., projectStore.selectionSource === 'manual' && !projectStore.selectedProjectPath?.trim()) and change canClearProjectSelection to Boolean(projectStore.selectedProjectPath?.trim()). Keep selectedProjectName logic the same (use projectStore.selectedProject?.name when present, otherwise fall back to hasExplicitNoProjectSelection ? t('common.project.none') : t('common.project.select')) so name resolution still prefers the reconciled object but the boolean flags rely on the stable selectedProjectPath.src/renderer/src/stores/ui/project.ts (1)
151-158: Logic inselectProjectis correct but a bit cryptic.
selectedProjectPath.value || source === 'manual' ? source : 'none'relies on||/?:precedence. It's correct, but readability would benefit from parentheses or an explicit conditional.Optional clarification
- selectionSource.value = selectedProjectPath.value || source === 'manual' ? source : 'none' + const keepSource = selectedProjectPath.value !== null || source === 'manual' + selectionSource.value = keepSource ? source : 'none'🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/renderer/src/stores/ui/project.ts` around lines 151 - 158, The conditional assignment to selectionSource.value in selectProject is correct but hard to read due to operator precedence; change it to an explicit, parenthesized or ternary expression to make intent clear — e.g., compute a boolean like const hasSelected = !!selectedProjectPath.value and then set selectionSource.value = hasSelected || source === 'manual' ? source : 'none' (or use an if/else) after calling selectedProjectPath.value = normalizePath(path); keep the calls to normalizePath(path), reconcileProjects(projects.value) and updates to projects.value intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@src/renderer/src/pages/NewThreadPage.vue`:
- Around line 427-452: The auto-selection of the global default project in
applyDraftDefaultsForSelectedAgent (run by the selectedAgent watcher) clobbers
an explicit "no project" choice; add a guard that checks the project's
selectionSource and selectedProjectPath (e.g., if selectionSource === 'manual'
&& selectedProjectPath === null) and skip calling projectStore.selectProject and
avoid setting draftStore.projectDir when that explicit manual-none selection is
present; apply this guard in both the ACP branch (the block setting providerId
'acp') and the DeepChat branch before the existing projectStore.selectProject
calls so manual-cleared project selection is preserved across agent changes.
---
Nitpick comments:
In `@src/renderer/src/pages/NewThreadPage.vue`:
- Around line 181-190: The computed flags couple to projectStore.selectedProject
(which can be undefined) instead of the raw path; change
hasExplicitNoProjectSelection to check projectStore.selectedProjectPath (e.g.,
projectStore.selectionSource === 'manual' &&
!projectStore.selectedProjectPath?.trim()) and change canClearProjectSelection
to Boolean(projectStore.selectedProjectPath?.trim()). Keep selectedProjectName
logic the same (use projectStore.selectedProject?.name when present, otherwise
fall back to hasExplicitNoProjectSelection ? t('common.project.none') :
t('common.project.select')) so name resolution still prefers the reconciled
object but the boolean flags rely on the stable selectedProjectPath.
In `@src/renderer/src/stores/ui/project.ts`:
- Around line 151-158: The conditional assignment to selectionSource.value in
selectProject is correct but hard to read due to operator precedence; change it
to an explicit, parenthesized or ternary expression to make intent clear — e.g.,
compute a boolean like const hasSelected = !!selectedProjectPath.value and then
set selectionSource.value = hasSelected || source === 'manual' ? source : 'none'
(or use an if/else) after calling selectedProjectPath.value =
normalizePath(path); keep the calls to normalizePath(path),
reconcileProjects(projects.value) and updates to projects.value intact.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: bd7f6854-8a76-4060-8855-dafc44c8e75c
📒 Files selected for processing (4)
src/renderer/src/pages/NewThreadPage.vuesrc/renderer/src/stores/ui/project.tstest/renderer/pages/NewThreadPage.test.tstest/renderer/stores/projectStore.test.ts
Summary by CodeRabbit
New Features
Improvements
Bug Fixes / Reliability
Tests