Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

refactor: update app buttons to use the new button component#17684

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
BrunoQuaresma merged 9 commits intomainfrombq/refactor-agent-button
May 6, 2025
Merged
Show file tree
Hide file tree
Changes fromall 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
4 changes: 3 additions & 1 deletionsite/e2e/helpers.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1042,7 +1042,9 @@ export async function openTerminalWindow(
): Promise<Page> {
// Wait for the web terminal to open in a new tab
const pagePromise = context.waitForEvent("page");
await page.getByTestId("terminal").click({ timeout: 60_000 });
await page
.getByRole("link", { name: /terminal/i })
.click({ timeout: 60_000 });
const terminal = await pagePromise;
await terminal.waitForLoadState("domcontentloaded");

Expand Down
12 changes: 7 additions & 5 deletionssite/src/components/Button/Button.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,7 +13,9 @@ const buttonVariants = cva(
text-sm font-semibold font-medium cursor-pointer no-underline
focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-content-link
disabled:pointer-events-none disabled:text-content-disabled
[&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg]:p-0.5`,
[&:is(a):not([href])]:pointer-events-none [&:is(a):not([href])]:text-content-disabled
[&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg]:p-0.5
[&>img]:pointer-events-none [&>img]:shrink-0 [&>img]:p-0.5`,
{
variants: {
variant: {
Expand All@@ -28,11 +30,11 @@ const buttonVariants = cva(
},

size: {
lg: "min-w-20 h-10 px-3 py-2 [&_svg]:size-icon-lg",
sm: "min-w-20 h-8 px-2 py-1.5 text-xs [&_svg]:size-icon-sm",
lg: "min-w-20 h-10 px-3 py-2 [&_svg]:size-icon-lg [&>img]:size-icon-lg",
sm: "min-w-20 h-8 px-2 py-1.5 text-xs [&_svg]:size-icon-sm [&>img]:size-icon-sm",
xs: "min-w-8 py-1 px-2 text-2xs rounded-md",
icon: "size-8 px-1.5 [&_svg]:size-icon-sm",
"icon-lg": "size-10 px-2 [&_svg]:size-icon-lg",
icon: "size-8 px-1.5 [&_svg]:size-icon-sm [&>img]:size-icon-sm",
"icon-lg": "size-10 px-2 [&_svg]:size-icon-lg [&>img]:size-icon-lg",
},
},
defaultVariants: {
Expand Down
8 changes: 4 additions & 4 deletionssite/src/components/ExternalImage/ExternalImage.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,15 +5,15 @@ import { getExternalImageStylesFromUrl } from "theme/externalImages";
export const ExternalImage = forwardRef<
HTMLImageElement,
ImgHTMLAttributes<HTMLImageElement>
>((attrs, ref) => {
>((props, ref) => {
const theme = useTheme();

return (
// biome-ignore lint/a11y/useAltText:no reasonable alt to provide
// biome-ignore lint/a11y/useAltText:alt should be passed in as a prop
<img
ref={ref}
css={getExternalImageStylesFromUrl(theme.externalImages,attrs.src)}
{...attrs}
css={getExternalImageStylesFromUrl(theme.externalImages,props.src)}
{...props}
/>
);
});
25 changes: 9 additions & 16 deletionssite/src/modules/dashboard/Navbar/ProxyMenu.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -81,32 +81,25 @@ export const ProxyMenu: FC<ProxyMenuProps> = ({ proxyContextValue }) => {
</span>

{selectedProxy ? (
<div css={{ display: "flex", gap: 8, alignItems: "center" }}>
<div css={{ width: 16, height: 16, lineHeight: 0 }}>
<img
// Empty alt text used because we don't want to double up on
// screen reader announcements from visually-hidden span
alt=""
src={selectedProxy.icon_url}
css={{
objectFit: "contain",
width: "100%",
height: "100%",
}}
/>
</div>
<>
<img
// Empty alt text used because we don't want to double up on
// screen reader announcements from visually-hidden span
alt=""
src={selectedProxy.icon_url}
/>

<Latency
latency={latencies?.[selectedProxy.id]?.latencyMS}
isLoading={proxyLatencyLoading(selectedProxy)}
size={24}
/>
</div>
</>
) : (
"Select Proxy"
)}

<ChevronDownIcon className="text-content-primary !size-icon-xs" />
<ChevronDownIcon className="text-content-primary !size-icon-sm" />
</Button>

<Menu
Expand Down
34 changes: 16 additions & 18 deletionssite/src/modules/management/OrganizationSidebarView.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -62,25 +62,23 @@ export const OrganizationSidebarView: FC<
<Button
variant="outline"
aria-expanded={isPopoverOpen}
className="w-60justify-between p-2 h-11"
className="w-60gap-2 justify-start"
>
<div className="flex flex-row gap-2 items-center p-2 truncate">
{activeOrganization ? (
<>
<Avatar
size="sm"
src={activeOrganization.icon}
fallback={activeOrganization.display_name}
/>
<span className="truncate">
{activeOrganization.display_name || activeOrganization.name}
</span>
</>
) : (
<span className="truncate">No organization selected</span>
)}
</div>
<ChevronDown />
{activeOrganization ? (
<>
<Avatar
size="sm"
src={activeOrganization.icon}
fallback={activeOrganization.display_name}
/>
<span className="truncate">
{activeOrganization.display_name || activeOrganization.name}
</span>
</>
) : (
<span className="truncate">No organization selected</span>
)}
<ChevronDown className="ml-auto !size-icon-sm" />
</Button>
</PopoverTrigger>
<PopoverContent align="start" className="w-60">
Expand Down
27 changes: 2 additions & 25 deletionssite/src/modules/resources/AgentButton.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,8 @@
import Button,{type ButtonProps } from "@mui/material/Button";
import{Button, type ButtonProps } from "components/Button/Button";
import { forwardRef } from "react";

export const AgentButton = forwardRef<HTMLButtonElement, ButtonProps>(
(props, ref) => {
const { children, ...buttonProps } = props;

return (
<Button
{...buttonProps}
color="neutral"
size="xlarge"
variant="contained"
ref={ref}
css={(theme) => ({
padding: "12px 20px",
color: theme.palette.text.primary,
// Making them smaller since those icons don't have a padding around them
"& .MuiButton-startIcon, & .MuiButton-endIcon": {
width: 16,
height: 16,

"& svg, & img": { width: "100%", height: "100%" },
},
})}
>
{children}
</Button>
);
return <Button variant="outline" ref={ref} {...props} />;
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

What is purpose of keeping AgentButton around instead of removing it and using Button directly?

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This is a good question.

Since we want to have the TerminalLink, AppLink, VSCode buttons, etc. visually consistent, and be sure they are always looking the same, I just decided to keep the AgentButton. Of course, we could just set the variant in all these components, but since they are many (around 5 or 6 I guess) it would be easy to forget to update one of them when changing some of the styles (maybe it is not a problem since we have tests).

I'm going to refactor the apps logic very soon, so If I see it is just ok to remove the AgentButton, I will do.

);
38 changes: 20 additions & 18 deletionssite/src/modules/resources/AgentDevcontainerCard.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
import Link from "@mui/material/Link";
import Tooltip from "@mui/material/Tooltip";
import type {
Workspace,
WorkspaceAgent,
WorkspaceAgentContainer,
} from "api/typesGenerated";
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "components/Tooltip/Tooltip";
import { ExternalLinkIcon } from "lucide-react";
import type { FC } from "react";
import { portForwardURL } from "utils/portForward";
Expand DownExpand Up@@ -74,29 +78,27 @@ export const AgentDevcontainerCard: FC<AgentDevcontainerCardProps> = ({
const linkDest = hasHostBind
? portForwardURL(
wildcardHostname,
port.host_port!,
port.host_port,
agent.name,
workspace.name,
workspace.owner_name,
location.protocol === "https" ? "https" : "http",
)
: "";
return (
<Tooltip key={portLabel} title={helperText}>
<span>
<Link
key={portLabel}
color="inherit"
component={AgentButton}
underline="none"
startIcon={<ExternalLinkIcon className="size-icon-sm" />}
disabled={!hasHostBind}
href={linkDest}
>
{portLabel}
</Link>
</span>
</Tooltip>
<TooltipProvider key={portLabel}>
<Tooltip>
<TooltipTrigger>
<AgentButton disabled={!hasHostBind} asChild>
<a href={linkDest}>
<ExternalLinkIcon />
{portLabel}
</a>
</AgentButton>
</TooltipTrigger>
<TooltipContent>{helperText}</TooltipContent>
</Tooltip>
</TooltipProvider>
);
})}
</div>
Expand Down
70 changes: 33 additions & 37 deletionssite/src/modules/resources/AppLink/AppLink.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
import { useTheme } from "@emotion/react";
import ErrorOutlineIcon from "@mui/icons-material/ErrorOutline";
import CircularProgress from "@mui/material/CircularProgress";
import Link from "@mui/material/Link";
import Tooltip from "@mui/material/Tooltip";
import { API } from "api/api";
import type * as TypesGen from "api/typesGenerated";
import { displayError } from "components/GlobalSnackbar/utils";
import { Spinner } from "components/Spinner/Spinner";
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "components/Tooltip/Tooltip";
import { useProxy } from "contexts/ProxyContext";
import { type FC,type MouseEvent,useState } from "react";
import { type FC, useState } from "react";
import { createAppLinkHref } from "utils/apps";
import { generateRandomString } from "utils/random";
import { AgentButton } from "../AgentButton";
Expand DownExpand Up@@ -75,21 +79,7 @@ export const AppLink: FC<AppLinkProps> = ({ app, workspace, agent }) => {

let primaryTooltip = "";
if (app.health === "initializing") {
icon = (
// This is a hack to make the spinner appear in the center of the start
// icon space
<span
css={{
display: "flex",
width: "100%",
height: "100%",
alignItems: "center",
justifyContent: "center",
}}
>
<CircularProgress size={14} />
</span>
);
icon = <Spinner loading />;
primaryTooltip = "Initializing...";
}
if (app.health === "unhealthy") {
Expand All@@ -112,22 +102,13 @@ export const AppLink: FC<AppLinkProps> = ({ app, workspace, agent }) => {
canClick = false;
}

const isPrivateApp = app.sharing_level === "owner";

return (
<Tooltip title={primaryTooltip}>
<Link
color="inherit"
component={AgentButton}
startIcon={icon}
endIcon={isPrivateApp ? undefined : <ShareIcon app={app} />}
disabled={!canClick}
href={href}
css={{
pointerEvents: canClick ? undefined : "none",
textDecoration: "none !important",
}}
onClick={async (event: MouseEvent<HTMLElement>) => {
const canShare = app.sharing_level !== "owner";

const button = (
<AgentButton asChild>
<a
href={canClick ? href : undefined}
onClick={async (event) => {
if (!canClick) {
return;
}
Expand DownExpand Up@@ -187,8 +168,23 @@ export const AppLink: FC<AppLinkProps> = ({ app, workspace, agent }) => {
}
}}
>
{icon}
{appDisplayName}
</Link>
</Tooltip>
{canShare && <ShareIcon app={app} />}
</a>
</AgentButton>
);

if (primaryTooltip) {
return (
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>{button}</TooltipTrigger>
<TooltipContent>{primaryTooltip}</TooltipContent>
</Tooltip>
</TooltipProvider>
);
}

return button;
};
35 changes: 16 additions & 19 deletionssite/src/modules/resources/TerminalLink/TerminalLink.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
import Link from "@mui/material/Link";
import { TerminalIcon } from "components/Icons/TerminalIcon";
import type { FC, MouseEvent } from "react";
import { generateRandomString } from "utils/random";
Expand DownExpand Up@@ -39,23 +38,21 @@ export const TerminalLink: FC<TerminalLinkProps> = ({
}/terminal?${params.toString()}`;

return (
<Link
underline="none"
color="inherit"
component={AgentButton}
startIcon={<TerminalIcon />}
href={href}
onClick={(event: MouseEvent<HTMLElement>) => {
event.preventDefault();
window.open(
href,
Language.terminalTitle(generateRandomString(12)),
"width=900,height=600",
);
}}
data-testid="terminal"
>
{DisplayAppNameMap.web_terminal}
</Link>
<AgentButton asChild>
<a
href={href}
onClick={(event: MouseEvent<HTMLElement>) => {
event.preventDefault();
window.open(
href,
Language.terminalTitle(generateRandomString(12)),
"width=900,height=600",
);
}}
>
<TerminalIcon />
{DisplayAppNameMap.web_terminal}
</a>
</AgentButton>
);
};
Loading
Loading

[8]ページ先頭

©2009-2025 Movatter.jp