Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion apps/web/src/components/BranchToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ import {
} from "react";
import { flushSync } from "react-dom";

import { useComposerDraftStore, type DraftId } from "../composerDraftStore";
import {
useComposerDraftStore,
type ComposerThreadTarget,
type DraftId,
} from "../composerDraftStore";
import { EnvironmentMachineIcon } from "./EnvironmentMachineIcon";
import { useProject, useThreadShellsForProjectRefs } from "../state/entities";
import {
Expand Down Expand Up @@ -86,6 +90,7 @@ interface BranchToolbarProps {
isServerThread: boolean;
showGitControls: boolean;
draftId?: DraftId;
composerDraftTarget?: ComposerThreadTarget | null | undefined;
onEnvModeChange: (mode: EnvMode) => void;
envMode: EnvMode;
activeThreadBranchOverride?: string | null;
Expand Down Expand Up @@ -596,6 +601,7 @@ export const BranchToolbar = memo(function BranchToolbar({
isServerThread,
showGitControls,
draftId,
composerDraftTarget,
onEnvModeChange,
envMode,
activeThreadBranchOverride,
Expand Down Expand Up @@ -714,6 +720,7 @@ export const BranchToolbar = memo(function BranchToolbar({
environmentId={environmentId}
threadId={threadId}
{...(draftId ? { draftId } : {})}
composerDraftTarget={composerDraftTarget}
envLocked={envLocked}
effectiveEnvModeOverride={effectiveEnvMode}
{...(activeThreadBranchOverride !== undefined ? { activeThreadBranchOverride } : {})}
Expand Down
9 changes: 8 additions & 1 deletion apps/web/src/components/BranchToolbarBranchSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ import {
type Ref,
} from "react";

import { useComposerDraftStore, type DraftId } from "../composerDraftStore";
import {
useComposerDraftStore,
type ComposerThreadTarget,
type DraftId,
} from "../composerDraftStore";
import { writeTextToClipboard } from "../hooks/useCopyToClipboard";
import { readLocalApi } from "../localApi";
import { useOpenPrLink } from "../lib/openPullRequestLink";
Expand Down Expand Up @@ -85,6 +89,7 @@ interface BranchToolbarBranchSelectorProps {
environmentId: EnvironmentId;
threadId: ThreadId;
draftId?: DraftId;
composerDraftTarget?: ComposerThreadTarget | null | undefined;
envLocked: boolean;
effectiveEnvModeOverride?: "local" | "worktree";
activeThreadBranchOverride?: string | null;
Expand All @@ -109,6 +114,7 @@ export function BranchToolbarBranchSelector({
environmentId,
threadId,
draftId,
composerDraftTarget,
envLocked,
effectiveEnvModeOverride,
activeThreadBranchOverride,
Expand Down Expand Up @@ -882,6 +888,7 @@ export function BranchToolbarBranchSelector({
branchPr={branchPr}
branchSourceControlProvider={branchStatusQuery.data?.sourceControlProvider}
onActed={() => branchStatusQuery.refresh()}
composerTarget={composerDraftTarget}
/>
) : null}
</div>
Expand Down
9 changes: 8 additions & 1 deletion apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3897,7 +3897,14 @@ export default function ChatView(props: ChatViewProps) {
worktreePath={activeThread.worktreePath}
isServerThread={isServerThread}
{...(draftId ? { draftId } : {})}
composerDraftTarget={composerDraftTarget}
// Without a composer, handoffs fall back to opening a new thread.
composerDraftTarget={
!composerMounted
? undefined
: queuedRunEdit.isEditing
? null
: composerDraftTarget
}
activeProjectName={activeProject?.title}
activeProjectScripts={activeProject ? activeProjectScripts : undefined}
preferredScriptId={
Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/components/chat/ThreadDetailsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ interface ThreadDetailsPanelProps extends Pick<
worktreePath: string | null;
isServerThread: boolean;
draftId?: DraftId;
composerDraftTarget: ComposerThreadTarget;
composerDraftTarget: ComposerThreadTarget | null | undefined;
activeProjectName: string | undefined;
activeProjectScripts: ReadonlyArray<ProjectScript> | undefined;
preferredScriptId: string | null;
Expand Down Expand Up @@ -118,6 +118,7 @@ export function ThreadDetailsPanel(props: ThreadDetailsPanelProps) {
worktreePath: props.worktreePath,
isServerThread: props.isServerThread,
...(props.draftId ? { draftId: props.draftId } : {}),
composerDraftTarget: props.composerDraftTarget,
onEnvModeChange: props.onEnvModeChange,
startFromOrigin: props.startFromOrigin,
onStartFromOriginChange: props.onStartFromOriginChange,
Expand Down
61 changes: 59 additions & 2 deletions apps/web/src/components/chat/ThreadDetailsPrRow.browser.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { expect, it, vi } from "vite-plus/test";
const state = vi.hoisted(() => ({
status: "success" as PullRequestCheck["status"],
extraStatus: null as PullRequestCheck["status"] | null,
mergeability: "mergeable" as "mergeable" | "conflicting",
mergeMethods: ["merge"] as Array<"merge" | "squash" | "rebase">,
perform: vi.fn(),
newThread: vi.fn(),
Expand Down Expand Up @@ -47,7 +48,7 @@ const queryData = () => ({
title: "Test PR",
state: "open",
isDraft: false,
mergeability: "mergeable",
mergeability: state.mergeability,
headBranch: "feature",
baseBranch: "main",
changedFiles: 1,
Expand Down Expand Up @@ -232,6 +233,32 @@ it("requires a new merge click after passing checks become pending and pass agai
expect(state.perform).not.toHaveBeenCalled();
});

it("blocks Fix while a queued message is being edited", async () => {
await using screen = await setup();
state.status = "failure";
await act(async () => {
await screen.rerender(
<ThreadDetailsPrRow
environmentId={EnvironmentId.make("environment")}
pr={null}
number={1}
status={null}
project={null}
label="Test PR"
openAriaLabel="Open PR"
onOpen={vi.fn()}
composerTarget={null}
/>,
);
});
const blockedFix = [...screen.container.querySelectorAll("button")].find(
(button) => button.textContent?.trim() === "Fix",
)!;
expect(blockedFix.getAttribute("aria-disabled")).toBe("true");
await act(async () => blockedFix.click());
expect(state.newThread).not.toHaveBeenCalled();
});

async function setup() {
state.perform.mockReset();
state.checkoutError = null;
Expand All @@ -245,6 +272,7 @@ async function setup() {

state.status = "success";
state.extraStatus = null;
state.mergeability = "mergeable";
state.mergeMethods = ["merge"];
state.projects = [];
state.pullRequests = [];
Expand Down Expand Up @@ -275,9 +303,38 @@ it("adds the failing checks to a given composer instead of opening a new thread"
await clickButton(screen.container, "Fix");
expect(state.newThread).not.toHaveBeenCalled();
expect(state.prepareThread).not.toHaveBeenCalled();
const fixDraft = useComposerDraftStore.getState().getComposerDraft(threadRef);
expect(fixDraft?.prompt).toContain("Fix the actionable findings attached");
expect(fixDraft?.prompt).not.toContain("> CI-failure");
expect(fixDraft?.prompt).toContain(
"Verify the checkout matches this branch before making changes, switch to it if it does not",
);
expect(fixDraft?.reviewComments.map((comment) => comment.rangeLabel)).toEqual([
"Test PR",
"CI-failure",
]);
await act(async () => {
state.mergeability = "conflicting";
await screen.rerender(
<ThreadDetailsPrRow
environmentId={EnvironmentId.make("environment")}
pr={null}
number={1}
status={null}
project={null}
label="Test PR"
openAriaLabel="Open PR"
onOpen={vi.fn()}
composerTarget={threadRef}
/>,
);
});
await clickButton(screen.container, "Resolve");
expect(useComposerDraftStore.getState().getComposerDraft(threadRef)?.prompt).toContain(
"https://github.com/owner/repo/pull/1",
"Resolve the conflicts between the attached pull request",
);
expect(state.newThread).not.toHaveBeenCalled();
expect(state.prepareThread).not.toHaveBeenCalled();
});

const repositoryClone = {
Expand Down
40 changes: 26 additions & 14 deletions apps/web/src/components/chat/ThreadDetailsPrRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {

import {
buildFixFindingsHandoff,
buildResolveConflictsPrompt,
buildResolveConflictsHandoff,
classifyPullRequestChecks,
describePullRequestChecks,
isPullRequestConflicting,
Expand Down Expand Up @@ -111,8 +111,8 @@ export function ThreadDetailsPrRow({
onOpen: (event: ReactMouseEvent<HTMLElement>) => void;
onActed?: () => void;
onStopWatching?: (() => void) | undefined;
/** Fix and Resolve write here instead of checking the pull request out in a new thread. */
composerTarget?: ComposerThreadTarget | undefined;
/** Fix and Resolve write here instead of checking the pull request out in a new thread. Null blocks while a queued edit is open. */
composerTarget?: ComposerThreadTarget | null | undefined;
}) {
const serverConfigs = useServerConfigs();
const supportsPullRequests = serverConfigs.get(environmentId) !== undefined;
Expand Down Expand Up @@ -202,6 +202,7 @@ export function ThreadDetailsPrRow({
void startHandoff(kind, task);
return;
}
if (composerTarget === null) return;
writeHandoffToComposer(composerTarget, task);
toastManager.add({
type: "success",
Expand All @@ -212,15 +213,19 @@ export function ThreadDetailsPrRow({

const startResolveConflicts = () => {
if (detail === null) return;
handOff("conflicts", {
prompt: buildResolveConflictsPrompt({
handOff(
"conflicts",
buildResolveConflictsHandoff({
number: detail.number,
title: detail.title,
url: detail.url,
headBranch: detail.headBranch,
baseBranch: detail.baseBranch,
inThisThread: composerTarget !== undefined,
state: detail.state,
isDraft: detail.isDraft,
inThisThread: composerTarget != null,
}),
});
);
};

const startFixChecks = () => {
Expand All @@ -239,7 +244,7 @@ export function ThreadDetailsPrRow({
comments: [],
checks: detail.checks,
commentsTruncated: false,
inThisThread: composerTarget !== undefined,
inThisThread: composerTarget != null,
}),
);
};
Expand Down Expand Up @@ -342,9 +347,7 @@ export function ThreadDetailsPrRow({
);

const newThreadSuffix =
composerTarget === undefined ? (
<ArrowUpRightIcon aria-hidden className="size-3 shrink-0" />
) : null;
composerTarget == null ? <ArrowUpRightIcon aria-hidden className="size-3 shrink-0" /> : null;
const trailingAction =
rowAction === "resolve"
? {
Expand All @@ -354,7 +357,7 @@ export function ThreadDetailsPrRow({
destructive: true,
suffix: newThreadSuffix,
tooltip:
composerTarget === undefined
composerTarget == null
? "Check the branch out and resolve the conflicts in a new thread"
: "Resolve the conflicts in this thread",
onClick: startResolveConflicts,
Expand Down Expand Up @@ -382,7 +385,7 @@ export function ThreadDetailsPrRow({
newThreadSuffix
),
tooltip:
composerTarget === undefined
composerTarget == null
? "Fix the failing checks in a new thread"
: "Fix the failing checks in this thread",
onClick: startFixChecks,
Expand All @@ -399,6 +402,9 @@ export function ThreadDetailsPrRow({
}
: null;

const handoffBlocked =
composerTarget === null && (rowAction === "fix" || rowAction === "resolve");

const watching =
onStopWatching !== undefined && (detail?.state ?? pr?.state ?? "open") === "open";
const watchControl = (part: "secondary" | "icon") =>
Expand Down Expand Up @@ -498,14 +504,20 @@ export function ThreadDetailsPrRow({
part="meta"
tone={trailingAction.destructive ? "destructive" : "primary"}
disabled={actionPending || handoff !== null}
// Disabled buttons take no pointer or focus, which would hide the reason.
aria-disabled={handoffBlocked || undefined}
onClick={trailingAction.onClick}
/>
}
>
{trailingAction.pending ? trailingAction.pendingLabel : trailingAction.label}
{trailingAction.suffix}
</TooltipTrigger>
<TooltipPopup side="top">{trailingAction.tooltip}</TooltipPopup>
<TooltipPopup side="top">
{handoffBlocked
? "Finish editing the queued message first"
: trailingAction.tooltip}
</TooltipPopup>
</Tooltip>
) : null}
</div>
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/components/chat/ThreadDetailsPrRows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function ThreadDetailsPrLinkRow({
onOpen: (event: ReactMouseEvent<HTMLElement>) => void;
onActed?: (() => void) | undefined;
onStopWatching?: (() => void) | undefined;
composerTarget?: ComposerThreadTarget | undefined;
composerTarget?: ComposerThreadTarget | null | undefined;
}) {
const projects = useProjects();
const parsed = sourceControlClients.parseChangeRequestUrl(link.url)?.link;
Expand Down Expand Up @@ -169,7 +169,7 @@ export function ThreadDetailsThreadPrRows({
branchPr?: VcsStatusResult["pr"];
branchSourceControlProvider?: VcsStatusResult["sourceControlProvider"];
onActed?: () => void;
composerTarget?: ComposerThreadTarget | undefined;
composerTarget?: ComposerThreadTarget | null | undefined;
}) {
const thread = useQuietThreadShell(threadRef);
const displayed = useThreadDisplayedPullRequest(
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/components/chat/UserMessageContextChips.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ const userMessageContextPresentationRegistry = createContextPresentationRegistry
kind={isPullRequest ? PULL_REQUEST_CHIP_KINDS[pullRequestState] : "review-comment"}
icon={isPullRequest ? <PullRequestGlyph.pullRequest /> : <MessageCircleIcon />}
label={label}
openOnHover
>
<UserMessageReviewCommentCard
comment={{
Expand Down
3 changes: 3 additions & 0 deletions apps/web/src/components/composerContextPresentation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ function ContextChip(props: {
details: ReactNode;
detailsMode: ContextPresentationCapability["details"];
kind: ContextChipKind;
openOnHover?: boolean;
}) {
if (props.detailsMode === "popover") {
return (
Expand All @@ -147,6 +148,7 @@ function ContextChip(props: {
icon={props.icon}
label={props.label}
accessibleLabel={props.kindLabel + ", " + props.label}
openOnHover={props.openOnHover === true}
>
{props.details}
</ContextChipPopover>
Expand Down Expand Up @@ -434,6 +436,7 @@ const composerContextPresentationRegistry = createContextPresentationRegistry<
details={<ComposerReviewCommentDetails comment={entry.record} />}
detailsMode={definition.capabilities.details}
kind={isPullRequest ? PULL_REQUEST_CHIP_KINDS[pullRequestState] : "review-comment"}
openOnHover
/>
);
},
Expand Down
4 changes: 4 additions & 0 deletions apps/web/src/components/contextChipParts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,15 @@ export function ContextChipPopover(props: {
accessibleLabel: string;
/** Overrides the kind's accent color. */
accent?: string | undefined;
openOnHover?: boolean;
children: ReactNode;
}) {
return (
<Popover>
<PopoverTrigger
openOnHover={props.openOnHover === true}
delay={150}
closeDelay={120}
render={
<ContextChip
kind={props.kind}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,5 @@ it("can still add conflict resolution to an existing composer without checkout s
await act(() => resolve.click());
const draft = useComposerDraftStore.getState().getComposerDraft(draftId);
expect(draft?.prompt).toContain("conflicts");
expect(draft?.prompt).toContain(detail.url);
expect(draft?.reviewComments[0]?.pullRequest?.url).toBe(detail.url);
});
Loading
Loading