Skip to content

feat(project): add ability to clear selected project in NewThreadPage#1495

Merged
zerob13 merged 2 commits into
devfrom
clear-space
Apr 20, 2026
Merged

feat(project): add ability to clear selected project in NewThreadPage#1495
zerob13 merged 2 commits into
devfrom
clear-space

Conversation

@zhangmo8

@zhangmo8 zhangmo8 commented Apr 20, 2026

Copy link
Copy Markdown
Collaborator
image

Summary by CodeRabbit

  • New Features

    • Added a "clear project" option in the project dropdown to manually remove the selected project.
  • Improvements

    • Refined project selection behavior so manual clears persist and default projects are not re-applied unintentionally.
    • Dropdown UI now more clearly indicates explicit "no project" vs. "select project" states.
  • Bug Fixes / Reliability

    • More robust handling of content-type when caching remote images.
  • Tests

    • Added/updated tests to cover manual clear behavior and dropdown interactions.

@coderabbitai

coderabbitai Bot commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4c940891-d36f-4bec-96ff-426d4ffe9ecb

📥 Commits

Reviewing files that changed from the base of the PR and between 36b7fad and 457a2f7.

📒 Files selected for processing (1)
  • src/main/presenter/devicePresenter/index.ts

📝 Walkthrough

Walkthrough

Added a "clear project" control to NewThreadPage and propagated a new selectionSource state in the project store so manual "no project" selections are preserved and exposed to the UI.

Changes

Cohort / File(s) Summary
Project Selection UI
src/renderer/src/pages/NewThreadPage.vue
Added "clear project" DropdownMenuItem and trigger testids; replaced selectedProjectName logic with hasExplicitNoProjectSelection and canClearProjectSelection; added clearSelectedProject() and adjusted dropdown separators.
Project Store
src/renderer/src/stores/ui/project.ts
Changed selectProject(path, source) logic to preserve 'manual' when explicitly passed even for null/empty path; exposed selectionSource in the store's public API.
Component Tests
test/renderer/pages/NewThreadPage.test.ts
Updated mock projectStore to allow nullable selectedProject and include selectionSource; replaced selectProject mock with functional implementation; adjusted stubs; added test verifying clear-project click calls selectProject(null, 'manual') and updates UI.
Store Unit Tests
test/renderer/stores/projectStore.test.ts
Added test ensuring selectProject(null, 'manual') keeps selection cleared even when default project path changes via IPC (CONFIG_EVENTS.DEFAULT_PROJECT_PATH_CHANGED).
Presenter - Image Caching
src/main/presenter/devicePresenter/index.ts
Normalized content-type header handling by reading rawContentType, joining array values when present, and deriving contentType before extension checks to avoid incorrect type assumptions.

Sequence Diagram

sequenceDiagram
    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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • zerob13

Poem

🐇 A little hop, a gentle clear,
I nudged the menu, the choice drew near.
Manual paths whispered "none" with cheer,
Projects unfurled, then disappeared,
A rabbit's tap — the view is clear.

🚥 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main feature addition: enabling users to clear their selected project in NewThreadPage, which aligns with the primary changes across all modified files.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch clear-space

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 coderabbitai Bot left a comment

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.

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 | 🟠 Major

Explicit "no project" selection gets clobbered by applyDraftDefaultsForSelectedAgent.

This function is invoked by the selectedAgent watcher with immediate: 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 IPC DEFAULT_PROJECT_PATH_CHANGED path, 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 on selectedProject (projects array lookup) rather than selectedProjectPath.

hasExplicitNoProjectSelection and canClearProjectSelection both read from the computed selectedProject, which resolves to undefined whenever the path isn't present in projects.value. In practice reconcileProjects injects a synthetic entry for manual selections, so this is fine today — but it couples these flags to reconciliation timing. Using projectStore.selectedProjectPath directly 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 in selectProject is 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

📥 Commits

Reviewing files that changed from the base of the PR and between e4cc488 and 36b7fad.

📒 Files selected for processing (4)
  • src/renderer/src/pages/NewThreadPage.vue
  • src/renderer/src/stores/ui/project.ts
  • test/renderer/pages/NewThreadPage.test.ts
  • test/renderer/stores/projectStore.test.ts

@zerob13 zerob13 merged commit 0824dc0 into dev Apr 20, 2026
3 checks passed
@zhangmo8 zhangmo8 deleted the clear-space branch April 21, 2026 03:49
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.

2 participants