Skip to content

Commit 496fde5

Browse files
committed
fix(web): compact chat header actions into an overflow menu
1 parent d8a485e commit 496fde5

2 files changed

Lines changed: 139 additions & 7 deletions

File tree

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

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import { readNativeApi } from "~/nativeApi";
5454
interface GitActionsControlProps {
5555
gitCwd: string | null;
5656
activeThreadId: ThreadId | null;
57+
inMenu?: boolean;
5758
}
5859

5960
interface PendingDefaultBranchAction {
@@ -203,7 +204,11 @@ function GitQuickActionIcon({ quickAction }: { quickAction: GitQuickAction }) {
203204
return <InfoIcon className={iconClassName} />;
204205
}
205206

206-
export default function GitActionsControl({ gitCwd, activeThreadId }: GitActionsControlProps) {
207+
export default function GitActionsControl({
208+
gitCwd,
209+
activeThreadId,
210+
inMenu,
211+
}: GitActionsControlProps) {
207212
const threadToastData = useMemo(
208213
() => (activeThreadId ? { threadId: activeThreadId } : undefined),
209214
[activeThreadId],
@@ -738,6 +743,53 @@ export default function GitActionsControl({ gitCwd, activeThreadId }: GitActions
738743

739744
if (!gitCwd) return null;
740745

746+
if (inMenu) {
747+
return (
748+
<>
749+
{gitActionMenuItems.map((item) => {
750+
const disabledReason = getMenuActionDisabledReason({
751+
item,
752+
gitStatus: gitStatusForActions,
753+
isBusy: isGitActionRunning,
754+
hasOriginRemote,
755+
});
756+
if (item.disabled && disabledReason) {
757+
return (
758+
<Popover key={`${item.id}-${item.label}`}>
759+
<PopoverTrigger
760+
openOnHover
761+
nativeButton={false}
762+
render={<span className="block w-max cursor-not-allowed" />}
763+
>
764+
<MenuItem className="w-full" disabled>
765+
<GitActionItemIcon icon={item.icon} />
766+
{item.label}
767+
</MenuItem>
768+
</PopoverTrigger>
769+
<PopoverPopup tooltipStyle side="left" align="center">
770+
{disabledReason}
771+
</PopoverPopup>
772+
</Popover>
773+
);
774+
}
775+
776+
return (
777+
<MenuItem
778+
key={`${item.id}-${item.label}`}
779+
disabled={item.disabled}
780+
onClick={() => {
781+
openDialogForMenuItem(item);
782+
}}
783+
>
784+
<GitActionItemIcon icon={item.icon} />
785+
{item.label}
786+
</MenuItem>
787+
);
788+
})}
789+
</>
790+
);
791+
}
792+
741793
return (
742794
<>
743795
{!isRepo ? (

‎apps/web/src/components/chat/ChatHeader.tsx‎

Lines changed: 86 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@ import {
44
type ResolvedKeybindingsConfig,
55
type ThreadId,
66
} from "@t3tools/contracts";
7-
import { memo } from "react";
7+
import { EllipsisIcon, DiffIcon, TerminalSquareIcon, PlayIcon, FolderOpenIcon } from "lucide-react";
8+
import { memo, useEffect, useRef, useState } from "react";
89
import GitActionsControl from "../GitActionsControl";
9-
import { DiffIcon, TerminalSquareIcon } from "lucide-react";
1010
import { Badge } from "../ui/badge";
11+
import { Button } from "../ui/button";
12+
import { Menu, MenuItem, MenuPopup, MenuSeparator as MenuDivider, MenuTrigger } from "../ui/menu";
1113
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
1214
import ProjectScriptsControl, { type NewProjectScriptInput } from "../ProjectScriptsControl";
1315
import { Toggle } from "../ui/toggle";
1416
import { SidebarTrigger } from "../ui/sidebar";
1517
import { OpenInPicker } from "./OpenInPicker";
18+
import { readNativeApi } from "~/nativeApi";
19+
20+
const HEADER_ACTIONS_COMPACT_BREAKPOINT_PX = 860;
1621

1722
interface ChatHeaderProps {
1823
activeThreadId: ThreadId;
@@ -61,8 +66,35 @@ export const ChatHeader = memo(function ChatHeader({
6166
onToggleTerminal,
6267
onToggleDiff,
6368
}: ChatHeaderProps) {
69+
const containerRef = useRef<HTMLDivElement | null>(null);
70+
const [useOverflowPopover, setUseOverflowPopover] = useState(false);
71+
const hasOverflowActions = activeProjectScripts !== undefined || activeProjectName !== undefined;
72+
73+
useEffect(() => {
74+
const container = containerRef.current;
75+
if (!container) return;
76+
77+
const updateLayout = (width: number) => {
78+
setUseOverflowPopover(width < HEADER_ACTIONS_COMPACT_BREAKPOINT_PX);
79+
};
80+
81+
updateLayout(container.clientWidth);
82+
83+
if (typeof ResizeObserver === "undefined") return;
84+
const observer = new ResizeObserver((entries) => {
85+
const entry = entries[0];
86+
if (!entry) return;
87+
updateLayout(entry.contentRect.width);
88+
});
89+
observer.observe(container);
90+
return () => observer.disconnect();
91+
}, []);
92+
6493
return (
65-
<div className="@container/header-actions flex min-w-0 flex-1 items-center gap-2">
94+
<div
95+
ref={containerRef}
96+
className="@container/header-actions flex min-w-0 flex-1 items-center gap-2"
97+
>
6698
<div className="flex min-w-0 flex-1 items-center gap-2 overflow-hidden sm:gap-3">
6799
<SidebarTrigger className="size-7 shrink-0 md:hidden" />
68100
<h2
@@ -83,7 +115,53 @@ export const ChatHeader = memo(function ChatHeader({
83115
)}
84116
</div>
85117
<div className="flex shrink-0 items-center justify-end gap-2 @3xl/header-actions:gap-3">
86-
{activeProjectScripts && (
118+
{hasOverflowActions && useOverflowPopover ? (
119+
<Menu>
120+
<MenuTrigger
121+
render={<Button size="icon-xs" variant="outline" aria-label="More actions" />}
122+
>
123+
<EllipsisIcon className="size-4" />
124+
</MenuTrigger>
125+
<MenuPopup align="end">
126+
{activeProjectScripts && activeProjectScripts.length > 0 && (
127+
<>
128+
<div className="px-2 py-1.5 font-medium text-muted-foreground text-xs">
129+
Run script
130+
</div>
131+
{activeProjectScripts.slice(0, 5).map((script) => (
132+
<MenuItem key={script.id} onClick={() => onRunProjectScript(script)}>
133+
<PlayIcon className="size-4 shrink-0" />
134+
{script.name}
135+
</MenuItem>
136+
))}
137+
{activeProjectScripts.length > 5 && (
138+
<MenuItem disabled className="text-muted-foreground">
139+
+{activeProjectScripts.length - 5} more
140+
</MenuItem>
141+
)}
142+
<MenuDivider />
143+
</>
144+
)}
145+
{activeProjectName && (
146+
<>
147+
<MenuItem
148+
onClick={() => {
149+
const api = readNativeApi();
150+
if (!api || !openInCwd) return;
151+
void api.shell.openInEditor(openInCwd, "file-manager");
152+
}}
153+
>
154+
<FolderOpenIcon className="size-4 shrink-0" />
155+
Open folder
156+
</MenuItem>
157+
<MenuDivider />
158+
<GitActionsControl inMenu gitCwd={gitCwd} activeThreadId={activeThreadId} />
159+
</>
160+
)}
161+
</MenuPopup>
162+
</Menu>
163+
) : null}
164+
{!useOverflowPopover && activeProjectScripts && (
87165
<ProjectScriptsControl
88166
scripts={activeProjectScripts}
89167
keybindings={keybindings}
@@ -94,14 +172,16 @@ export const ChatHeader = memo(function ChatHeader({
94172
onDeleteScript={onDeleteProjectScript}
95173
/>
96174
)}
97-
{activeProjectName && (
175+
{!useOverflowPopover && activeProjectName && (
98176
<OpenInPicker
99177
keybindings={keybindings}
100178
availableEditors={availableEditors}
101179
openInCwd={openInCwd}
102180
/>
103181
)}
104-
{activeProjectName && <GitActionsControl gitCwd={gitCwd} activeThreadId={activeThreadId} />}
182+
{!useOverflowPopover && activeProjectName && (
183+
<GitActionsControl gitCwd={gitCwd} activeThreadId={activeThreadId} />
184+
)}
105185
<Tooltip>
106186
<TooltipTrigger
107187
render={

0 commit comments

Comments
 (0)