Skip to content
Merged
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
33 changes: 33 additions & 0 deletions apps/web/src/components/BranchToolbar.logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
resolvePreviousWorktreeLabel,
resolvePreviousWorktreeSeed,
shouldIncludeBranchPickerItem,
shouldShowComposerContextStrip,
shouldShowEnvironmentIndicator,
} from "./BranchToolbar.logic";

Expand Down Expand Up @@ -421,6 +422,38 @@ describe("shouldShowEnvironmentIndicator", () => {
});
});

describe("shouldShowComposerContextStrip", () => {
it("keeps the environment indicator visible for a non-Git project", () => {
expect(
shouldShowComposerContextStrip({
hasActiveProject: true,
isGitRepo: false,
showEnvironmentIndicator: true,
}),
).toBe(true);
});

it("hides the strip when a non-Git project has no environment indicator", () => {
expect(
shouldShowComposerContextStrip({
hasActiveProject: true,
isGitRepo: false,
showEnvironmentIndicator: false,
}),
).toBe(false);
});

it("shows Git controls without requiring an environment indicator", () => {
expect(
shouldShowComposerContextStrip({
hasActiveProject: true,
isGitRepo: true,
showEnvironmentIndicator: false,
}),
).toBe(true);
});
});

describe("resolveEffectiveEnvMode", () => {
it("treats draft threads already attached to a worktree as current-checkout mode", () => {
expect(
Expand Down
8 changes: 8 additions & 0 deletions apps/web/src/components/BranchToolbar.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ export function shouldShowEnvironmentIndicator(input: {
return input.activeEnvironment !== null && !input.activeEnvironment.isPrimary;
}

export function shouldShowComposerContextStrip(input: {
hasActiveProject: boolean;
isGitRepo: boolean;
showEnvironmentIndicator: boolean;
}): boolean {
return input.hasActiveProject && (input.isGitRepo || input.showEnvironmentIndicator);
}

export function resolveEnvModeLabel(mode: EnvMode): string {
return mode === "worktree" ? "New worktree" : "Current checkout";
}
Expand Down
56 changes: 32 additions & 24 deletions apps/web/src/components/BranchToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { Separator } from "./ui/separator";
interface BranchToolbarProps {
environmentId: EnvironmentId;
threadId: ThreadId;
showGitControls: boolean;
draftId?: DraftId;
onEnvModeChange: (mode: EnvMode) => void;
effectiveEnvModeOverride?: EnvMode;
Expand Down Expand Up @@ -309,6 +310,7 @@ function useLabelsOverflow(element: HTMLDivElement | null): boolean {
export const BranchToolbar = memo(function BranchToolbar({
environmentId,
threadId,
showGitControls,
draftId,
onEnvModeChange,
effectiveEnvModeOverride,
Expand Down Expand Up @@ -403,7 +405,7 @@ export const BranchToolbar = memo(function BranchToolbar({
data-compact={labelsOverflow ? "" : undefined}
className="chat-composer-context-strip group/composer-context -mt-4 mx-auto flex w-[calc(100%-2.75rem)] max-w-[calc(48rem-2.75rem)] items-center gap-2 ps-1 pe-2 pt-5 pb-1"
>
{isMobile ? (
{isMobile && showGitControls ? (
<MobileRunContextSelector
envLocked={envLocked}
envModeLocked={envModeLocked}
Expand All @@ -428,34 +430,40 @@ export const BranchToolbar = memo(function BranchToolbar({
availableEnvironments={availableEnvironments}
{...(showEnvironmentPicker && onEnvironmentChange ? { onEnvironmentChange } : {})}
/>
<Separator orientation="vertical" className="mx-0.5 h-3.5!" />
{showGitControls ? (
<Separator orientation="vertical" className="mx-0.5 h-3.5!" />
) : null}
</>
)}
<BranchToolbarEnvModeSelector
envLocked={envModeLocked}
effectiveEnvMode={effectiveEnvMode}
activeWorktreePath={activeWorktreePath}
onEnvModeChange={onEnvModeChange}
previousWorktreeLabel={previousWorktreeLabel}
onUsePreviousWorktree={onUsePreviousWorktree}
/>
{showGitControls ? (
<BranchToolbarEnvModeSelector
envLocked={envModeLocked}
effectiveEnvMode={effectiveEnvMode}
activeWorktreePath={activeWorktreePath}
onEnvModeChange={onEnvModeChange}
previousWorktreeLabel={previousWorktreeLabel}
onUsePreviousWorktree={onUsePreviousWorktree}
/>
) : null}
</div>
)}

<BranchToolbarBranchSelector
className="min-w-0 flex-1 justify-end md:ml-auto md:flex-none"
environmentId={environmentId}
threadId={threadId}
{...(draftId ? { draftId } : {})}
envLocked={envLocked}
{...(effectiveEnvModeOverride ? { effectiveEnvModeOverride } : {})}
{...(activeThreadBranchOverride !== undefined ? { activeThreadBranchOverride } : {})}
{...(onActiveThreadBranchOverrideChange ? { onActiveThreadBranchOverrideChange } : {})}
startFromOrigin={startFromOrigin}
onStartFromOriginChange={onStartFromOriginChange}
{...(onCheckoutPullRequestRequest ? { onCheckoutPullRequestRequest } : {})}
{...(onComposerFocusRequest ? { onComposerFocusRequest } : {})}
/>
{showGitControls ? (
<BranchToolbarBranchSelector
className="min-w-0 flex-1 justify-end md:ml-auto md:flex-none"
environmentId={environmentId}
threadId={threadId}
{...(draftId ? { draftId } : {})}
envLocked={envLocked}
{...(effectiveEnvModeOverride ? { effectiveEnvModeOverride } : {})}
{...(activeThreadBranchOverride !== undefined ? { activeThreadBranchOverride } : {})}
{...(onActiveThreadBranchOverrideChange ? { onActiveThreadBranchOverrideChange } : {})}
startFromOrigin={startFromOrigin}
onStartFromOriginChange={onStartFromOriginChange}
{...(onCheckoutPullRequestRequest ? { onCheckoutPullRequestRequest } : {})}
{...(onComposerFocusRequest ? { onComposerFocusRequest } : {})}
/>
) : null}
</div>
);
});
22 changes: 20 additions & 2 deletions apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,12 @@ import { ChatHeader } from "./chat/ChatHeader";
import { PanelLayoutControls, RightPanelMaximizeControl } from "./chat/PanelLayoutControls";
import { type ExpandedImagePreview } from "./chat/ExpandedImagePreview";
import { NoActiveThreadState } from "./NoActiveThreadState";
import { resolveEffectiveEnvMode, resolveLocalCheckoutBranchMismatch } from "./BranchToolbar.logic";
import {
resolveEffectiveEnvMode,
resolveLocalCheckoutBranchMismatch,
shouldShowComposerContextStrip,
shouldShowEnvironmentIndicator,
} from "./BranchToolbar.logic";
import {
getProviderStatusBannerKey,
ProviderStatusBanner,
Expand Down Expand Up @@ -1745,6 +1750,14 @@ function ChatViewContent(props: ChatViewProps) {
return envs;
}, [activeProject, allProjects, projectGroupingSettings, primaryEnvironmentId, environmentById]);
const hasMultipleEnvironments = logicalProjectEnvironments.length > 1;
const activeEnvironmentOption =
logicalProjectEnvironments.find(
(environment) => environment.environmentId === activeThread?.environmentId,
) ?? null;
const showComposerEnvironmentIndicator = shouldShowEnvironmentIndicator({
activeEnvironment: activeEnvironmentOption,
canPickEnvironment: hasMultipleEnvironments,
});

const openPullRequestDialog = useCallback(
(reference?: string) => {
Expand Down Expand Up @@ -2514,7 +2527,11 @@ function ChatViewContent(props: ChatViewProps) {
terminalUiLaunchContext?.threadId === activeThreadId ? terminalUiLaunchContext : null;
// Default true while loading to avoid toolbar flicker.
const isGitRepo = gitStatusQuery.data?.isRepo ?? true;
const showComposerContextStrip = isGitRepo && activeProject !== null;
const showComposerContextStrip = shouldShowComposerContextStrip({
hasActiveProject: activeProject !== null,
isGitRepo,
showEnvironmentIndicator: showComposerEnvironmentIndicator,
});
const initialDiffPanelGitScope =
gitStatusQuery.data?.hasWorkingTreeChanges === true ? "unstaged" : "branch";
const diffPanelGitStatusResolutionKey = gitStatusQuery.data ? "resolved" : "pending";
Expand Down Expand Up @@ -6180,6 +6197,7 @@ function ChatViewContent(props: ChatViewProps) {
<BranchToolbar
environmentId={activeThread.environmentId}
threadId={activeThread.id}
showGitControls={isGitRepo}
{...(routeKind === "draft" && draftId ? { draftId } : {})}
onEnvModeChange={onEnvModeChange}
startFromOrigin={startFromOrigin}
Expand Down
Loading