Skip to content

Commit 5b8445b

Browse files
chrisdeemingmaria-rcksjuliusmarmingeclaude
authored
fix(web): collapse the resting composer (pingdotgg#7855)
Co-authored-by: maria-rcks <[email protected]> Co-authored-by: Julius Marminge <[email protected]> Co-authored-by: Claude Code <[email protected]>
1 parent 24799de commit 5b8445b

33 files changed

Lines changed: 2297 additions & 292 deletions

‎apps/web/src/components/BranchToolbar.logic.test.ts‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,26 +430,40 @@ describe("shouldShowComposerContextStrip", () => {
430430
hasActiveProject: true,
431431
isGitRepo: false,
432432
showEnvironmentIndicator: true,
433+
hostsRestingComposerControls: false,
433434
}),
434435
).toBe(true);
435436
});
436437

437-
it("hides the strip when a non-Git project has no environment indicator", () => {
438+
it("hides the strip when a non-Git project has nothing to show", () => {
438439
expect(
439440
shouldShowComposerContextStrip({
440441
hasActiveProject: true,
441442
isGitRepo: false,
442443
showEnvironmentIndicator: false,
444+
hostsRestingComposerControls: false,
443445
}),
444446
).toBe(false);
445447
});
446448

449+
it("keeps the strip for visible resting composer controls in a non-Git thread", () => {
450+
expect(
451+
shouldShowComposerContextStrip({
452+
hasActiveProject: true,
453+
isGitRepo: false,
454+
showEnvironmentIndicator: false,
455+
hostsRestingComposerControls: true,
456+
}),
457+
).toBe(true);
458+
});
459+
447460
it("shows Git controls without requiring an environment indicator", () => {
448461
expect(
449462
shouldShowComposerContextStrip({
450463
hasActiveProject: true,
451464
isGitRepo: true,
452465
showEnvironmentIndicator: false,
466+
hostsRestingComposerControls: false,
453467
}),
454468
).toBe(true);
455469
});

‎apps/web/src/components/BranchToolbar.logic.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,13 @@ export function shouldShowComposerContextStrip(input: {
5959
hasActiveProject: boolean;
6060
isGitRepo: boolean;
6161
showEnvironmentIndicator: boolean;
62+
/** A collapsed composer's controls currently fit in their measured strip host. */
63+
hostsRestingComposerControls: boolean;
6264
}): boolean {
63-
return input.hasActiveProject && (input.isGitRepo || input.showEnvironmentIndicator);
65+
return (
66+
input.hasActiveProject &&
67+
(input.isGitRepo || input.showEnvironmentIndicator || input.hostsRestingComposerControls)
68+
);
6469
}
6570

6671
export function resolveEnvModeLabel(mode: EnvMode): string {

‎apps/web/src/components/BranchToolbar.tsx‎

Lines changed: 82 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { memo, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useStat
1212
import { useComposerDraftStore, type DraftId } from "../composerDraftStore";
1313
import { EnvironmentMachineIcon } from "./EnvironmentMachineIcon";
1414
import { useProject, useThread, useThreadShellsForProjectRefs } from "../state/entities";
15-
import { useIsMobile } from "../hooks/useMediaQuery";
1615
import {
1716
type EnvMode,
1817
type EnvironmentOption,
@@ -40,6 +39,7 @@ import {
4039
} from "./ui/menu";
4140
import { Separator } from "./ui/separator";
4241
import { ComposerSurface } from "./chat/ComposerSurface";
42+
import { cn } from "~/lib/utils";
4343

4444
interface BranchToolbarProps {
4545
environmentId: EnvironmentId;
@@ -57,6 +57,8 @@ interface BranchToolbarProps {
5757
onComposerFocusRequest?: () => void;
5858
availableEnvironments?: readonly EnvironmentOption[];
5959
onEnvironmentChange?: (environmentId: EnvironmentId) => void;
60+
composerControlsHostRef?: (element: HTMLDivElement | null) => void;
61+
contextStripVisible?: boolean;
6062
}
6163

6264
interface MobileRunContextSelectorProps {
@@ -120,15 +122,26 @@ const MobileRunContextSelector = memo(function MobileRunContextSelector({
120122
const triggerContent = (
121123
<>
122124
{icon}
123-
<span className="min-w-0 truncate">
124-
{showEnvironmentIndicator ? (activeEnvironment?.label ?? "Run on") : workspaceLabel}
125+
<span
126+
data-composer-label
127+
className="min-w-0 max-w-[240px] group-data-[compact]/composer-context:max-w-0"
128+
>
129+
<span
130+
data-composer-label-motion
131+
className="block w-full min-w-0 max-w-[240px] origin-left truncate transition-[opacity,transform] duration-180 ease-[cubic-bezier(0.32,0.72,0,1)] group-data-[compact]/composer-context:[transform:translateX(-0.25rem)_scaleX(0.95)] group-data-[compact]/composer-context:opacity-0 motion-reduce:transform-none motion-reduce:transition-opacity"
132+
>
133+
{showEnvironmentIndicator ? (activeEnvironment?.label ?? "Run on") : workspaceLabel}
134+
</span>
125135
</span>
126136
</>
127137
);
128138

129139
if (isLocked) {
130140
return (
131-
<span className="inline-flex h-7 min-w-0 max-w-[48%] flex-1 items-center justify-start gap-1 rounded-md border border-transparent px-[calc(--spacing(2)-1px)] text-sm font-medium text-muted-foreground/70 sm:h-6 md:hidden">
141+
<span
142+
className="inline-flex h-7 min-w-0 max-w-[48%] flex-initial items-center justify-start gap-1 rounded-md border border-transparent px-[calc(--spacing(2)-1px)] font-normal text-muted-foreground/70 text-xs sm:h-6"
143+
data-composer-context-control
144+
>
132145
{triggerContent}
133146
</span>
134147
);
@@ -138,7 +151,8 @@ const MobileRunContextSelector = memo(function MobileRunContextSelector({
138151
<Menu>
139152
<MenuTrigger
140153
render={<Button variant="ghost" size="xs" />}
141-
className="min-w-0 max-w-[48%] flex-1 justify-start text-muted-foreground/70 hover:text-foreground/80 md:hidden"
154+
className="min-w-0 max-w-[48%] flex-initial justify-start font-normal text-muted-foreground/70 text-xs! hover:text-foreground/80"
155+
data-composer-context-control
142156
>
143157
{triggerContent}
144158
<ChevronDownIcon className="size-3 shrink-0 opacity-50" />
@@ -251,10 +265,14 @@ function useLabelsOverflow(element: HTMLDivElement | null): boolean {
251265
let counted = 0;
252266
for (const child of parent.children) {
253267
if (!(child instanceof HTMLElement)) continue;
254-
if (child.offsetWidth <= 1) continue;
255-
const position = getComputedStyle(child).position;
268+
if (child.offsetWidth === 0) continue;
269+
const style = getComputedStyle(child);
270+
const position = style.position;
256271
if (position === "absolute" || position === "fixed") continue;
257-
width += child.offsetWidth;
272+
width +=
273+
child.offsetWidth +
274+
(Number.parseFloat(style.marginInlineStart) || 0) +
275+
(Number.parseFloat(style.marginInlineEnd) || 0);
258276
counted += 1;
259277
}
260278
return width + gap * Math.max(0, counted - 1);
@@ -264,10 +282,15 @@ function useLabelsOverflow(element: HTMLDivElement | null): boolean {
264282
let groups = 0;
265283
for (const child of current.children) {
266284
if (!(child instanceof HTMLElement)) continue;
267-
const width = contentWidth(child);
285+
// The host itself flexes into all remaining room. Measure the controls
286+
// inside it so Git labels compact before squeezing out the model picker.
287+
const hostedControls = child.matches('[data-chat-resting-composer-controls-host="true"]')
288+
? child.querySelector<HTMLElement>('[data-chat-composer-resting-controls="true"]')
289+
: null;
290+
const width = hostedControls ? contentWidth(hostedControls) : contentWidth(child);
268291
if (width <= 1) continue;
269-
needed += width;
270292
groups += 1;
293+
needed += width;
271294
}
272295
needed += stripGap * Math.max(0, groups - 1);
273296
for (const label of current.querySelectorAll<HTMLElement>("[data-composer-label]")) {
@@ -390,6 +413,8 @@ export const BranchToolbar = memo(function BranchToolbar({
390413
onComposerFocusRequest,
391414
availableEnvironments,
392415
onEnvironmentChange,
416+
composerControlsHostRef,
417+
contextStripVisible = true,
393418
}: BranchToolbarProps) {
394419
const threadRef = useMemo(
395420
() => scopeThreadRef(environmentId, threadId),
@@ -460,7 +485,6 @@ export const BranchToolbar = memo(function BranchToolbar({
460485
activeEnvironment: activeEnvironmentOption,
461486
canPickEnvironment: showEnvironmentPicker,
462487
});
463-
const isMobile = useIsMobile();
464488
const [stripElement, setStripElement] = useState<HTMLDivElement | null>(null);
465489
const labelsOverflow = useLabelsOverflow(stripElement);
466490

@@ -470,24 +494,40 @@ export const BranchToolbar = memo(function BranchToolbar({
470494
<ComposerSurface.ContextStrip
471495
ref={setStripElement}
472496
data-compact={labelsOverflow ? "" : undefined}
497+
className={cn(
498+
"gap-1 text-xs font-normal text-muted-foreground/70",
499+
// A non-Git strip with no visible composer controls should occupy no
500+
// space, but its host must retain a prospective width so controls can
501+
// become visible again when the chat view grows.
502+
!contextStripVisible && "pointer-events-none invisible absolute inset-x-0 top-full",
503+
)}
473504
>
474-
{isMobile && showGitControls ? (
475-
<MobileRunContextSelector
476-
envLocked={envLocked}
477-
envModeLocked={envModeLocked}
478-
environmentId={environmentId}
479-
availableEnvironments={availableEnvironments}
480-
showEnvironmentPicker={showEnvironmentPicker}
481-
showEnvironmentIndicator={showEnvironmentIndicator}
482-
onEnvironmentChange={onEnvironmentChange}
483-
effectiveEnvMode={effectiveEnvMode}
484-
activeWorktreePath={activeWorktreePath}
485-
onEnvModeChange={onEnvModeChange}
486-
previousWorktreeLabel={previousWorktreeLabel}
487-
onUsePreviousWorktree={onUsePreviousWorktree}
488-
/>
489-
) : (
490-
<div className="flex min-w-10 flex-1 items-center gap-1">
505+
{showGitControls ? (
506+
<div className="contents @3xl/composer-surface:hidden">
507+
<MobileRunContextSelector
508+
envLocked={envLocked}
509+
envModeLocked={envModeLocked}
510+
environmentId={environmentId}
511+
availableEnvironments={availableEnvironments}
512+
showEnvironmentPicker={showEnvironmentPicker}
513+
showEnvironmentIndicator={showEnvironmentIndicator}
514+
onEnvironmentChange={onEnvironmentChange}
515+
effectiveEnvMode={effectiveEnvMode}
516+
activeWorktreePath={activeWorktreePath}
517+
onEnvModeChange={onEnvModeChange}
518+
previousWorktreeLabel={previousWorktreeLabel}
519+
onUsePreviousWorktree={onUsePreviousWorktree}
520+
/>
521+
</div>
522+
) : null}
523+
{showGitControls || showEnvironmentIndicator ? (
524+
<div
525+
className={cn(
526+
"min-h-7 min-w-10 items-center gap-1 sm:min-h-6",
527+
showGitControls ? "hidden @3xl/composer-surface:flex" : "flex",
528+
composerControlsHostRef ? "shrink" : "flex-1",
529+
)}
530+
>
491531
{showEnvironmentIndicator && availableEnvironments && (
492532
<>
493533
<BranchToolbarEnvironmentSelector
@@ -516,11 +556,23 @@ export const BranchToolbar = memo(function BranchToolbar({
516556
/>
517557
) : null}
518558
</div>
519-
)}
559+
) : null}
560+
561+
{composerControlsHostRef ? (
562+
// The host takes whatever the workspace and branch controls leave
563+
// over, in both strip layouts, so a collapsed composer can show its
564+
// model and mode controls wherever they fit.
565+
<div
566+
ref={composerControlsHostRef}
567+
data-composer-context-control
568+
data-chat-resting-composer-controls-host="true"
569+
className="flex min-w-0 flex-1 items-center justify-start overflow-x-clip overflow-y-visible"
570+
/>
571+
) : null}
520572

521573
{showGitControls ? (
522574
<BranchToolbarBranchSelector
523-
className="min-w-0 flex-1 justify-end md:ml-auto md:flex-initial"
575+
className="min-w-0 flex-initial justify-end @3xl/composer-surface:ml-auto"
524576
environmentId={environmentId}
525577
threadId={threadId}
526578
{...(draftId ? { draftId } : {})}

‎apps/web/src/components/BranchToolbarBranchSelector.tsx‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,17 @@ export function BranchToolbarBranchSelector({
745745
}
746746
>
747747
<ChangeRequestStatusIcon className="size-3" />
748-
<span>#{branchPr.number}</span>
748+
<span
749+
data-composer-label
750+
className="min-w-0 max-w-12 overflow-hidden group-data-[compact]/composer-context:max-w-0"
751+
>
752+
<span
753+
data-composer-label-motion
754+
className="block w-full min-w-0 max-w-12 origin-left truncate transition-[opacity,transform] duration-180 ease-[cubic-bezier(0.32,0.72,0,1)] group-data-[compact]/composer-context:[transform:translateX(-0.25rem)_scaleX(0.95)] group-data-[compact]/composer-context:opacity-0 motion-reduce:transform-none motion-reduce:transition-opacity"
755+
>
756+
#{branchPr.number}
757+
</span>
758+
</span>
749759
</TooltipTrigger>
750760
<TooltipPopup side="top">{branchPrTooltip}</TooltipPopup>
751761
</Tooltip>
@@ -759,7 +769,7 @@ export function BranchToolbarBranchSelector({
759769
>
760770
<ComboboxTrigger
761771
render={<Button variant="ghost" size="xs" />}
762-
className="min-w-0 max-w-full text-muted-foreground/70 hover:text-foreground/80"
772+
className="min-w-0 max-w-full font-normal text-muted-foreground/70 text-xs! hover:text-foreground/80"
763773
disabled={isInitialBranchesLoadPending || isBranchActionPending}
764774
>
765775
<GitBranchIcon className="size-3 shrink-0 opacity-70" />

‎apps/web/src/components/BranchToolbarEnvModeSelector.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const BranchToolbarEnvModeSelector = memo(function BranchToolbarEnvModeSe
5151
if (envLocked) {
5252
return (
5353
<span
54-
className="inline-flex h-7 min-w-0 items-center gap-1 border border-transparent px-[calc(--spacing(3)-1px)] text-sm font-medium text-muted-foreground/70 sm:h-6 sm:text-xs"
54+
className="inline-flex h-7 min-w-0 items-center gap-1 border border-transparent px-[calc(--spacing(2)-1px)] font-normal text-muted-foreground/70 text-xs sm:h-6"
5555
data-composer-context-control
5656
>
5757
{activeWorktreePath ? (
@@ -90,7 +90,7 @@ export const BranchToolbarEnvModeSelector = memo(function BranchToolbarEnvModeSe
9090
<SelectTrigger
9191
variant="ghost"
9292
size="xs"
93-
className="min-w-0 shrink font-medium"
93+
className="min-w-0 shrink font-normal text-xs!"
9494
aria-label="Workspace"
9595
data-composer-context-control
9696
>

‎apps/web/src/components/BranchToolbarEnvironmentSelector.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const BranchToolbarEnvironmentSelector = memo(function BranchToolbarEnvir
4949
if (envLocked || onEnvironmentChange === undefined) {
5050
return (
5151
<span
52-
className="inline-flex h-7 min-w-0 max-w-full items-center gap-1 border border-transparent px-[calc(--spacing(3)-1px)] text-sm font-medium text-muted-foreground/70 sm:h-6 sm:text-xs"
52+
className="inline-flex h-7 min-w-0 max-w-full items-center gap-1 border border-transparent px-[calc(--spacing(2)-1px)] font-normal text-muted-foreground/70 text-xs sm:h-6"
5353
data-composer-context-control
5454
>
5555
<EnvironmentMachineIcon
@@ -81,7 +81,7 @@ export const BranchToolbarEnvironmentSelector = memo(function BranchToolbarEnvir
8181
<SelectTrigger
8282
variant="ghost"
8383
size="xs"
84-
className="min-w-0 max-w-full font-medium"
84+
className="min-w-0 max-w-full font-normal text-xs!"
8585
aria-label="Run on"
8686
data-composer-context-control
8787
>

0 commit comments

Comments
 (0)