Skip to content

Commit c14f601

Browse files
authored
fix(web): keep narrow chat headers readable and aligned (#12453)
1 parent 0ff87f2 commit c14f601

7 files changed

Lines changed: 563 additions & 229 deletions

File tree

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

Lines changed: 175 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,16 @@ import {
7979
} from "~/components/ui/dialog";
8080
import { Group, GroupSeparator } from "~/components/ui/group";
8181
import { Input } from "~/components/ui/input";
82-
import { Menu, MenuItem, MenuPopup, MenuTrigger } from "~/components/ui/menu";
82+
import {
83+
Menu,
84+
MenuItem,
85+
MenuItemLabel,
86+
MenuPopup,
87+
MenuSub,
88+
MenuSubTrigger,
89+
MenuSubPopup,
90+
MenuTrigger,
91+
} from "~/components/ui/menu";
8392
import { Popover, PopoverPopup, PopoverTrigger } from "~/components/ui/popover";
8493
import { ScrollArea } from "~/components/ui/scroll-area";
8594
import { Textarea } from "~/components/ui/textarea";
@@ -108,6 +117,7 @@ import { useOpenLink } from "~/browser/useOpenLink";
108117
import { useOpenPrLink } from "~/lib/openPullRequestLink";
109118

110119
interface GitActionsControlProps {
120+
presentation?: "toolbar" | "menu";
111121
gitCwd: string | null;
112122
activeThreadRef: ScopedThreadRef | null;
113123
draftId?: DraftId;
@@ -374,24 +384,25 @@ function GitActionItemIcon({
374384
function GitQuickActionIcon({
375385
quickAction,
376386
SourceControlIcon,
387+
className = "size-3.5",
377388
}: {
378389
quickAction: GitQuickAction;
390+
className?: string;
379391
SourceControlIcon: ReturnType<typeof getSourceControlPresentation>["Icon"];
380392
}) {
381-
const iconClassName = "size-3.5";
382-
if (quickAction.kind === "open_pr") return <SourceControlIcon className={iconClassName} />;
383-
if (quickAction.kind === "open_publish") return <CloudUploadIcon className={iconClassName} />;
384-
if (quickAction.kind === "run_pull") return <CloudDownloadIcon className={iconClassName} />;
393+
if (quickAction.kind === "open_pr") return <SourceControlIcon className={className} />;
394+
if (quickAction.kind === "open_publish") return <CloudUploadIcon className={className} />;
395+
if (quickAction.kind === "run_pull") return <CloudDownloadIcon className={className} />;
385396
if (quickAction.kind === "run_action") {
386-
if (quickAction.action === "commit") return <GitCommitIcon className={iconClassName} />;
397+
if (quickAction.action === "commit") return <GitCommitIcon className={className} />;
387398
if (quickAction.action === "push" || quickAction.action === "commit_push") {
388-
return <CloudUploadIcon className={iconClassName} />;
399+
return <CloudUploadIcon className={className} />;
389400
}
390-
return <SourceControlIcon className={iconClassName} />;
401+
return <SourceControlIcon className={className} />;
391402
}
392-
if (quickAction.label === "Commit") return <GitCommitIcon className={iconClassName} />;
393-
if (quickAction.label === "Push") return <CloudUploadIcon className={iconClassName} />;
394-
return <InfoIcon className={iconClassName} />;
403+
if (quickAction.label === "Commit") return <GitCommitIcon className={className} />;
404+
if (quickAction.label === "Push") return <CloudUploadIcon className={className} />;
405+
return <InfoIcon className={className} />;
395406
}
396407

397408
interface PublishRepositoryDialogProps {
@@ -944,6 +955,7 @@ function PublishRepositoryDialog(props: PublishRepositoryDialogProps) {
944955
}
945956

946957
export default function GitActionsControl({
958+
presentation = "toolbar",
947959
gitCwd,
948960
activeThreadRef,
949961
draftId,
@@ -1632,33 +1644,161 @@ export default function GitActionsControl({
16321644

16331645
const canPublishRepository = isRepo && gitStatusForActions !== null && !hasPrimaryRemote;
16341646

1635-
if (!gitCwd) return null;
1636-
1637-
return (
1647+
const initializeGit = () => {
1648+
void (async () => {
1649+
const result = await initAction.run();
1650+
if (result._tag === "Success" || isAtomCommandInterrupted(result)) {
1651+
return;
1652+
}
1653+
const error = squashAtomCommandFailure(result);
1654+
toastManager.add(
1655+
stackedThreadToast({
1656+
type: "error",
1657+
title: "Git initialization failed",
1658+
description: error instanceof Error ? error.message : "An error occurred.",
1659+
...(threadToastData !== undefined ? { data: threadToastData } : {}),
1660+
}),
1661+
);
1662+
})();
1663+
};
1664+
const gitItems = (
16381665
<>
1639-
{!isRepo ? (
1640-
<Button
1641-
variant="outline"
1642-
size="xs"
1643-
disabled={initAction.isPending}
1666+
{gitActionMenuItems.map((item) => {
1667+
const disabledReason = getMenuActionDisabledReason({
1668+
item,
1669+
gitStatus: gitStatusForActions,
1670+
isBusy: isGitActionRunning,
1671+
hasPrimaryRemote,
1672+
});
1673+
if (item.disabled && disabledReason && presentation === "menu") {
1674+
return (
1675+
<div key={`${item.id}-${item.label}`}>
1676+
<MenuItem density={presentation === "menu" ? "touch" : "default"} disabled>
1677+
<GitActionItemIcon icon={item.icon} SourceControlIcon={SourceControlIcon} />
1678+
<MenuItemLabel>{item.label}</MenuItemLabel>
1679+
</MenuItem>
1680+
<p className="max-w-64 px-2 pb-2 text-xs text-muted-foreground">{disabledReason}</p>
1681+
</div>
1682+
);
1683+
}
1684+
if (item.disabled && disabledReason) {
1685+
return (
1686+
<Popover key={`${item.id}-${item.label}`}>
1687+
<PopoverTrigger
1688+
openOnHover
1689+
nativeButton={false}
1690+
render={<span className="block w-max cursor-not-allowed" />}
1691+
>
1692+
<MenuItem
1693+
density={presentation === "menu" ? "touch" : "default"}
1694+
className="w-full"
1695+
disabled
1696+
>
1697+
<GitActionItemIcon icon={item.icon} SourceControlIcon={SourceControlIcon} />
1698+
<MenuItemLabel>{item.label}</MenuItemLabel>
1699+
</MenuItem>
1700+
</PopoverTrigger>
1701+
<PopoverPopup tooltipStyle side="left" align="center">
1702+
{disabledReason}
1703+
</PopoverPopup>
1704+
</Popover>
1705+
);
1706+
}
1707+
1708+
return (
1709+
<MenuItem
1710+
density={presentation === "menu" ? "touch" : "default"}
1711+
key={`${item.id}-${item.label}`}
1712+
disabled={item.disabled}
1713+
onClick={() => {
1714+
openDialogForMenuItem(item);
1715+
}}
1716+
>
1717+
<GitActionItemIcon icon={item.icon} SourceControlIcon={SourceControlIcon} />
1718+
<MenuItemLabel>{item.label}</MenuItemLabel>
1719+
</MenuItem>
1720+
);
1721+
})}
1722+
{canPublishRepository ? (
1723+
<MenuItem
1724+
density={presentation === "menu" ? "touch" : "default"}
1725+
disabled={isGitActionRunning}
16441726
onClick={() => {
1645-
void (async () => {
1646-
const result = await initAction.run();
1647-
if (result._tag === "Success" || isAtomCommandInterrupted(result)) {
1648-
return;
1649-
}
1650-
const error = squashAtomCommandFailure(result);
1651-
toastManager.add(
1652-
stackedThreadToast({
1653-
type: "error",
1654-
title: "Git initialization failed",
1655-
description: error instanceof Error ? error.message : "An error occurred.",
1656-
...(threadToastData !== undefined ? { data: threadToastData } : {}),
1657-
}),
1658-
);
1659-
})();
1727+
setIsPublishDialogOpen(true);
16601728
}}
16611729
>
1730+
<CloudUploadIcon />
1731+
<MenuItemLabel>Publish repository...</MenuItemLabel>
1732+
</MenuItem>
1733+
) : null}
1734+
{gitStatusForActions?.refName === null && (
1735+
<p className="px-2 py-1.5 text-xs text-warning">
1736+
Detached HEAD: create and check out a branch to enable push and pull request actions.
1737+
</p>
1738+
)}
1739+
{gitStatusForActions &&
1740+
gitStatusForActions.refName !== null &&
1741+
!gitStatusForActions.hasWorkingTreeChanges &&
1742+
gitStatusForActions.behindCount > 0 &&
1743+
gitStatusForActions.aheadCount === 0 && (
1744+
<p className="px-2 py-1.5 text-xs text-warning">Behind upstream. Pull/rebase first.</p>
1745+
)}
1746+
{gitStatusError && <p className="px-2 py-1.5 text-xs text-destructive">{gitStatusError}</p>}
1747+
</>
1748+
);
1749+
1750+
if (!gitCwd) return null;
1751+
1752+
return (
1753+
<>
1754+
{presentation === "menu" ? (
1755+
!isRepo ? (
1756+
<MenuItem
1757+
density={presentation === "menu" ? "touch" : "default"}
1758+
1759+
disabled={initAction.isPending}
1760+
onClick={initializeGit}
1761+
>
1762+
<GitBranchPlusIcon className="size-4" />
1763+
<MenuItemLabel>
1764+
{initAction.isPending ? "Initializing..." : "Initialize Git"}
1765+
</MenuItemLabel>
1766+
</MenuItem>
1767+
) : (
1768+
<>
1769+
<MenuItem
1770+
density={presentation === "menu" ? "touch" : "default"}
1771+
1772+
disabled={isGitActionRunning || quickAction.disabled || !!quickActionDisabledReason}
1773+
onClick={runQuickAction}
1774+
>
1775+
<GitQuickActionIcon
1776+
className="size-4"
1777+
quickAction={quickAction}
1778+
SourceControlIcon={SourceControlIcon}
1779+
/>
1780+
<MenuItemLabel>{quickAction.label}</MenuItemLabel>
1781+
</MenuItem>
1782+
{quickActionDisabledReason && (
1783+
<p className="max-w-64 px-2 py-1.5 text-xs text-warning">
1784+
{quickActionDisabledReason}
1785+
</p>
1786+
)}
1787+
<MenuSub
1788+
onOpenChange={(open) => {
1789+
if (open) requestVcsStatusRefresh(refreshVcsStatus, activeEnvironmentId, gitCwd);
1790+
}}
1791+
>
1792+
<MenuSubTrigger density="touch" disabled={isGitActionRunning}>
1793+
<SourceControlIcon className="size-4" />
1794+
<MenuItemLabel>Git actions</MenuItemLabel>
1795+
</MenuSubTrigger>
1796+
<MenuSubPopup className="min-w-32 max-w-[calc(100vw-2rem)]">{gitItems}</MenuSubPopup>
1797+
</MenuSub>
1798+
</>
1799+
)
1800+
) : !isRepo ? (
1801+
<Button variant="outline" size="xs" disabled={initAction.isPending} onClick={initializeGit}>
16621802
<GitBranchPlusIcon className="size-3.5" aria-hidden />
16631803
<span className="ml-0.5">
16641804
{initAction.isPending ? "Initializing..." : "Initialize Git"}
@@ -1720,78 +1860,7 @@ export default function GitActionsControl({
17201860
<ChevronDownIcon aria-hidden="true" className="size-4" />
17211861
</MenuTrigger>
17221862
<MenuPopup align="end" className="w-full">
1723-
{gitActionMenuItems.map((item) => {
1724-
const disabledReason = getMenuActionDisabledReason({
1725-
item,
1726-
gitStatus: gitStatusForActions,
1727-
isBusy: isGitActionRunning,
1728-
hasPrimaryRemote,
1729-
});
1730-
if (item.disabled && disabledReason) {
1731-
return (
1732-
<Popover key={`${item.id}-${item.label}`}>
1733-
<PopoverTrigger
1734-
openOnHover
1735-
nativeButton={false}
1736-
render={<span className="block w-max cursor-not-allowed" />}
1737-
>
1738-
<MenuItem className="w-full" disabled>
1739-
<GitActionItemIcon
1740-
icon={item.icon}
1741-
SourceControlIcon={SourceControlIcon}
1742-
/>
1743-
{item.label}
1744-
</MenuItem>
1745-
</PopoverTrigger>
1746-
<PopoverPopup tooltipStyle side="left" align="center">
1747-
{disabledReason}
1748-
</PopoverPopup>
1749-
</Popover>
1750-
);
1751-
}
1752-
1753-
return (
1754-
<MenuItem
1755-
key={`${item.id}-${item.label}`}
1756-
disabled={item.disabled}
1757-
onClick={() => {
1758-
openDialogForMenuItem(item);
1759-
}}
1760-
>
1761-
<GitActionItemIcon icon={item.icon} SourceControlIcon={SourceControlIcon} />
1762-
{item.label}
1763-
</MenuItem>
1764-
);
1765-
})}
1766-
{canPublishRepository ? (
1767-
<MenuItem
1768-
disabled={isGitActionRunning}
1769-
onClick={() => {
1770-
setIsPublishDialogOpen(true);
1771-
}}
1772-
>
1773-
<CloudUploadIcon />
1774-
Publish repository...
1775-
</MenuItem>
1776-
) : null}
1777-
{gitStatusForActions?.refName === null && (
1778-
<p className="px-2 py-1.5 text-xs text-warning">
1779-
Detached HEAD: create and check out a branch to enable push and pull request
1780-
actions.
1781-
</p>
1782-
)}
1783-
{gitStatusForActions &&
1784-
gitStatusForActions.refName !== null &&
1785-
!gitStatusForActions.hasWorkingTreeChanges &&
1786-
gitStatusForActions.behindCount > 0 &&
1787-
gitStatusForActions.aheadCount === 0 && (
1788-
<p className="px-2 py-1.5 text-xs text-warning">
1789-
Behind upstream. Pull/rebase first.
1790-
</p>
1791-
)}
1792-
{gitStatusError && (
1793-
<p className="px-2 py-1.5 text-xs text-destructive">{gitStatusError}</p>
1794-
)}
1863+
{gitItems}
17951864
</MenuPopup>
17961865
</Menu>
17971866
</Group>

0 commit comments

Comments
 (0)