Skip to content

fix(task-input): prefill repo dropdown when starting task from sidebar "+" icon#2712

Open
mp-hog wants to merge 4 commits into
mainfrom
posthog-code/prefill-newtask-repo-sidebar-plus-review-fixes
Open

fix(task-input): prefill repo dropdown when starting task from sidebar "+" icon#2712
mp-hog wants to merge 4 commits into
mainfrom
posthog-code/prefill-newtask-repo-sidebar-plus-review-fixes

Conversation

@mp-hog

@mp-hog mp-hog commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Problem

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:

new-task-repo-dropdown

Fix

Make folderId drive both selectors. A registered folder already carries both path (local) and remoteUrl (the resolved owner/repo slug), so it's a single source of truth.

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 current workspace mode when it can represent the repo, and only switch (Cloud → last-used local mode) when it can't (a local-only repo while in Cloud). The switch uses the non-persisting setter, so it doesn't overwrite the user's mode preference.

Behavior

You're in Click "+" on… Result
Cloud cloud-capable repo dropdown follows the repo; stay in Cloud
Local dual-capable repo directory prefilled; stay in Local (cloud repo also seeded)
Cloud local-only repo switch to Local; directory prefilled
generic New task button unchanged — falls to last-used defaults

Testing

  • Unit tests for the pure resolver, areReposReady, and the hook cover every branch incl. the loading-gate and once-per-folderId guard.
  • @posthog/ui typecheck + biome clean; task-detail suite green (22/22); full @posthog/ui suite green (752/752).
  • Manually with local app, + icon switches to respective repo

Known limits (out of scope)

  • A cloud-only group with no registered local folder falls back to defaults (no folderId/remoteUrl to key off).
  • In Cloud mode, "+" on a repo whose org is not a connected GitHub integration intentionally switches to Local (per the "switch only when the mode can't represent the repo" rule).

mp-hog added 2 commits June 16, 2026 15:19
…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
@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit 23d7727.

@greptile-apps

greptile-apps Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor
Prompt To Fix All With AI
Fix 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

@mp-hog mp-hog marked this pull request as ready for review June 17, 2026 09:36
@mp-hog mp-hog changed the title fix(task-input): prefill repo from sidebar "+" in both local and cloud modes fix(task-input): prefill repo dropdown when starting task from sidebar "+" icon Jun 17, 2026
@mp-hog mp-hog requested a review from a team June 17, 2026 09:39
@greptile-apps

greptile-apps Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Reviews (2): Last reviewed commit: "Merge branch 'main' into posthog-code/pr..." | Re-trigger Greptile

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.

1 participant