Repository navigation
fix(mobile): show checkout branch for phone-created threads #9475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Adamulek123
wants to merge
3
commits into
pingdotgg:main
from
Adamulek123:fix/mobile-thread-branch-fallback
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import { describe, expect, it } from "vite-plus/test"; | ||
|
|
||
| import { resolveThreadDisplayBranch } from "./thread-display-branch"; | ||
|
|
||
| describe("resolveThreadDisplayBranch", () => { | ||
| it("prefers the stored branch over the live checkout", () => { | ||
| expect( | ||
| resolveThreadDisplayBranch({ | ||
| branch: "feature/phone-thread", | ||
| worktreePath: null, | ||
| liveCheckoutBranch: "main", | ||
| }), | ||
| ).toBe("feature/phone-thread"); | ||
| }); | ||
|
|
||
| it("falls back to the live checkout for local threads with no stored branch", () => { | ||
| expect( | ||
| resolveThreadDisplayBranch({ | ||
| branch: null, | ||
| worktreePath: null, | ||
| liveCheckoutBranch: "main", | ||
| }), | ||
| ).toBe("main"); | ||
| }); | ||
|
|
||
| it("stays blank for local threads while the checkout is unknown", () => { | ||
| expect( | ||
| resolveThreadDisplayBranch({ | ||
| branch: null, | ||
| worktreePath: null, | ||
| liveCheckoutBranch: null, | ||
| }), | ||
| ).toBeNull(); | ||
| }); | ||
|
|
||
| it("never falls back for worktree threads", () => { | ||
| expect( | ||
| resolveThreadDisplayBranch({ | ||
| branch: null, | ||
| worktreePath: "/repo/.t3/worktrees/feature", | ||
| liveCheckoutBranch: "main", | ||
| }), | ||
| ).toBeNull(); | ||
| }); | ||
|
|
||
| it("treats blank strings as missing", () => { | ||
| expect( | ||
| resolveThreadDisplayBranch({ branch: " ", worktreePath: null, liveCheckoutBranch: "main" }), | ||
| ).toBe("main"); | ||
| expect( | ||
| resolveThreadDisplayBranch({ branch: null, worktreePath: null, liveCheckoutBranch: " " }), | ||
| ).toBeNull(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /** | ||
| * Branch shown on a thread list row. The stored `thread.branch` always wins: | ||
| * it is the ref the thread was created against and the value the PR badge | ||
| * compares. A local thread (`worktreePath == null`) with a null branch was | ||
| * created before the live checkout was known (status pending, detached HEAD, | ||
| * non-repo, or offline queue) — the server never backfills that null, so the | ||
| * row falls back to the live checkout, mirroring web's header | ||
| * (`resolveBranchToolbarValue`). Worktree threads never fall back: their cwd | ||
| * is isolated and its checkout may be a temporary `t3-*` placeholder. | ||
| */ | ||
| export function resolveThreadDisplayBranch(input: { | ||
| readonly branch: string | null; | ||
| readonly worktreePath: string | null; | ||
| readonly liveCheckoutBranch: string | null; | ||
| }): string | null { | ||
| const stored = input.branch?.trim(); | ||
| if (stored) { | ||
| return stored; | ||
| } | ||
| if (input.worktreePath !== null) { | ||
| return null; | ||
| } | ||
| const live = input.liveCheckoutBranch?.trim(); | ||
| return live ? live : null; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell"; | ||
|
|
||
| import { useEnvironmentQuery } from "./query"; | ||
| import { resolveThreadDisplayBranch } from "./thread-display-branch"; | ||
| import { vcsEnvironment } from "./vcs"; | ||
|
|
||
| /** | ||
| * Branch label for a thread list row. Stored `thread.branch` needs no fetch; | ||
| * the live status stream is only subscribed for local missing-branch threads, | ||
| * where it is the same deduplicated per-(environmentId, cwd) stream the PR | ||
| * badge and the new-task composer already share — so rows on one project | ||
| * root share one subscription, and virtualization keeps it to visible rows. | ||
| */ | ||
| export function useThreadDisplayBranch( | ||
| thread: EnvironmentThreadShell, | ||
| projectCwd: string | null, | ||
| ): string | null { | ||
| const cwd = thread.worktreePath ?? projectCwd; | ||
| const needsLiveBranch = !thread.branch?.trim() && thread.worktreePath === null && cwd !== null; | ||
| const liveStatus = useEnvironmentQuery( | ||
| needsLiveBranch | ||
| ? vcsEnvironment.status({ | ||
| environmentId: thread.environmentId, | ||
| input: { cwd }, | ||
| }) | ||
| : null, | ||
| ); | ||
| return resolveThreadDisplayBranch({ | ||
| branch: thread.branch, | ||
| worktreePath: thread.worktreePath, | ||
| liveCheckoutBranch: liveStatus.data?.refName ?? null, | ||
| }); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.