fix(task-input): prefill repo dropdown when starting task from sidebar "+" icon#2712
Conversation
|
React Doctor found no issues in the changed files. 🎉 Reviewed by React Doctor for commit |
Prompt To Fix All With AIFix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
packages/ui/src/features/task-detail/hooks/useInitialRepoSelectionFromFolderId.test.ts:241-267
**Missing "waits for folders to load" test case**
The deleted `useInitialDirectoryFromFolderId.test.ts` explicitly tested the scenario where `folders` starts empty and the target folder arrives in a later render. That case is absent from the new test file. The hook bails early when `folders.find()` returns `undefined` and intentionally leaves `dirInitRef.current` unset so the effect retries once `folders` loads — but without a test for this path, a future regression (e.g., accidentally setting `dirInitRef.current` before finding the folder) would go unnoticed.
### Issue 2 of 2
packages/ui/src/features/task-detail/hooks/useInitialRepoSelectionFromFolderId.ts:22-29
**`areReposReady` permanently returns `false` when integration exists but repos are empty**
When `hasGithubIntegration = true` and `repositoriesCount = 0` is not a transient gap (e.g., a user installed the GitHub App then revoked access to every repository), `areReposReady` never returns `true`. As a result `reposLoaded` stays `false` in the hook, `repoModeInitRef.current` is never set, and clicking "+" on a local-only folder while in Cloud mode silently leaves the user in Cloud mode. The directory prefill still fires, so the failure is partial rather than total — but the mode switch the fix promises never happens for this cohort.
Reviews (1): Last reviewed commit: "fix(task-input): distinguish settled-emp..." | Re-trigger Greptile |
|
Reviews (2): Last reviewed commit: "Merge branch 'main' into posthog-code/pr..." | Re-trigger Greptile |
23d7727 to
f883819
Compare
|
Hey @mp-hog, how should this work if I am working on a local task, I click "+"? I would expect this to pre-fill the repo on local, but right now it does not and always tries to find the cloud repo. |
Thanks for your feedback @charlesvien ! Before this PR the open mode is the global last-used setting (which does not distinguish between repo). The logic for this PR the same logic, but it adds a fallback to Local if the mode is not applicable under the given repo (it wouldn't switch to Cloud). You are right though that it might still be surprising, as we don't distinguish this setting between repos, but the PR as is improves the Repo-Selection and is not making the Mode selection worse. I have locally started working on infering the Mode from the task history of a repo, but it touches a bunch of files and I think goes beyond the scope of this PR. That I believe would solve the surprising bit of the current logic. I would suggest: Ship as is and improve the Mode-selection in a follow-up. What do you think? Edit: Follow-up: #2939 |
…d modes The TASKS sidebar "+" button (and the command menu's "new task in folder") passes a `folderId` to the new-task screen, but `folderId` only ever prefilled the local directory selector — never the cloud repo dropdown. In Cloud mode the prefill was invisible, so clicking "+" on a repo left the cloud dropdown on the last-used (wrong) repo, and tasks could be started against the wrong repo. Make `folderId` drive both selectors. A registered folder already carries both `path` (local) and `remoteUrl` (the resolved `owner/repo` slug), so it is a single source of truth for the local directory and the cloud repo. New `useInitialRepoSelectionFromFolderId` hook + pure `resolveRepoSelectionForFolder` resolver: - always prefill the local directory from the folder path; - prefill the cloud repo when the folder's remote is a real `owner/repo` that is a connected GitHub integration; - keep the user's current workspace mode when it can represent the repo, and only switch (Cloud -> last-used local mode) when it can't (local-only repo while in Cloud). The mode switch uses the non-persisting setter so it does not overwrite the user's mode preference. The cloud/mode decision is gated on the integrations list having loaded, and runs once per `folderId` so it never clobbers a manual change. Replaces the directory-only `useInitialDirectoryFromFolderId` (removed). Call sites are unchanged, so every folder-scoped new-task entry point benefits. Known limits (out of scope): a cloud-only group with no registered local folder falls back to defaults; in Cloud mode, "+" on a repo whose org is not a connected integration intentionally switches to Local. Generated-By: PostHog Code Task-Id: 50f73c6f-d922-4d90-b547-a450102c770c
…ill guard
Address PR review feedback on the sidebar "+" repo prefill.
P1 (corrected): the cloud/mode readiness guard previously required
`repositories.length > 0`, which never becomes true for users in cloud
mode with zero connected GitHub integrations — so clicking "+" on a
local-only folder silently did nothing for them. The reviewer's proposed
fix (`!isLoadingRepos` alone) reintroduces the transient-empty race the
length check guarded against (the window where loading has cleared but
per-installation repo queries haven't populated yet), wrongly switching
users with integrations to Local on the common path. Instead, extract a
pure `areReposReady({ isLoadingRepos, repositoriesCount,
hasGithubIntegration })` helper: ready when not loading AND
(repos present OR no GitHub integration). Fixes the no-integration cohort
while preserving the transient-window guard for the common path.
P2: fold the resolver cases into an `it.each` table (per CLAUDE.md test
guidance), add the settled-empty `repositories` row, and add a
parameterised `areReposReady` table covering the transient-window and
no-integration cases.
Generated-By: PostHog Code
Task-Id: 50f73c6f-d922-4d90-b547-a450102c770c
f883819 to
84b17ef
Compare
Problem
Closes #1454
In the Tasks sidebar each repo group header has a hover "+" button to start a new task. Clicking it did not scope the new-task screen with that repo in cloud-mode, so that tasks were started under wrong repo.
It's this relation:
Fix
Make
folderIddrive both selectors. A registered folder already carries bothpath(local) andremoteUrl(the resolvedowner/reposlug), so it's a single source of truth.New
useInitialRepoSelectionFromFolderIdhook + pureresolveRepoSelectionForFolderresolver:owner/repothat is a connected GitHub integrationBehavior
Testing
areReposReady, and the hook cover every branch incl. the loading-gate and once-per-folderIdguard.@posthog/uitypecheck + biome clean; task-detail suite green (22/22); full@posthog/uisuite green (752/752).Known limits (out of scope)
folderId/remoteUrlto key off).